Skip to content
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

fix(node): Prevent node:child_process from always inheriting the parent environment (#27343) #27340

Merged
merged 4 commits into from
Jan 13, 2025

Conversation

TateKennington
Copy link
Contributor

@TateKennington TateKennington commented Dec 12, 2024

Fixes #27343

Currently the node:child_process polyfill is always passing the full parent environment to all spawned subprocesses. In the case where options.env is provided those keys are overridden but the rest of the parent environment is still passed through.

On Node the behaviour is for child processes to only inherit the parent environment when options.env isn't specified. When options.env is specified the child process inherits only those keys.

This PR updates the internal node child_process polyfill so that the clearEnv argument is set to true when spawning the subprocess to prevent the parent environment always being inherited by default. It also fixes an issue where normalizeSpawnArguments wasn't returning the env option if options.env was unset.

@CLAassistant
Copy link

CLAassistant commented Dec 12, 2024

CLA assistant check
All committers have signed the CLA.

@TateKennington TateKennington changed the title fix(node): Prevent node:child_process from always inheriting the parent environment fix(node): Prevent node:child_process from always inheriting the parent environment (#27343) Dec 12, 2024
@TateKennington TateKennington marked this pull request as ready for review December 12, 2024 19:34
@TateKennington
Copy link
Contributor Author

Hi @nathanwhit, could I please get a review on this if you have the time? 😄

(Sorry for the ping, I wasn't sure how best to request a review / who to ask, your name was just in the Git blame most recently 😅)

Copy link
Member

@nathanwhit nathanwhit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the PR!

sorry for the slow review, didn't see this one

@nathanwhit nathanwhit merged commit 5a39f2f into denoland:main Jan 13, 2025
17 checks passed
bartlomieju pushed a commit that referenced this pull request Jan 16, 2025
…nt environment (#27343) (#27340)

Fixes #27343

Currently the node:child_process polyfill is always passing the full
parent environment to all spawned subprocesses. In the case where
`options.env` is provided those keys are overridden but the rest of the
parent environment is still passed through.

On Node the behaviour is for child processes to only inherit the parent
environment when `options.env` isn't specified. When `options.env` is
specified the child process inherits only those keys.

This PR updates the internal node child_process polyfill so that the
`clearEnv` argument is set to true when spawning the subprocess to
prevent the parent environment always being inherited by default. It
also fixes an issue where `normalizeSpawnArguments` wasn't returning the
`env` option if `options.env` was unset.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

node:child_process always inherits parent env variables
3 participants