-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src,permission: --allow-wasi & prevent WASI exec
PR-URL: #53124 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
- Loading branch information
1 parent
f00ee1c
commit 2bcce32
Showing
17 changed files
with
183 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "permission/wasi_permission.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace node { | ||
|
||
namespace permission { | ||
|
||
// Currently, WASIPermission manage a single state | ||
// Once denied, it's always denied | ||
void WASIPermission::Apply(Environment* env, | ||
const std::vector<std::string>& allow, | ||
PermissionScope scope) { | ||
deny_all_ = true; | ||
} | ||
|
||
bool WASIPermission::is_granted(Environment* env, | ||
PermissionScope perm, | ||
const std::string_view& param) const { | ||
return deny_all_ == false; | ||
} | ||
|
||
} // namespace permission | ||
} // namespace node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef SRC_PERMISSION_WASI_PERMISSION_H_ | ||
#define SRC_PERMISSION_WASI_PERMISSION_H_ | ||
|
||
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
|
||
#include <vector> | ||
#include "permission/permission_base.h" | ||
|
||
namespace node { | ||
|
||
namespace permission { | ||
|
||
class WASIPermission final : public PermissionBase { | ||
public: | ||
void Apply(Environment* env, | ||
const std::vector<std::string>& allow, | ||
PermissionScope scope) override; | ||
bool is_granted(Environment* env, | ||
PermissionScope perm, | ||
const std::string_view& param = "") const override; | ||
|
||
private: | ||
bool deny_all_; | ||
}; | ||
|
||
} // namespace permission | ||
|
||
} // namespace node | ||
|
||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
#endif // SRC_PERMISSION_WASI_PERMISSION_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Flags: --experimental-permission --allow-wasi --allow-fs-read=* | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
common.skipIfWorker(); | ||
|
||
const assert = require('assert'); | ||
const { WASI } = require('wasi'); | ||
|
||
// Guarantee the initial state | ||
{ | ||
assert.ok(process.permission.has('wasi')); | ||
} | ||
|
||
// When a permission is set by cli, the process shouldn't be able | ||
// to create WASI instance unless --allow-wasi is sent | ||
{ | ||
// doesNotThrow | ||
new WASI({ | ||
version: 'preview1', | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Flags: --experimental-permission --allow-fs-read=* | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('node:assert'); | ||
|
||
const { WASI } = require('wasi'); | ||
|
||
{ | ||
assert.throws(() => { | ||
new WASI({ | ||
version: 'preview1', | ||
preopens: { '/': '/' }, | ||
}); | ||
}, common.expectsError({ | ||
code: 'ERR_ACCESS_DENIED', | ||
permission: 'WASI', | ||
})); | ||
} |