Repository navigation
fix: keep an own __proto__ key when copying the spawn environment - #994
Open
Mykola Dementiev (nikolay-dementiev) wants to merge 2 commits into
Open
Mykola Dementiev (nikolay-dementiev) wants to merge 2 commits into
Mykola Dementiev (nikolay-dementiev) wants to merge 2 commits into
Conversation
Author
|
@microsoft-github-policy-service agree |
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.
Fixes #993
Problem
spawncopiesoptions.envwithassign(src/utils.ts) usingtarget[key] = source[key]. When the source has an own__proto__key (for example one that came fromJSON.parse), the assignment runs theObject.prototype.__proto__setter instead of creating a property. A string value is ignored, so the variable never reaches_parseEnvand the child starts without it.child_processpasses the same object through.Change
assignnow creates each property withObject.defineProperty(enumerable, writable, configurable), so an own__proto__key is copied as an ordinary property and the target's prototype is untouched. The properties stay writable and configurable, so_sanitizeEnv(delete) and the laterPWD/TERMassignments keep working. Signature and return value are unchanged. The sameassignis used byUnixTerminalandWindowsTerminal.Tests
src/utils.test.ts(new):assigncopies an own__proto__key as an own property, keeps the prototype, and still copies other keys.src/unixTerminal.test.ts:spawnpasses an own__proto__env entry to the child (real spawn, exact outputtrue:selected-value).Both tests fail on the unfixed code (
false !== trueandfalse:[object Object]).Verification
macOS 26.5.2 arm64, Node v26.3.0, npm 11.16.0:
npm run buildnpm test: 26 passing (24 before),eslint src/cleanlib/: printstrue:selected-value(wasfalse:[object Object])Not verified
WindowsTerminalruns the sameassign, but this was not run on Windows.