Repository navigation
child_process: reject invalid environment variable names - #67659
ShogunPanda wants to merge 1 commit into
Conversation
| invalidKeys.push('=C:'); | ||
| } else { | ||
| // A lone '=' is not a valid name on Windows either. | ||
| invalidKeys.push('='); |
There was a problem hiding this comment.
I think it might be worth testing the lone = unconditionally, not just for Windows.
There was a problem hiding this comment.
Thanks. The validation already rejects a lone = on every platform: on POSIX indexOf(key, '=', 0) matches it, and on Windows we have the explicit key === '=' check because the search starts at index 1. == is also rejected on Windows, since indexOf(key, '=', 1) finds the second =.
You're right that the test only covers = on Windows. I'll add = and == to the shared invalidKeys list so this doesn't regress if that start index is refactored.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67659 +/- ##
==========================================
- Coverage 90.72% 90.58% -0.14%
==========================================
Files 801 802 +1
Lines 280960 286942 +5982
Branches 54260 55415 +1155
==========================================
+ Hits 254892 259926 +5034
- Misses 16248 17110 +862
- Partials 9820 9906 +86
🚀 New features to boost your workflow:
|
This comment was marked as resolved.
This comment was marked as resolved.
Keys in the `env` option that are empty or that contain `=` cannot be represented in the `KEY=VALUE` form used by the child process environment. They were passed through unchanged, so the child received a different variable than the one the caller wrote. Throw `ERR_INVALID_ARG_VALUE` for them, as is already done for keys that contain null bytes. On Windows, a leading `=` is allowed, as it is used by per-drive variables such as `=C:`. Signed-off-by: Paolo Insogna <paolo@cowtech.it>
5285e5b to
447c810
Compare
child_process.spawn()and friends build the child environment asKEY=VALUEstrings. A key inoptions.envthat is empty or thatcontains
=cannot be represented that way: for example{ 'A=B': 'C' }producedA=B=C, which the child reads as variableAwith value
B=C.This throws
ERR_INVALID_ARG_VALUEfor such keys innormalizeSpawnArguments(), next to the existing null byte check. OnWindows a leading
=is still accepted, becauseprocess.envcontainsper-drive entries like
=C:andenv: process.envmust keep working.On POSIX,
process.envdoes not expose entries starting with=, soenv: process.envis unaffected.This is a bug fix and not an API change: such input has never been
representable, and the child always received a different variable than
the one requested. The same applies to the null byte validation of
env, which landed without a semver label and was backported tov18.x and v19.x (#44782).
Includes a test covering
spawn,spawnSync,exec,execSync,execFile,execFileSyncandfork, a positive case for a leading=on Windows, and a one line doc note.