Repository navigation
Conversation
Copy caller options onto a null-prototype object in the constructor so that inherited properties (e.g. a polluted Object.prototype.workerOpts, workerData, bufferSize or sync) are not read and flowed into the Worker, where env and execArgv are honored. Add regression tests that pollute Object.prototype and assert nothing leaks into the worker.
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.
What
Copy caller options onto a null-prototype object in the
ThreadStreamconstructor:This ensures inherited properties (e.g. a polluted
Object.prototype.workerOpts,workerData,bufferSizeorsync) are never read and flowed into theworker_threads.Worker, whereenvandexecArgvare honored.Why
Defense-in-depth hardening against prototype pollution. An attacker who can pollute
Object.prototypeearlier in the same process (a common CWE-1321 primitive) could otherwise get a craftedworkerOpts(e.g.{ env: { NODE_OPTIONS: --require <file> } }) reaching a spawned worker. Copying options onto a null-prototype object means only the caller's own enumerable properties are used.The one-line change also covers every other option read (
bufferSize,sync,filename,workerData), not justworkerOpts.Tests
Adds
test/prototype-pollution.test.js(with atest/report-pollution.jsfixture) that pollutesObject.prototypeand asserts nothing leaks into the worker:workerOpts.name→ worker keeps the default nameworkerOpts.env→ worker environment is not replacedworkerData→ workeroptsare unaffectedbufferSize→ constructor no longer throwsVerified the regression tests fail against the pre-fix code and pass after the change.
npm test: 74 tests, 71 pass, 3 skipped (yarn-specific), 0 fail.