Skip to content

fix(mcpx): affected-tests --run executes argv, never a shell (#5649) - #8672

Merged
dezren39 merged 2 commits into
mainfrom
queue/10479-5649-affected-tests
Nov 11, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/10479-5649-affected-tests

Conversation

@dezren39

@dezren39 dezren39 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #5649: pkgs/mcpx/scripts/affected-tests.py --run built shell command strings out of Git-reported paths and executed them with shell=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:

  • Collection: git ls-files / git diff --name-only are read NUL-delimited (-z), so a path with spaces or metacharacters stays one value instead of being whitespace-split into bogus fragments.
  • Execution: every tier command now carries an (argv, cwd) pair alongside its display string. --run executes subprocess.run(argv, cwd=...) — no shell anywhere (the file has no shell=True left). The (cd pkgs/mcpx && …) strings become a real cwd=; the -run '<regex>' quoting disappears because the regex is a single argv element.
  • Output compatibility: dry-run prints exactly the same command strings as before — the existing selector tests (test_affected_untracked.py asserts display strings verbatim) pass unmodified, and the mcpx-test-affected just recipe is untouched.

Regression tests

New pkgs/mcpx/scripts/tests/test_affected_run_injection.py mirrors the untracked-parity fixture (scratch git repo, real selector CLI) but runs with --run:

  • evil$(touch${IFS}pwned).go untracked → selector exits 0, no pwned marker 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).
  • The probe from the issue is inverted by construction: filenames are now only ever argv elements.

🤖 Queue task 10479, lane code-d.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

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).
@dezren39
dezren39 requested a review from a team as a code owner November 11, 2026 12:32
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T12:43:01.336049Z 0f2a00d Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39

Copy link
Copy Markdown
Member Author

@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).

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 013d0791-0f99-4c48-b3c3-c49270fc7e2d
Commits

Reviewing files that changed from the base of the PR and between 538d98b and 0f2a00d.

Files selected for processing: 4

  • .github/test-suite-registry.json
  • .github/workflows/mcpx-test.yml
  • pkgs/mcpx/scripts/affected-tests.py
  • pkgs/mcpx/scripts/tests/test_affected_run_injection.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread pkgs/mcpx/scripts/affected-tests.py Resolved
@dezren39

Copy link
Copy Markdown
Member Author

@codex review — all three findings addressed in the new head:

  • P1 (CI wiring): added the Affected run-injection regressions (#5649) step to the Go-equipped unit job in .github/workflows/mcpx-test.yml (alongside the sibling selector suites) and registered mcpx.scripts.affected-run-injection in .github/test-suite-registry.json, mirroring mcpx.scripts.affected-untracked (same venue; the registry honestly records that workflow as disabled_manually / uncovered-in-fact, like its sibling).
  • P2 (non-UTF-8 filenames): run() now decodes subprocess output with errors="surrogateescape", so raw filename bytes from the NUL-delimited Git output round-trip losslessly instead of raising UnicodeDecodeError before filtering.
  • P2 (space test): the test now asserts the executed output contains gofmt -l pkgs/mcpx/with space.go and the root package test command — under the old splitting nothing was selected, so it can no longer pass vacuously.

Local: full scripts/tests discover green (23 tests).

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 0f2a00d622

ℹ️ 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".

@dezren39
dezren39 merged commit 147aef2 into main Nov 11, 2026
3 of 17 checks passed
@dezren39
dezren39 deleted the queue/10479-5649-affected-tests branch November 11, 2026 12:45
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.

mcpx(affected-tests): --run executes shell syntax from changed paths

1 participant