-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
permission: add --allow-env flag for environment variable access control #62827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nabeel378
wants to merge
8
commits into
nodejs:main
Choose a base branch
from
nabeel378:feat/permission-allow-env-flag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+411
−4
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
efce03f
permission: add --allow-env option for environment variable permissions
nabeel378 31e4b5f
doc: add documentation for --allow-env flag in CLI and permissions
nabeel378 f3544f8
permission: add --allow-env option for environment variable permissions
nabeel378 c54086a
permission,doc: fix --allow-env docs and expand test coverage
nabeel378 b6a89cf
permission: refactor permission checks and improve test assertions fo…
nabeel378 cba1261
permission: fix env var default behavior and add manpage docs
nabeel378 5131c17
chore: re-trigger CI
nabeel378 591de5d
doc: fix --allow-env docs to describe opt-in model
nabeel378 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -1559,6 +1559,14 @@ changes: | |
| The `process.env` property returns an object containing the user environment. | ||
| See environ(7). | ||
|
|
||
| When the [Permission Model][] is enabled, access to environment variables is | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue as cli.md |
||
| unrestricted by default. To restrict access, the `--allow-env` flag must be | ||
| explicitly passed. Once `--allow-env` is specified, reading a restricted | ||
| variable silently returns `undefined`, while writing or deleting throws | ||
| `ERR_ACCESS_DENIED`. Use `--allow-env=*` to grant access to all variables or | ||
| `--allow-env=HOME,PATH` to grant access to specific ones. See the | ||
| [`--allow-env`][] documentation for more details. | ||
|
|
||
| An example of this object looks like: | ||
|
|
||
| <!-- eslint-skip --> | ||
|
|
@@ -4595,6 +4603,7 @@ cases: | |
| [`'exit'`]: #event-exit | ||
| [`'message'`]: child_process.md#event-message | ||
| [`'uncaughtException'`]: #event-uncaughtexception | ||
| [`--allow-env`]: cli.md#--allow-env | ||
| [`--no-deprecation`]: cli.md#--no-deprecation | ||
| [`--permission`]: cli.md#--permission | ||
| [`--unhandled-rejections`]: cli.md#--unhandled-rejectionsmode | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
| #include "env_var_permission.h" | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| namespace node { | ||
|
|
||
| namespace permission { | ||
|
|
||
| void EnvVarPermission::Apply(Environment* env, | ||
| const std::vector<std::string>& allow, | ||
| PermissionScope scope) { | ||
| deny_all_ = true; | ||
| if (!allow.empty()) { | ||
| if (allow.size() == 1 && allow[0] == "*") { | ||
| allow_all_ = true; | ||
| return; | ||
| } | ||
| for (const std::string& arg : allow) { | ||
| allowed_env_vars_.insert(arg); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| bool EnvVarPermission::is_granted(Environment* env, | ||
| PermissionScope perm, | ||
| const std::string_view& param) const { | ||
| if (deny_all_) { | ||
| if (allow_all_) { | ||
| return true; | ||
| } | ||
| if (param.empty()) { | ||
| return false; | ||
| } | ||
| return allowed_env_vars_.find(std::string(param)) != | ||
| allowed_env_vars_.end(); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| } // namespace permission | ||
| } // namespace node |
This file contains hidden or 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,35 @@ | ||
| #ifndef SRC_PERMISSION_ENV_VAR_PERMISSION_H_ | ||
| #define SRC_PERMISSION_ENV_VAR_PERMISSION_H_ | ||
|
|
||
| #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
|
|
||
| #include <set> | ||
| #include <string> | ||
| #include <vector> | ||
| #include "permission/permission_base.h" | ||
|
|
||
| namespace node { | ||
|
|
||
| namespace permission { | ||
|
|
||
| class EnvVarPermission 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_ = false; | ||
| bool allow_all_ = false; | ||
| std::set<std::string> allowed_env_vars_; | ||
| }; | ||
|
|
||
| } // namespace permission | ||
|
|
||
| } // namespace node | ||
|
|
||
| #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
| #endif // SRC_PERMISSION_ENV_VAR_PERMISSION_H_ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This paragraph and the console block below it describe a deny-by-default model that the code does not implement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! You're right, env vars are unrestricted by default with --permission. They only get restricted when --allow-env is explicitly passed. Updated both cli.md and process.md with the correct description and working examples.