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

node:child_process always inherits parent env variables #27343

Closed
TateKennington opened this issue Dec 12, 2024 · 0 comments · Fixed by #27340
Closed

node:child_process always inherits parent env variables #27343

TateKennington opened this issue Dec 12, 2024 · 0 comments · Fixed by #27340

Comments

@TateKennington
Copy link
Contributor

Version: Deno 2.1.3

Hi there 👋

I'm currently experiencing an issue where Deno's node:child_process polyfill is always passing the parent process's environment to spawned subprocesses even when the env option is provided. On Node it looks like the correct behaviour is for the parent environment to be inherited only when env isn't specified, otherwise only the values from env are passed to the environment.

For example, the code:

import child_process from 'node:child_process'

child_process.spawnSync('env', { env: { test: 'test' } }).stdout.toString('utf8')

When run on Node only outputs 'test=test\n' but when run on Deno outputs the full parent environment in addition to test=test.

I've had a go at fixing this in #27340 😄

nathanwhit pushed a commit that referenced this issue Jan 13, 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.
bartlomieju pushed a commit that referenced this issue 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
1 participant