Conversation
Collaborator
|
Review requested:
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #66132 +/- ##
========================================
Coverage 90.27% 90.27%
========================================
Files 790 792 +2
Lines 271651 272380 +729
Branches 51842 52013 +171
========================================
+ Hits 245228 245889 +661
- Misses 16928 16946 +18
- Partials 9495 9545 +50
🚀 New features to boost your workflow:
|
jasnell
marked this pull request as draft
September 19, 2026 16:19
This comment was marked as resolved.
This comment was marked as resolved.
jasnell
marked this pull request as ready for review
September 19, 2026 17:29
Necessarily semver-major. When `--permission` is on, every env var not matched by `--allow-env` is removed at startup. It takes names, patterns (`PREFI_*`), or `*`, repeatable or comma-sep'd. There are a range of env vars that Node.js itself uses, and a default range that are generally known to be safe in common usage. These are never scrubbed. These include things like `NODE_OPTIONS`, `NODE_EXTRA_CA_CERTS`, `PATH`, `HOME`, etc. Env vars can be dropped at runtime after reading using `permission.drop()`. This is a stronger protection than using `process.env.FOO = undefined` because it will scrub the env var also from the environment block. On Linux, the removed entries are overwritten in the initial environment block and fs reads of /proc/*/environ are denied. On Windows, removal also clears the C runtime's copy of the environ using _wputenv_s Reading a removed name returns undefined, warns once per name, and publishes to a diagnostics channel. Env file keys are allowed. If the user had reason to pass in an env file the assumption is they meant to allow them. File-source config (node.config.json and NODE_OPTIONS from a .env file can only narrow the allow list. Embedders must call ScrubProcessEnvironment() themselves on startup. This is left up to the embedder to determine the exact timing but needs to be called before startup actually happens. Child processes are started with `--allow-env=*`. Those either receive the explicit env they were started with or only the env they inherit from the parent. Since the parent process is scrubbed, it should never be more than what the parent can see. Main part of the impl was done by hand. Docs, tests, verification pass, and cleanup nits were automated. Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode
Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode
jasnell
force-pushed
the
jasnell/allow-env
branch
from
September 19, 2026 18:43
3740011 to
9127642
Compare
Member
|
why semver-major? |
Member
Author
|
It's major because it's filter-by-default when |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Necessarily semver-major.
Alternative for a previous attempt in #62827 that stalled out.
When
--permissionis on, every env var not matched by--allow-envis removed at startup. It takes names, patterns (PREFI_*), or*, repeatable or comma-sep'd.There are a range of env vars that Node.js itself uses, and a default range that are generally known to be safe in common usage. These are never scrubbed. These include things like
NODE_OPTIONS,NODE_EXTRA_CA_CERTS,PATH,HOME, etc.Env vars can be dropped at runtime after reading using
permission.drop(). This is a stronger protection than usingprocess.env.FOO = undefinedbecause it will scrub the env var also from the environment block.On Linux, the removed entries are overwritten in the initial environment block and fs reads of /proc/*/environ are denied.
On Windows, removal also clears the C runtime's copy of the environ using _wputenv_s
Reading a removed name returns undefined, warns once per name, and publishes to a diagnostics channel.
Env file keys are allowed. If the user had reason to pass in an env file the assumption is they meant to allow them.
File-source config (node.config.json and NODE_OPTIONS from a .env file can only narrow the allow list.
Embedders must call ScrubProcessEnvironment() themselves on startup. This is left up to the embedder to determine the exact timing but needs to be called before startup actually happens.
Child processes are started with
--allow-env=*. Those either receive the explicit env they were started with or only the env they inherit from the parent. Since the parent process is scrubbed, it should never be more than what the parent can see.The key motivation here is that environment variables are the primary mechanism for injecting secrets into applications. These can be trivially exfiltrated using simple one-liners like
fetch('...', { headers: { secret: process.env.SECRET } }). Simply unsetting those viaprocess.env.SECRET = undefinedis typically not enough since those can still be read from the underlying environment block. This PR provides stronger protection but it obviously cannot be 100% since depending on how it is used, the strings can still be in memory.The prior attempt to add this in #62827 had a number of flaws that this version addresses. That PR used an incomplete view filter.
process.report.getReport(), native addons, FFI,and
/proc/self/environcould all still read the real environment. Scrubbingbefore any JavaScript runs protects those paths. This PR also fixes a number of other breaking changes the other PR would have introduced:
process.envandprocess.loadEnvFile()keep working.--env-filefiles are allowed.--allow-env=*, because the environment they inherit has already been scrubbed.