fix(cli): prevent command injection via ZX_* variables loaded from --env#1447
Open
l3tchupkt wants to merge 1 commit intogoogle:mainfrom
Open
fix(cli): prevent command injection via ZX_* variables loaded from --env#1447l3tchupkt wants to merge 1 commit intogoogle:mainfrom
l3tchupkt wants to merge 1 commit intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
loading a .env file via --env merges its contents into process.env, which resolveDefaults() then blindly promotes into live execution settings. An attacker who can modify the .env file (supply-chain PR, compromised dep) can set ZX_PREFIX/ZX_POSTFIX/ZX_SHELL to arbitrary shell code that runs for every call in an otherwise-trusted script. Fix: snapshot ZX_* keys present in process.env before dotenv.config() runs, then purge any ZX_* key introduced by the file before resolveDefaults() sees the environment. Legitimate ZX_* variables set by the operator (e.g. from the shell that launched zx) are preserved; only file-injected ones are stripped. Reported-by: LAKSHMIKANTHAN K (letchupkt) CWE: CWE-94 / CWE-77 (Command Injection)
1f7badb to
ade6207
Compare
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.
Reported-by: LAKSHMIKANTHAN K (letchupkt)
CWE: CWE-78 (Command Injection)
Summary
This PR fixes a command injection vulnerability in the
zxCLI caused by unsafe handling of environment variables loaded via the--envoption.Previously,
.envfiles loaded throughdotenv.config()were merged directly intoprocess.env, after whichresolveDefaults()importedZX_*variables into runtime execution settings. This allowed attacker-controlled.envfiles to influence execution parameters such asZX_PREFIX,ZX_POSTFIX, andZX_SHELL.As a result, untrusted configuration files could inject arbitrary shell commands into otherwise safe scripts.
Relevant technical choices
Enforced separation between configuration data and execution control parameters
Prevented
resolveDefaults()from importingZX_*variables originating from.envfilesIntroduced filtering/blocking of sensitive execution keys when loaded via
--env, including:ZX_PREFIXZX_POSTFIXZX_SHELLZX_CWDZX_PREFER_LOCALEnsured that only trusted sources (CLI flags or direct environment) can control execution behavior
Maintained backward compatibility for standard
.envusage while removing unsafe control-plane influenceImpact
Prevents command injection through malicious
.envfiles.This mitigates risks such as:
ZX_PREFIX/ZX_POSTFIXUsage demo
npm buildbefore committing and verified the bundle updates correctly.run testand confirmed all tests succeed. Added tests to cover my changes if needed.