Repository navigation
fix(mcpx): affected-tests --run executes argv, never a shell (#5649) - #8672
Conversation
affected-tests.py collected Git-reported paths as text, split them on whitespace, interpolated .go paths and package directories into command strings, and ran the strings with shell=True: a crafted filename in an untrusted checkout executed arbitrary shell syntax during --run. Paths are now structured end to end: git ls-files/diff output is NUL-delimited, and every tier command carries an argv vector plus an explicit cwd. --run executes argv with no shell; the printed dry-run commands are unchanged, so existing selector tests and the mcpx-test-affected recipe see the same output. New regression suite test_affected_run_injection.py drives the real selector with --run in a scratch repo: command-substitution and semicolon filenames create no marker file, and a space in a filename stays a single path. All scripts tests pass (10 in the affected suites; full discover green).
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review Security fix for #5649. Please check: (1) no remaining path from Git-reported filenames to a shell — collection is NUL-delimited and every tier command executes as argv with an explicit cwd (no shell=True remains); (2) dry-run display strings are byte-identical to before for ordinary paths (existing selector tests pin them); (3) the new --run regression tests actually exercise the injection (scratch repo, metacharacter filenames, marker-file assertions). |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 23 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 371933e263
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ut; stronger space test (#5649 review)
|
@codex review — all three findings addressed in the new head:
Local: full scripts/tests discover green (23 tests). |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Fixes #5649:
pkgs/mcpx/scripts/affected-tests.py --runbuilt shell command strings out of Git-reported paths and executed them withshell=True, so a crafted filename in an untrusted checkout ran arbitrary shell syntax during a routine affected-test run.The fix keeps paths structured end to end, following the issue's suggested shape:
git ls-files/git diff --name-onlyare read NUL-delimited (-z), so a path with spaces or metacharacters stays one value instead of being whitespace-split into bogus fragments.(argv, cwd)pair alongside its display string.--runexecutessubprocess.run(argv, cwd=...)— no shell anywhere (the file has noshell=Trueleft). The(cd pkgs/mcpx && …)strings become a realcwd=; the-run '<regex>'quoting disappears because the regex is a single argv element.test_affected_untracked.pyasserts display strings verbatim) pass unmodified, and themcpx-test-affectedjust recipe is untouched.Regression tests
New
pkgs/mcpx/scripts/tests/test_affected_run_injection.pymirrors the untracked-parity fixture (scratch git repo, real selector CLI) but runs with--run:evil$(touch${IFS}pwned).gountracked → selector exits 0, nopwnedmarker created (the old code executed the substitution from the gofmt line);x;touch${IFS}pwned2;.go→ no marker;with space.go→ stays a single path, selector exits 0.Verification
python3 -m unittest discover -s pkgs/mcpx/scripts/tests— green (including the 3 new tests and the pre-existing affected/embeds/shard/seed suites).🤖 Queue task 10479, lane code-d.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.