Skip to content

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

Closed

Description

@dezren39

Finding

affected-tests.py --run executes shell commands containing Git-reported paths without quoting them. The script collects changed and untracked paths at pkgs/mcpx/scripts/affected-tests.py:366-371, interpolates .go paths and package directories into command strings at :399-404 and :412-414, then runs each string with subprocess.run(..., shell=True) at :605-608. The repo-level mcpx-test-affected recipe exposes the --run argument (root.just:187-191).

A controlled scratch-repository probe confirmed arbitrary shell syntax in a space-free untracked .go filename executed during --run and created a marker file. The probe ran outside the laptop checkout. Current selector tests explicitly use the dry-run seam and never --run (pkgs/mcpx/scripts/tests/test_affected_untracked.py:12-19,85-99).

Why it matters

A developer running the documented affected-test command with --run against an untrusted branch can execute commands from a crafted filename. This turns a local test-selection convenience into a shell-execution boundary.

Suggested fix

Keep Git paths as structured values (prefer NUL-delimited Git output), build argument vectors for gofmt, go vet, and go test, and use cwd= rather than shell cd strings. Add a scratch-repo regression test with shell metacharacters in a filename and assert that no marker command runs.

Activity

  1. added
    kind/securitySecurity issue or security hardening
    app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Nov 4, 2026
  2. developing-today commented on Nov 4, 2026

    @developing-today
    Contributor
  3. added
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 5, 2026
  4. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

    Triage evidence (2026-11-05, fresh read of current main via gh api):

    • pkgs/mcpx/scripts/affected-tests.py is 614 lines at current main; the --run loop still executes with subprocess.run(cmd, cwd=root, shell=True) (line 608).
    • Commands are built as strings interpolating Git-reported paths unquoted: the gofmt -l command joins pkgs/mcpx/{p} paths with spaces, and go vet / go test commands interpolate package directories via pkg_arg() — a crafted path containing shell syntax reaches the shell unchanged.
    • No open PR fixes this path (PR fix(mcpx): include untracked contents in affected-tests (#3320) #4398 covered untracked-file contents, a different change), and no live fix task existed — enqueued task 10479 (small_fix, dedupe repo-health:v1:fix:developing-today/code:issue:5649).
    • Fix path (as scoped on the issue): keep Git paths structured (NUL-delimited output), argv vectors for gofmt/go vet/go test, cwd= instead of shell cd, plus a scratch-repo regression test with shell metacharacters in a filename asserting no marker executes.
  5. added
    status/triagedTriaged and routed (see agent note)
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    work/assignedQueue worker lifecycle state
    and removed on Nov 5, 2026
  6. developing-today commented on Nov 5, 2026

    @developing-today
    Contributor

    🤖 Agent note · handed off

  7. 149 remaining items

  8. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 11, 2026
  9. added 2 commits that reference this issue on Nov 11, 2026
  10. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (task 10479, lane code-d)

    • Fix: PR fix(mcpx): affected-tests --run executes argv, never a shell (#5649) #8672 merged 2026-11-11T12:45Z (merge commit 147aef2) — affected-tests.py no longer builds shell strings from Git-reported paths. Collection is NUL-delimited (git ls-files -z / git diff --name-only -z); every tier command carries an argv vector + explicit cwd and --run executes argv with no shell (no shell=True remains). Dry-run display strings are byte-identical for ordinary paths, so the existing selector tests and the mcpx-test-affected recipe are unaffected.
    • Review: Codex round 1 found three real gaps, all fixed in 0f2a00d and re-reviewed clean — the new suite is wired into the Go-equipped unit job in mcpx-test.yml and registered as mcpx.scripts.affected-run-injection; run() decodes subprocess output with surrogateescape so non-UTF-8 filename bytes can't crash the selector; the space-in-filename test now asserts the whole path appears in the executed commands (it could pass vacuously before).
    • Tests: new test_affected_run_injection.py drives the real selector with --run in a scratch repo — $(touch…) and ;touch… filenames create no marker, a spaced filename stays one path. Full pkgs/mcpx/scripts/tests discover green (23 tests) pre-merge.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/securitySecurity issue or security hardeningpriority/lowNice to have; do when convenientstatus/donestatus:donetask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions