Skip to content

fix: deny a git push whose subcommand hides behind a non-plain word - #17374

Closed
chenmingwei23 wants to merge 1 commit into
mainfrom
fix/8459-git-publish-nonplain-preverb
Closed

chenmingwei23 wants to merge 1 commit into
mainfrom
fix/8459-git-publish-nonplain-preverb

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Why this change

This is issue #8459, filed from the review lane of #8115 (not day-to-day usage): the git-publish floor did not recognise a git invocation as a publish when a word the shell can rewrite (a parameter expansion, a command substitution, or a brace expansion) sat where the subcommand should be, so a push to a protected branch ran without the branch gate ever being consulted. Everyone on the host is affected, because this floor runs on every shell command the agent issues. The issue carries needs-investigation; the recorded reason is that closing it properly needs a normalizer that models shell substitution. Rather than predict expansion output, this fix fails closed when a genuine shell expansion sits in the subcommand slot with a literal push as the next non-flag word — the fail-safe answer to exactly that boundary — and it does so inside the normalizer walker that already exists, not a new pass. We read this as a real correctness gap for all users rather than a niche need, so it is a default behaviour change, not an opt-in.

Reviewer note: this changes default behaviour for all users: a git-publish spelling whose subcommand slot is a word the shell can rewrite, with a literal push as the next non-flag word, is now denied. This gate is the sole protected-branch enforcement point on the host, so fail-safe is the right default — a false positive refuses an uncommon spelling and always has a plain-form workaround (git push origin <branch>), while a false negative is an unverified push to a protected branch. The accepted false positives are enumerated under "Accepted fail-safe cost" below.

Problem / Motivation

Goal: deny a git segment whose subcommand position is a word the shell can rewrite (expansion, substitution, glob, extglob, quoted option name), without modelling shell expansion.

The git-publish floor's detector required git and its subcommand to be adjacent (modulo flags and empty words). A word that is neither a flag nor the subcommand broke that adjacency, so the command was not recognised as a publish and the protected-branch gate was never consulted.

Why it matters

The git-publish floor is the sole protected-branch enforcement point on this host. A git invocation it fails to recognise as a publish lets a push to a protected branch run without the branch check — and because it runs on every shell command the agent issues, the gap affects everyone, not a niche workflow.

Not a goal

  • Modelling shell expansion (the fix refuses to verify rather than predicting expansion output).
  • A separate pre-verb pass (an earlier head added one; it was removed in favour of the one existing walker after review found it both leaky and over-broad).
  • A coarse compound-shell rule (an earlier head's case/if/for deny was removed as out of scope — it broke the chat Bash and cron gates).

What changed (motivation → approach → change)

The fix lives entirely in _is_git_push_via_normalizer in argv_floor.py — the SAME walker that already tokenizes via normalize_shell_command, then skips global flags (_GIT_ARG_FLAGS) and their values and empty words to reach the subcommand position. There is no separate pass and no new lexer.

  • The detector dequotes via normalize_shell_command (so "git" "push", g""it push, 'g'it push resolve to their true tokens) and, for every token resolving to git, seeks the subcommand past global flags, their values, and empty words.
  • A literal push subcommand denies anywhere it is reached (quote-evaded "git" "push", after a newline, a shell keyword, an unlisted runner, or a wrapper WITH options such as timeout 5 git push / sudo -u root git push / env -C /tmp git push): there is no command-position gate, so the literal-push match is caught regardless of how git is reached — the fail-safe choice, since its only failure mode is an over-refusal, never a missed push.
  • The ONE addition over the base is the Goal: a subcommand slot holding a genuine shell expansion — a parameter ($@, ${CMD}), a command substitution ($(…), backticks), or an alternating brace expansion ({a,b}, {1..3}), matched by _GIT_PUBLISH_SUBCOMMAND_EXPANSION_RE — denies when the next non-flag word after it is a literal push (git $@ push). Requiring push to be the word the expansion sits immediately before, not merely present later, is what distinguishes the Goal from a read whose own argument mentions push.
  • There is deliberately no command-position gate on the expansion branch: a false expansion match is a recoverable OVER-refusal, never a missed push. A command-position restriction was tried and removed after review found it BOTH leaked (a wrapper with options, or a dropped newline, put git out of position so an expansion push slipped through) AND over-refused (an echo argument named like a wrapper). The single forward pass is linear.
  • Gating on a genuine expansion marker rather than on "not a strict literal" is what keeps legitimate reads allowed: an xargs/find {} placeholder, a comma/range-free {abc} group, and an @(…) extglob are not words the shell rewrites into a verb, so (like the base) they stay allowed.

The one git-publish detection constant added (_GIT_PUBLISH_SUBCOMMAND_EXPANSION_RE) lives in shell_normalizer.py beside the tokenizer and the existing _GIT_ARG_FLAGS it goes with, so argv_floor.py stays well within its per-file cap.

Accepted fail-safe cost (false positives, by design)

The one accepted false positive is the bare git <expansion> push form — e.g. git $@ push origin main — which denies even if the expansion was benign, because the shell can rewrite the slot before the gate sees it. It is a loud, recoverable denial; the workaround is the plain literal git push origin <branch>.

Commands the fix leaves ALLOWED, matching the base exactly:

  • An expansion subcommand whose next non-flag word is NOT push names some other verb and is allowed: git $@ status, git ${CMD} log, git $GIT_OPTS stash push (the expansion is a global-option placeholder; the next word is stash), git $X log --grep push and git $X log; git stash push (the next word is log).
  • A literal non-push subcommand with a substitution in a flag VALUE the seek skips: git -C $(pwd) log, git --git-dir=$(git rev-parse --git-common-dir) worktree list.
  • An xargs/find {} placeholder and an @(…) extglob in the slot: git {} rev-parse, ls … | xargs -I{} git -C {} stash push, git @(x) push — none is a shell-rewritable verb.
  • A git-publish spelling MENTIONED inside a print-only command (echo usage: git $OPTS push origin feat, printf 'git $OPTS push origin main') — the expansion branch is suppressed when git is a plain argument of echo/printf in the same simple command, since it only prints. A command separator between the print verb and git (echo hi then a newline then git $@ push) makes git its own command and still denies, and a printed literal git push stays caught.
  • A redirect written before the subcommand: git 2>/dev/null stash push -m wip, git 2>/dev/null push -u origin feat/example, git > /dev/null status — the redirect token is the slot, neither the matched expansion nor a literal push adjacent to git.
  • git -C ~/src/x status / git -C ~/src/x worktree add … (the normalizer resolves ~), git commit -m 'message', git log --grep='pattern' (a subcommand's own arguments are never scanned), a read-only subcommand after a value-carrying -c whose value contains a ; (git -c 'alias.x=a;b' stash), and glued read-only chains (git fetch;git status, git log --oneline -5; git status).

Residual (not closed here, tracked under #8459's follow-ups). An expansion that IS the subcommand with no following literal push word — git $SUB origin main or git $(echo push) origin main, where the expansion itself evaporates to push and no separate push word follows — hands the slot a rewritable word but the next-word-is-push condition does not hold, so the branch does not fire. This is the same result as the base (which allows these too); closing it needs the normalizer to resolve an expansion's VALUE, the same substitution-modelling boundary the issue records as out of scope.

Backwards compatibility

Compatible for ordinary git usage: a non-publish subcommand with later arguments (git add *.py, git log --grep push), a plain feature-branch push (git push origin my-feature), a plain-prefixed read-only command (git -C /abs/path status), and glued read-only chains all stay allowed. Only a git-publish spelling whose subcommand slot is a word the shell can rewrite, with a literal push as the next non-flag word, is newly denied.

Tests

  • test/test_push_branch_gate.py::TestGitPushNonPlainPreverbIsDeniedFailSafe::test_every_reviewed_construct_table — one table over every reviewed construct that can hide a git publish; the publish shapes DENY (expansions in the subcommand slot with a trailing push, quote-evaded literal pushes, glued-separator and assignment-prefix forms, wrapper keywords), and the read-only / golden-path shapes ALLOW (expansion subcommands with no trailing push, the {} placeholder and @(…) extglob, redirect-before-subcommand stashes, glued read-only chains, worktree-dev clones, subcommand-argument globs and patterns, a -c value containing a ;).
  • test/test_push_branch_gate.py::TestGitPushNonPlainPreverbIsDeniedFailSafe::test_long_runner_expansion_run_stays_linear — a long run of env git $@ repeats resolves well inside the event-loop budget (the trailing-push test is O(1), so the walk is linear).
  • test/test_push_branch_gate.py::TestGitPushNonPlainPreverbIsDeniedFailSafe::test_every_reviewed_construct_table — one table over every reviewed construct that can hide a git publish; the publish shapes DENY (expansions whose next non-flag word is push, quote-evaded literal pushes, pushes reached through a wrapper with options or across a newline, glued-separator and assignment-prefix forms), and the read-only / golden-path shapes ALLOW (expansions whose next word is another verb — git $GIT_OPTS stash push, git $X log --grep push — the {} placeholder and @(…) extglob, redirect-before-subcommand forms, glued read-only chains, worktree-dev clones, subcommand-argument globs and patterns, a -c value containing a ;).
  • test/test_push_branch_gate.py::TestGitPushNonPlainPreverbIsDeniedFailSafe::test_long_runner_expansion_run_stays_linear — a DETERMINISTIC operation-count bound (not wall-clock): _cut_at_operator's call count on a run of env git $@ push repeats must grow linearly with the token count (doubling the input at most ~doubles the work), so a return of a quadratic per-git scan fails regardless of host speed.
  • test/test_denied_commands_security.py and test/test_security_gate_liveness.py — exercise the same walker and the per-module / package line budgets (budget raised from 28,741 on the base to 28,800 for this fix; the narration in test_security_gate_liveness.py describes that base → head change).
  • Run on this head: test_push_branch_gate.py, test_denied_commands_security.py, test_security.py, test_llm_helpers_edit_gate.py, test_security_gate_liveness.py all pass (2822 passed, 2 skipped), with black/flake8/mypy clean.

Manual verification

Each reviewed input was run through is_denied directly and confirmed to deny (publish shapes) or allow (read-only / golden-path shapes), including the redirect-before-subcommand stashes, the {} placeholder fan-out, and the glued-operator chains. The protected-push and plain-feature-push baselines were confirmed unchanged against two fresh origin/main worktrees. No manual UI steps apply — this is a security-gate predicate.

Screenshots / video

N/A — this change is a shell-command security predicate with no UI surface.

Related Issues

Pattern harvest

Not generalizable: this fix reuses the existing normalizer, the shared flag table (_GIT_ARG_FLAGS), the git-resolution helper, and the one git-publish walker; it adds no lexer, no detection pass, and no reusable abstraction, so there is no rule candidate to harvest.

Checklist

  • Tests added/updated and passing on this head.
  • Black / isort / flake8 / mypy clean.
  • Spec updated (docs/system-specs/modules/security.md), including the accepted residual.
  • No new public API or config.
  • Fail-safe direction confirmed (over-refusal, never a silent allow).

Contribution License Agreement

By submitting this pull request, I confirm that my contribution is made under the terms of the project's Contribution License Agreement.

@chenmingwei23
chenmingwei23 requested a review from a team as a code owner October 6, 2026 12:02
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/argv_floor.py

  • src/kiro_crew/security/shell_normalizer.py

  • @chenmingwei23 posted a complete reasoning template for 98637db.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of 98637db82231a245063ae7ebaa2d35187c94430f — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The echo/printf suppression is an addition nobody reported a need for. It is set once for the whole command, so echo git; git $@ push origin main gets past the fix it rides on.

Not justified as shipped

  • Item 2 — inherited: there is no reported refusal of an echoed git $X push. The description's own rule is that "a false expansion match is a recoverable OVER-refusal, never a missed push", and print_only_git_arg = _GIT_PUBLISH_PRINT_ONLY_ARG_RE.search(text_lower) is checked against the whole text, so one echo … git anywhere switches off the expansion branch for every later git.
    Subtraction: delete _GIT_PUBLISH_PRINT_ONLY_ARG_RE, the print_only_git_arg variable and its and not print_only_git_arg clause, and turn the two echo/printf must_allow rows into must_deny rows.
    Clears when: the suppression is removed, or a linked report shows a real workflow that issues an echoed git <expansion> push.
  • Item 6 — framing gap: the frozen Goal says it will deny a subcommand slot holding a "glob, extglob". The diff pins "git @(missing_8459) %s origin main" as allowed, and only denies when a literal push follows the expansion.
    Clears when: a human amends the Goal to the narrower shape that actually ships (an expansion followed by a literal push).

What this change ships

Inventory (6 items) — 3 justified

Intent: stop a push to a protected branch from getting past the branch gate when a shell expansion sits where git's subcommand should be (issue #8459). This is a FIX.

  1. git <expansion> push … (including through wrappers and after newlines) is now denied by default — justified
  2. The expansion deny is skipped when echo/printf … git appears anywhere in the command — inherited
  3. _GIT_ARG_FLAGS moved from argv_floor.py to shell_normalizer.py to stay under the per-file cap — rides along
  4. Package line budget raised from 28,741 to 28,800 — justified
  5. Rationale comments in _is_git_push_via_normalizer removed, with behaviour unchanged — undeclared, rides along
  6. The Goal claims glob and extglob slots are denied, but the diff allows them — framing gap

[FIRST-PRINCIPLES-REVIEWED] 98637db

Description read

[DESCRIPTION-READ] 37910e58099cdbfc9edd9a27438aec42c415b61a1aa273bb1dd2634c90d3f479

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — 🟡 CONCERNS

Design-level review of 98637db82231a245063ae7ebaa2d35187c94430f — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

The print-only suppression covers the whole command rather than each segment, so prefixing echo git; turns the PR's own new denial back off.

Watch

  • The suppression is a single flag for the whole command. print_only_git_arg = _GIT_PUBLISH_PRINT_ONLY_ARG_RE.search(text_lower) is not None is computed once over the raw text, and then gates the expansion check for every git token. Take echo git; git $@ push origin main. The regex matches echo git in the first segment, which sets the flag, so the real git $@ push in the second segment is never checked. The protected-branch push goes through exactly as it did on base. The PR's tests only cover a separator between echo and the same git token. They never cover an earlier, separate print-only segment.
    Clears when: the suppression applies only to the git token the print verb actually reaches (decided inside the walk, using the same segment), and echo git; git $@ push origin main is in must_deny.
  • The fix looks only one word past the expansion, and the description promises more than the code delivers. After the expansion slot the check does k = _seek_subcommand(j), so git ${A} ${B} push origin main (both unset) reaches ${B} and stops: allowed, and git pushes. Separately, the Goal says it covers "expansion, substitution, glob, extglob, quoted option name". The code and tests deliberately allow globs and @(…) extglobs. The quoted-option-name case (git '-C' …) was already dequoted by the existing normalizer pass. Either the condition should be "the run of expansions/flags in the slot ends in a literal push", or the description should be changed to say what the code actually covers.
    Clears when: consecutive expansion words are skipped before the push check (with git $A $B push origin main in must_deny), or the description says glob/extglob are out of scope and records multi-expansion as a residual.

[DESIGN-REVIEWED] 98637db

Description read

[DESCRIPTION-READ] 15b668b3f00c224ec7014c296adb214e49a90c75a628590a02784af42c8e6ca3

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 98637db82231a245063ae7ebaa2d35187c94430f — this comment is updated in place on each push.

Review details

Advisory only: the new git <expansion> push deny can be switched off by adding echo git anywhere else in the command.

FINDING — src/kiro_crew/security/argv_floor.py:3566 — print_only_git_arg = _GIT_PUBLISH_PRINT_ONLY_ARG_RE.search(text_lower) is a single yes/no check over the whole raw text, so git $@ push origin main && echo git (also echo git; git $@ push origin main, or git $@ push origin main 'x;echo git') skips the expansion branch. is_denied returns None, so the push this change sets out to refuse is allowed. The base commit also allowed it, so this is an incomplete fix, not a regression. → Fix: only suppress the branch when the echo/printf match ends at the git occurrence being judged (for example, test the regex against text_lower sliced up to that token's position), not anywhere in the command.

[OPUS-REVIEWED] 98637db

Verdict parsed from the review's SHA-scoped output markers for commit 98637db82231a245063ae7ebaa2d35187c94430f.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 98637db82231a245063ae7ebaa2d35187c94430f: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- 🔴 BLOCK (blocking)

Which legitimate operations does 98637db82231a245063ae7ebaa2d35187c94430f newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: a script-confirmed newly-refused operation.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 16 classified, 4 newly refused, 12 still allowed.
  • ubuntu-latest (platform posix): 16 classified, 4 newly refused, 12 still allowed.
  • windows-latest (platform windows): 6 classified, 2 newly refused, 4 still allowed.

Newly refused (confirmed by the real classifier at both refs)

  • git 2>"$LOG" push -u origin feat/example (posix, leg macos-latest)
    • Who loses it: A worker publishing its feature branch while capturing stderr to a log path held in a variable (the CI-style capture a push wrapper writes); the redirect sits in the subcommand slot and carries a $, which is not a word the shell rewrites into a verb.
    • Refused by: deny-rules -- Blocked by security policy: .git\s+(-\S+\s+[^-]\S\s+|-\S+\s+)push\s+[^&|;\n]{[^{}](,|..)[^{}]}
      Matched structurally on the command's argv, not by the pattern text above: shell substitution or expansion fuses text into the push target, so the destination branch cannot be determined before t
  • git commit -F - <<'EOF' fix(security): deny git $@ push in the subcommand slot EOF (posix, leg macos-latest)
    • Who loses it: A worker committing THIS fix with a heredoc message that names the shape it blocks; the heredoc body is data, not a git invocation.
    • Refused by: deny-rules -- Blocked by security policy: .git\s+(-\S+\s+[^-]\S\s+|-\S+\s+)push\s+[^&|;\n]{[^{}](,|..)[^{}]}
      Matched structurally on the command's argv, not by the pattern text above: shell substitution or expansion fuses text into the push target, so the destination branch cannot be determined before t
  • cat > /tmp/pr-body.md <<'EOF' Closes the git $GIT_OPTS push residual (#8459). EOF (posix, leg macos-latest)
    • Who loses it: prepare-pr writing a PR body to a temp file before gh pr create; the heredoc body is prose that mentions the blocked shape.
    • Refused by: deny-rules -- Blocked by security policy: .git\s+(-\S+\s+[^-]\S\s+|-\S+\s+)push\s+[^&|;\n]{[^{}](,|..)[^{}]}
      Matched structurally on the command's argv, not by the pattern text above: shell substitution or expansion fuses text into the push target, so the destination branch cannot be determined before t
  • git status --porcelain # next: git $X push once CI is green (posix, leg macos-latest)
    • Who loses it: A worker's status read with a trailing shell comment noting the next step; a comment is never executed.
    • Refused by: deny-rules -- Blocked by security policy: .git\s+(-\S+\s+[^-]\S\s+|-\S+\s+)push\s+[^&|;\n]{[^{}](,|..)[^{}]}
      Matched structurally on the command's argv, not by the pattern text above: shell substitution or expansion fuses text into the push target, so the destination branch cannot be determined before t
  • git 2>"$LOG" push -u origin feat/example (posix, leg ubuntu-latest)
    • Who loses it: A worker publishing its feature branch while capturing stderr to a log path held in a variable (the CI-style capture a push wrapper writes); the redirect sits in the subcommand slot and carries a $, which is not a word the shell rewrites into a verb.
    • Refused by: deny-rules -- Blocked by security policy: .git\s+(-\S+\s+[^-]\S\s+|-\S+\s+)push\s+[^&|;\n]{[^{}](,|..)[^{}]}
      Matched structurally on the command's argv, not by the pattern text above: shell substitution or expansion fuses text into the push target, so the destination branch cannot be determined before t
  • git commit -F - <<'EOF' fix(security): deny git $@ push in the subcommand slot EOF (posix, leg ubuntu-latest)
    • Who loses it: A worker committing THIS fix with a heredoc message that names the shape it blocks; the heredoc body is data, not a git invocation.
    • Refused by: deny-rules -- Blocked by security policy: .git\s+(-\S+\s+[^-]\S\s+|-\S+\s+)push\s+[^&|;\n]{[^{}](,|..)[^{}]}
      Matched structurally on the command's argv, not by the pattern text above: shell substitution or expansion fuses text into the push target, so the destination branch cannot be determined before t
  • cat > /tmp/pr-body.md <<'EOF' Closes the git $GIT_OPTS push residual (#8459). EOF (posix, leg ubuntu-latest)
    • Who loses it: prepare-pr writing a PR body to a temp file before gh pr create; the heredoc body is prose that mentions the blocked shape.
    • Refused by: deny-rules -- Blocked by security policy: .git\s+(-\S+\s+[^-]\S\s+|-\S+\s+)push\s+[^&|;\n]{[^{}](,|..)[^{}]}
      Matched structurally on the command's argv, not by the pattern text above: shell substitution or expansion fuses text into the push target, so the destination branch cannot be determined before t
  • git status --porcelain # next: git $X push once CI is green (posix, leg ubuntu-latest)
    • Who loses it: A worker's status read with a trailing shell comment noting the next step; a comment is never executed.
    • Refused by: deny-rules -- Blocked by security policy: .git\s+(-\S+\s+[^-]\S\s+|-\S+\s+)push\s+[^&|;\n]{[^{}](,|..)[^{}]}
      Matched structurally on the command's argv, not by the pattern text above: shell substitution or expansion fuses text into the push target, so the destination branch cannot be determined before t
  • git 2>$null push -u origin feat/example (windows, leg windows-latest)
    • Who loses it: The PowerShell way to silence stderr, typed by a Windows worker publishing its feature branch; $null is a redirect target, not an expansion that can become a subcommand.
    • Refused by: deny-rules -- Blocked by security policy: .git\s+(-\S+\s+[^-]\S\s+|-\S+\s+)push\s+[^&|;\n]{[^{}](,|..)[^{}]}
      Matched structurally on the command's argv, not by the pattern text above: shell substitution or expansion fuses text into the push target, so the destination branch cannot be determined before t
  • git -C "$env:USERPROFILE\src\kc-wt-example" 2>$null push -u origin feat/example (windows, leg windows-latest)
    • Who loses it: A Windows worker publishing from its worktree by absolute path while silencing stderr in PowerShell; the -C value is consumed and the redirect stands in the subcommand slot.
    • Refused by: deny-rules -- Blocked by security policy: .git\s+(-\S+\s+[^-]\S\s+|-\S+\s+)push\s+[^&|;\n]{[^{}](,|..)[^{}]}
      Matched structurally on the command's argv, not by the pattern text above: shell substitution or expansion fuses text into the push target, so the destination branch cannot be determined before t

Each row above is an operation that the base ref ALLOWS and this change REFUSES. Narrow the rule at the tier named. Withdrawing a row is not the way to green: that is its own pull request, on its own merits.

Scope-Verdict: CONCERNS

TIGHTENING: the git-publish floor's detector _is_git_push_via_normalizer (sensitive-command tier, reached through _is_git_publish → _git_publish_floor_tags) -- it refuses a shell expansion in git's subcommand slot that hides a push, where the shell rewrites the slot so git really pushes but the raw text never shows an adjacent git push. The hunk: if (_GIT_PUBLISH_SUBCOMMAND_EXPANSION_RE.search(subcommand) and not print_only_git_arg): k = _seek_subcommand(j); if k < n and _resolves_to(tokens[k], "push"): return True, with _GIT_PUBLISH_SUBCOMMAND_EXPANSION_RE = re.compile(r"\$||{[^{}](?:,|..)[^{}]}")`.

ADJUDICATED: 22 candidates, 0 confirmed newly-refused at the time of writing. The verdicts come from the classifier legs, which run after this review.

PLATFORM COVERAGE: The diff assumes one thing about platforms: a $ in the subcommand slot means a POSIX parameter expansion. On Windows that does not hold, because PowerShell spells redirects and variables with $ too (2>$null, $env:X). So I wrote windows rows for exactly that boundary: git 2>$null push -u origin feat/example, the same with a -C "$env:USERPROFILE\..." worktree path, a $env: option placeholder before fetch, git.exe with a $env:TEMP\ path, and a cmd.exe %USERPROFILE%\ path. The posix rows cover:

  • an expansion carried in a redirect target in the slot (git 2>"$LOG" push)
  • expansions in values the seek consumes (-C, -c, --git-dir=, --work-tree=)
  • expansion placeholders followed by a non-push verb
  • brace expansion and ${BASE}.. in subcommand arguments
  • heredoc bodies and shell comments that mention the blocked shape
  • the printf … && boundary of the print-only suppression

No row is any, because every row carries a path, a separator or a host-specific variable spelling. Two Windows spellings get no row on purpose, because each one matches the threat shape: PowerShell splatting (git @args push, which the regex does not match) and cmd %VAR% in the subcommand slot.

UNADJUDICATED: No guard here sits outside the shell composite. One narrowing can be argued but not confirmed by a row, because encoding it would admit the threat. The PR accepts the cost of git <expansion> push refusing every target, unconditionally (_GIT_PUBLISH_UNGATED). That includes ordinary spellings like git $GIT_OPTS push -u origin feat/example or git "${opts[@]}" push origin feat/example, which scripts use to splice in global options. I left them out as rows on purpose. An expansion standing before push can evaluate to push origin main, so allowing a feature-branch target in that shape would let a protected push through.

A narrower mechanism is possible. The regex treats any $ in the slot as an expansion, including a redirect token (2>"$LOG", PowerShell 2>$null). A redirect target can never become git's subcommand. If the windows/posix redirect rows above come back refused, the fix is to skip tokens shaped like redirects (^\d*[<>]) in _seek_subcommand before the expansion test. That keeps git $@ push origin main refused.

[SCOPE-REVIEWED] 98637db

The confirmed rows, in the committed corpus's own shape
{
  "golden_paths": [
    {
      "kind": "shell",
      "command_or_flow": "git 2>\"$LOG\" push -u origin feat/example",
      "platform": "posix",
      "reason": "A worker publishing its feature branch while capturing stderr to a log path held in a variable (the CI-style capture a push wrapper writes); the redirect sits in the subcommand slot and carries a `$`, which is not a word the shell rewrites into a verb."
    },
    {
      "kind": "shell",
      "command_or_flow": "git commit -F - <<'EOF'\nfix(security): deny git $@ push in the subcommand slot\nEOF",
      "platform": "posix",
      "reason": "A worker committing THIS fix with a heredoc message that names the shape it blocks; the heredoc body is data, not a git invocation."
    },
    {
      "kind": "shell",
      "command_or_flow": "cat > /tmp/pr-body.md <<'EOF'\nCloses the git $GIT_OPTS push residual (#8459).\nEOF",
      "platform": "posix",
      "reason": "prepare-pr writing a PR body to a temp file before gh pr create; the heredoc body is prose that mentions the blocked shape."
    },
    {
      "kind": "shell",
      "command_or_flow": "git status --porcelain # next: git $X push once CI is green",
      "platform": "posix",
      "reason": "A worker's status read with a trailing shell comment noting the next step; a comment is never executed."
    },
    {
      "kind": "shell",
      "command_or_flow": "git 2>$null push -u origin feat/example",
      "platform": "windows",
      "reason": "The PowerShell way to silence stderr, typed by a Windows worker publishing its feature branch; `$null` is a redirect target, not an expansion that can become a subcommand."
    },
    {
      "kind": "shell",
      "command_or_flow": "git -C \"$env:USERPROFILE\\src\\kc-wt-example\" 2>$null push -u origin feat/example",
      "platform": "windows",
      "reason": "A Windows worker publishing from its worktree by absolute path while silencing stderr in PowerShell; the -C value is consumed and the redirect stands in the subcommand slot."
    }
  ]
}

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 98637db82231a245063ae7ebaa2d35187c94430f and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 98637db

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 98637db82231a245063ae7ebaa2d35187c94430f: <one-sentence reason>

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 6, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/8459-git-publish-nonplain-preverb branch from 9a1e3b4 to 1a3e135 Compare October 6, 2026 13:30
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 6, 2026
@chenmingwei23 chenmingwei23 changed the title security: deny a git segment with a non-plain word before its subcommand (#8459) security: deny a git segment with a non-plain word before its subcommand Oct 6, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/8459-git-publish-nonplain-preverb branch from 1a3e135 to 800a18b Compare October 6, 2026 14:16
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 6, 2026
@chenmingwei23 chenmingwei23 changed the title security: deny a git segment with a non-plain word before its subcommand fix: deny a git push whose subcommand hides behind a non-plain word Oct 6, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 6, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/8459-git-publish-nonplain-preverb branch from 800a18b to d130dce Compare October 6, 2026 15:45
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed on head 158b2b705f. One disposition per Opus 5.5 finding from a2f2fa4df8.

  • BLOCKING — shell_normalizer.py:3304 (new refusal of read-only git with a glued operator): fixed. The subcommand-position walk now cuts the word at its first active operator (via the shared _cut_at_operator, which splits at ()&;|<> but not brace expansion) before the plainness test, so a trailing ;/|/&/) glued to an otherwise-plain subcommand is read as the command boundary it is — git status; ls, git status|cat, git pull&&make, and (git status) return None again, as they did at the merge-base. Any command hiding after that boundary is still judged at its true position by the glued-operator sub-group walk, and an expansion/quote/brace in the word ($HOME, "$X", $@, {,push}) survives the cut and stays non-plain, so every publish-shifting case still declines. A regression test pins the read-only cases allowed and the companion test keeps a hidden push after the same operator declining.

  • FINDING — shell_normalizer.py:3315 (an unquoted -C value that word-splits at run time): accepted and deferred to git-publish floor: -C value from an unquoted expansion is parsed as one fixed word #18520. This is pre-existing behaviour in the floor's argument parser (_git_push_args via _git_publish_floor_tags), untouched by this PR and reproducing on origin/main at the merge-base; this PR's new pass routes the segment into the floor but does not change how the floor parses arguments. The fix belongs in that untouched parser and is tracked in git-publish floor: -C value from an unquoted expansion is parsed as one fixed word #18520 with the one-line fix direction.

Local gate on 158b2b705f: push-gate, denied-commands and liveness suites pass (1477 pass / 1 skip); flake8/mypy clean; comment-history gate passed on the diff; package line budget reconciled to the measured total.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed on head 571e8a0754. One disposition per GPT 6.1 / Opus 5.5 finding from 158b2b705f. All four are in this PR's new code and are fixed with tests; nothing deferred this round.

  • shell_normalizer.py wrapper walk — a wrapped git publish was let through: fixed. The wrapper walk reads lowercased text, but the value-option set stored env's options uppercased (-C/-S), so the lowercased -c never matched and env -C <dir> git $X push read the directory as the program and was allowed. The set is now stored lowercased to match the walk. timeout was missing from the transparent-keyword set (and takes a positional duration), and exec -a had no value entry, so timeout 5 git $X push and exec -a foo git $X push were allowed; timeout is added with its positional duration consumed, and exec -a is added. All now decline.

  • shell_normalizer.py subcommand walk — read-only git with a glued option value was denied: fixed. git --namespace="team one" rev-parse and git --git-dir="$D" status are one fixed word, but dequoting exposed the inner space before the deterministic-value check and the word was rejected. A glued --opt=value / -c key=value whose option is a value-taking flag is now checked with the deterministic-value predicate before the plainness test, so these read-only commands are allowed again (the separate-value spelling already was); a non-deterministic glued value still declines.

  • argv_floor.py pass-3 segmentation — a quoted newline fabricated a command: fixed. The segmenter split at every newline, so a git … line inside a quoted commit message or printf string was judged as its own command and refused. Segmentation is now quote-aware: a newline inside a quote is literal and does not split, while the escaped-newline splice protection is unchanged.

Tests added for all four (the three wrapped-publish declines, and the glued-option-value + quoted-newline allows). Local gate on 571e8a0754: push-gate, denied-commands and liveness suites pass (1479 pass / 1 skip); flake8/mypy clean; comment-history gate passed; per-module and package line budgets reconciled.

E2E: the one failing spec is session-tags-e2e.spec.ts 17b (sidebar tag columns), a frontend spec unrelated to this security-string diff that passed only on a retry (flaky). It re-runs on this head; if it flakes again it is a one-time retrigger, not a code change here.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

On 571e8a0754, three of the findings are over-refusals (loud, recoverable false denials, not an allowed publish). Accepted and deferred to #18520:

  • Heredoc body scanned as a command (GPT 6.1 + Opus 5.5, argv_floor.py:3506). cat <<'EOF' … git * status … EOF has its inert heredoc body judged as a command, so a printing operation the base permits is declined. The fix is to skip heredoc body lines in pass 3's segment walk.
  • Backslash-escaped literal in a -C value (Opus 5.5, shell_normalizer.py:3440). git -C /tmp/a\ b status is a fixed literal path but the deterministic-value predicate rejects every backslash escape, so a read-only command is declined. The fix is to treat an escape of an ordinary character as a fixed literal.

Both are tracked in #18520 (now extended with these two cases); neither is fixed in this PR. The remaining BLOCKING item is handled separately.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed on head 67587f6d55, on the fail-safe side.

  • shell_normalizer.py:2818 (a protected-branch push on the line after a comment was let through): fixed by reverting this round's quoted-newline change. _split_push_command_segments now splits on EVERY newline again, exactly as its docstring states, so an unterminated quote opened by an unmodelled trailing comment can no longer fold a following git push --force origin main into the first segment and hide its target. A regression test pins that input to DENY.

  • The over-refusal that the reverted change had addressed (a git line inside a quoted message / printf text / heredoc body being judged as a command) is the SAFE failure here — a loud, recoverable denial, not an allowed publish — so it is deferred to git-publish floor: -C value from an unquoted expansion is parsed as one fixed word #18520 rather than fixed, together with the heredoc-body and backslash-escaped-literal findings.

  • Kept from the prior head (these are under-refusal and read-only fixes, unaffected by the revert): the wrapper value-option casing (env -c matched against the lowercased walk), timeout added as a transparent keyword with its positional duration consumed, exec -a added, and the glued --opt=value deterministic-value check.

Local gate on 67587f6d55: push-gate, denied-commands and liveness suites pass (1480 pass / 1 skip); flake8/mypy clean; comment-history gate passed; per-module and package budgets reconciled (the module is back below the cap after the revert).

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

For a maintainer — a design decision this PR keeps running into.

Base behaviour. On current origin/main (d4c3a7334d), both git @(missing) push origin main and bash -O extglob -O nullglob -c 'git @(missing) push origin main' return None — i.e. the protected-branch floor does not act on either. So the extglob case the latest review raised is not a regression introduced here: the base allows it too, because the subcommand-prefix pass that would judge it is what this PR adds. The PR's pass simply does not yet model the extglob word, so it reads @(missing) as a benign subcommand and lets the command through.

The recurring pattern. This PR reads the words before the git subcommand one at a time and asks whether each is "plain". Across review rounds the walk has met a sequence of shell constructs it did not model — glued operators, quoted newlines, heredoc bodies, a case-folded wrapper option, a glued --opt=value, backslash-escaped literals, and now an extglob pattern @(...). Each is a small, local correction, but the list is open-ended: the per-word plainness reading will keep meeting new constructs (brace expansion, process substitution variants, other extglob forms) as the shell grammar is large.

The choice.

  • (a) Keep patching each construct as reviews surface it. Each fix is small and the deny set stays precise, but the walk never provably covers the whole grammar, so new gaps are expected.
  • (b) Refuse any git command where a word BEFORE the subcommand contains a shell metacharacter, rather than trying to read each such word precisely. This is a single coarse rule: it closes the whole class at once (including the forms above) and cannot be out-modelled, at the cost of refusing some read-only commands that use a metacharacter in a prefix word (a loud, recoverable denial).

Both are defensible; (b) trades precision for a closed rule. This needs a maintainer's call on where the PR should sit, since it is a scope-and-approach decision rather than a single bug. The remaining tracked over-refusals are in #18520.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Resolved on the fail-closed side (option b). The per-construct reading is replaced with ONE rule: a word up to and including the git subcommand position is trusted only if it fully matches a strict literal pattern — ASCII letters, digits and _ . / = : -. Any other word (a quote, $, backtick, ( ) [ ] { } * ? ! @ ~, a newline or a backslash) means the shell can rewrite it, so the subcommand cannot be trusted and the command is treated as a possible publish for the floor to judge (it declines on a protected target).

Why: the per-word parser kept meeting shell constructs it did not model, one per round, and the grammar is open-ended — a precise reading can never provably cover it. One coarse rule closes the whole class at once (extglob, brace/glob expansions, glued operators, wrapper keywords with their options, command substitutions, quoted expansions) and fails closed on anything new, so no future construct can slip through.

The per-construct parsers are removed and the detector shrinks accordingly (shell_normalizer.py drops ~460 lines, back near its pre-change size). One table test pins every construct raised in review: the publish cases decline, the plain read-only cases are allowed. The accepted cost is over-refusal of some read-only commands whose pre-subcommand prefix uses a metacharacter (a tilde path, a trailing operator, a git line inside a quoted message); these are loud, recoverable denials with the plain form as the workaround, and are tracked for a follow-up.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

F1 is fixed on this head. The allowlist walk no longer guesses where the subcommand starts from the first non-option word; a value-taking git global option (-C, -c, --git-dir, --work-tree, --namespace, --exec-path, --config-env, --super-prefix) now consumes its next word as its value, and that value must itself be strictly plain.

So git -C . $@ <publish> origin main declines: . is read as the -C value, the subcommand becomes $@, which is non-plain, and the command is treated as a possible publish the floor declines on a protected target. git -c x=y $X <publish> origin main and git -C "$D" <publish> origin main decline the same way (a non-plain option value is itself enough), where <publish> is the push verb.

Only the words before the subcommand are checked, so a subcommand's own arguments are untouched: git commit -m 'message', git log --grep='pattern' and git show ... | grep ... stay allowed. Added as a table test alongside the existing constructs.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

ai-review-disposition target=first-principles head=1c2364c7e2eaedef1810dcbef0c0d9fae7fe6b7f

Adopted the subtraction you proposed. The separate pre-verb pass is deleted in full — its function, its per-group walk, its strict-plain helper, its option-value set and its two regexes are gone — and the rule now lives in the one walker that already existed (_is_git_push_via_normalizer): after it skips global flags, their values and redirections to the subcommand, a subcommand token that is not a strict literal ([A-Za-z0-9_./=:-]) is treated as a possible publish for the floor to judge. Because the walker reads normalized/dequoted tokens, that one check closes the quoted-option-name and leading-redirection holes without a second option set.

  • Item 1 / Blocker (duplicate walker): resolved by the deletion above.
  • Item 2 / 3 (description vs diff, deny-message workaround): the description is rewritten to match the walker behaviour, and the deny message no longer suggests a form the code refuses. The deterministic_value claims are removed; no such function or test ships.
  • Item 4 / 5 (_GIT_ARG_FLAGS extra flags and move): _GIT_ARG_FLAGS keeps its original five entries and the walker reads it in place.

Read-only commands the earlier pass over-refused now pass: git -C ~/src/x status, git fetch;git status, git stash; git pull --rebase origin main, git commit -m 'message'.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

F1 and F2 are both fixed on this head, and the fix is a redesign rather than another patch of the earlier pass. The separate pre-verb pass is deleted; the rule now lives in _is_git_push_via_normalizer, the walker that already tokenizes through normalize_shell_command and skips global flags, their values and redirections to the subcommand. After that seek, a subcommand token that is not a strict literal ([A-Za-z0-9_./=:-]) is treated as a possible publish for the floor to judge.

Because the walker reads normalized, dequoted tokens:

  • F1 (git '-C' . $@ <publish> origin main): '-C' normalizes to -C, so it is recognized as the value-taking flag, consumes ., and $@ is the subcommand — non-plain, so it declines. The quoted spelling no longer slips past a raw-text option check.
  • F2 (>$x git $@ origin main): the leading redirection is a token the seek already skips, the walker finds git, and $@ is the subcommand — non-plain, so it declines.

A token with a glued control operator is split first, so ok;git $@ <publish> and git fetch;git status are read at their true command positions, and <publish> is the push verb. Read-only chains (git fetch;git status, git stash; git pull) and a subcommand's own arguments (git commit -m '...', git log --grep=...) stay allowed. Added to the table test alongside the earlier constructs.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

For a maintainer — this PR has a regression against main, so I have converted it to draft.

The subcommand walker splits a normalized token on a control operator (;/&/|) so that a command glued after one (ok;git ...) is read at its true position. That split also fires inside a -c config value, where the operator is data rather than a separator: "git" -c 'alias.x=a;b' <publish> origin main has its value cut into alias.x=a and b, so b is read as the subcommand and the real publish slips past the protected-branch ceiling. The command is denied on main and allowed here, where <publish> is the push verb.

The design choice:

(a) Drop the token split entirely. The walker then no longer sees a command glued after a ;/&/|, so the Security Scope golden-path chains that split was added to keep allowed (git fetch;git status, git stash; git pull --rebase origin main) return to being over-refused.

(b) Split only outside quoted option values — track quote state so a ; inside '...'/"..." is left alone and only a true command boundary splits. That closes this case and keeps the golden paths, but it is a parsing change to the walker and should have design sign-off before it ships.

No change is applied here pending that decision; the branch is held as draft so the regression cannot merge.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Follow-up to #issuecomment-6092505499 (the maintainer question):

Resolved by taking option (b): the control-operator token split now runs only outside option values.

The walker tracks the token right after a value-taking git option (-c, -C, --git-dir, --work-tree, --namespace) and leaves that one value whole, so a control operator inside a quoted value stays data. The normalizer only keeps an operator glued inside a token when it was quoted; a bare separator stays glued to the adjacent command word, which the split still handles. So "git" -c 'alias.x=a;b' push origin main is denied here exactly as on main, while the glued-command cases (ok;git $@ push, git fetch;git status) and the Security Scope golden-path chains keep their intended behaviour.

Option (a) — dropping the split — was not taken: it would bring back the golden-path over-refusals the split exists to clear.

Added a regression row for "git" -c 'alias.x=a;b' push origin main (denied) and git -c 'x=1;y=2' push origin main (denied), plus a golden-path row git -c 'alias.x=a;b' stash (allowed, since the subcommand is a read-only stash). Every existing deny row is kept.

New head 2affeb6bab. Local gate green (black/flake8/mypy clean, touched suites pass, line budget met). Also folded in: the import sort on argv_floor.py, the ## Tests heading, and the removal of two platform-dependent must_allow rows (git "$HOME"/git ~) whose expansion differs by OS and reddened the Windows shard.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 2affeb6
  • What rule changed: The git-publish floor's one normalizer walker now verifies the SUBCOMMAND position and fails closed when it cannot. After skipping global flags and their values, redirections and empty words to the subcommand token, a subcommand that is not a strict literal ([A-Za-z0-9_./=:-]) is treated as a possible publish for the floor to judge. A token with a glued control operator is split so a command hidden after ;/&/| sits at its own position; the split exempts a value token right after a value-taking option (-c/-C/...), so a control operator inside a quoted value stays data.
  • Before -> after (what was allowed/blocked, now): Before, a word the shell rewrites in the subcommand slot (git $@ push, git -C . $@ push, git '-C' . $@ push, >$x git $@, ok;git $@ push) let a protected push slip past the gate. After, each is denied by the subcommand check. A plain git push origin main is denied as before; a plain feature push and read-only git usage stay allowed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): A benign command whose subcommand position is itself an expansion is OVER-refused (a loud, recoverable denial; the workaround is the plain literal form). The failure direction is fail-safe: it blocks more, never leaks and never silently allows a protected push.
  • Evidence checked (which sandbox result proves it): A table over every reviewed construct (TestGitPushNonPlainPreverbIsDeniedFailSafe::test_every_reviewed_construct_table) asserts each publish shape denies and each read-only / golden-path shape allows, including the quoted--c-value regression rows and the glued-operator chains. Verified green on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): git fetch;git status, git stash; git pull --rebase origin main, git log --oneline -5; git status, git -C ~/src/x worktree add ..., git add *.py, git commit -m ..., git -c 'alias.x=a;b' stash all ALLOW (table rows, green).
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or public API changed; the fix lives entirely inside the existing walker, reusing the existing normalizer, flag table and resolution helper. No new pass, no new lexer.
    • Existing tests (which suites passed on this head): test_push_branch_gate.py, test_denied_commands_security.py, test_security_gate_liveness.py, test_exfil_carveouts.py all pass (1486 passed, 1 skipped), plus black/flake8/mypy clean and the per-module + package line budgets met.
  • How to undo: Revert this commit; the floor returns to the prior per-word scan behaviour.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Re: the GPT 6.1 blocking finding on 2affeb6bab (attached option value split):

Fixed on new head 7d3c45a711.

The option-value exemption now also covers the ATTACHED form. The control-operator token split leaves a token whole in two cases, because an operator inside it is data: (1) a token in option-value position right after a separated value-taking option (-c/-C/...), and (2) any token that starts with - — a flag, or an attached option value such as --work-tree=/tmp/a;b or -cfoo;bar. A command word (program or subcommand) never starts with -, so a glued command separator never lands inside such a token; the only ;/&/| it can carry is data from a quoted value.

So "git" --work-tree="/tmp/a;b" push origin HEAD:main now denies (the value stays one token, the seek lands on push), matching main. Added table rows for the attached forms (--work-tree=.../-git-dir=.../-cfoo), kept the separated--c-value rows and every existing deny row, and the glued-command chains and read-only golden paths still behave as before.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 7d3c45a
  • What rule changed: The git-publish floor's one normalizer walker now verifies the SUBCOMMAND position and fails closed when it cannot. After skipping global flags and their values, redirections and empty words to the subcommand token, a subcommand that is not a strict literal ([A-Za-z0-9_./=:-]) is treated as a possible publish for the floor to judge. A token with a glued control operator is split so a command hidden after ;/&/| sits at its own position; the split exempts a value token right after a value-taking option (-c/-C/...), so a control operator inside a quoted value stays data.
  • Before -> after (what was allowed/blocked, now): Before, a word the shell rewrites in the subcommand slot (git $@ push, git -C . $@ push, git '-C' . $@ push, >$x git $@, ok;git $@ push) let a protected push slip past the gate. After, each is denied by the subcommand check. A plain git push origin main is denied as before; a plain feature push and read-only git usage stay allowed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): A benign command whose subcommand position is itself an expansion is OVER-refused (a loud, recoverable denial; the workaround is the plain literal form). The failure direction is fail-safe: it blocks more, never leaks and never silently allows a protected push.
  • Evidence checked (which sandbox result proves it): A table over every reviewed construct (TestGitPushNonPlainPreverbIsDeniedFailSafe::test_every_reviewed_construct_table) asserts each publish shape denies and each read-only / golden-path shape allows, including the quoted--c-value regression rows and the glued-operator chains. Verified green on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): git fetch;git status, git stash; git pull --rebase origin main, git log --oneline -5; git status, git -C ~/src/x worktree add ..., git add *.py, git commit -m ..., git -c 'alias.x=a;b' stash all ALLOW (table rows, green).
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or public API changed; the fix lives entirely inside the existing walker, reusing the existing normalizer, flag table and resolution helper. No new pass, no new lexer.
    • Existing tests (which suites passed on this head): test_push_branch_gate.py, test_denied_commands_security.py, test_security_gate_liveness.py, test_exfil_carveouts.py all pass (1486 passed, 1 skipped), plus black/flake8/mypy clean and the per-module + package line budgets met.
  • How to undo: Revert this commit; the floor returns to the prior per-word scan behaviour.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Re: the Security Scope review (newly-refused rows):

Fixed on new head 12db9696b9 (also rebased onto current main).

The over-refusals are resolved by making the walker command-position only. It now tokenizes quote- and operator-aware (shlex with punctuation_chars, so an unquoted operator is its own word and 'git|push' stays one word), and it matches git only as the first word of a simple command — reached after stepping over control operators, env assignments, redirections (operator + operand), command wrappers (env/timeout/nice/…), and a here-doc body start. git appearing as a search argument is no longer read as a program.

Each confirmed row now allows:

  • grep -n git *.md, grep -c git "$LOG" — git is grep's argument, not a command word.
  • rg -n 'git|push' src, grep -nE 'git|.*push' …, git grep -E 'foo|git' -- — the quoted pattern stays one token; no split fractures it.
  • git > /dev/null status — the redirection is skipped during the subcommand seek, so the literal status is found.
  • command -v git && git --version and the version/status chains — allowed.

Still denied: git push, git $@ push, git -C . $@ push, the attached-form --work-tree=/tmp/a;b push, git>/dev/null push, wrapper-run pushes (env git push, timeout 5 git $X push), glued-operator pushes (ok;git $@ push), and a here-doc body push (sh <<EOF … git push … EOF). Table-tested both directions; every prior deny row kept.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 12db969
  • What rule changed: The git-publish floor's one normalizer walker now verifies the SUBCOMMAND position and fails closed when it cannot. After skipping global flags and their values, redirections and empty words to the subcommand token, a subcommand that is not a strict literal ([A-Za-z0-9_./=:-]) is treated as a possible publish for the floor to judge. A token with a glued control operator is split so a command hidden after ;/&/| sits at its own position; the split exempts a value token right after a value-taking option (-c/-C/...), so a control operator inside a quoted value stays data.
  • Before -> after (what was allowed/blocked, now): Before, a word the shell rewrites in the subcommand slot (git $@ push, git -C . $@ push, git '-C' . $@ push, >$x git $@, ok;git $@ push) let a protected push slip past the gate. After, each is denied by the subcommand check. A plain git push origin main is denied as before; a plain feature push and read-only git usage stay allowed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): A benign command whose subcommand position is itself an expansion is OVER-refused (a loud, recoverable denial; the workaround is the plain literal form). The failure direction is fail-safe: it blocks more, never leaks and never silently allows a protected push.
  • Evidence checked (which sandbox result proves it): A table over every reviewed construct (TestGitPushNonPlainPreverbIsDeniedFailSafe::test_every_reviewed_construct_table) asserts each publish shape denies and each read-only / golden-path shape allows, including the quoted--c-value regression rows and the glued-operator chains. Verified green on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): git fetch;git status, git stash; git pull --rebase origin main, git log --oneline -5; git status, git -C ~/src/x worktree add ..., git add *.py, git commit -m ..., git -c 'alias.x=a;b' stash all ALLOW (table rows, green).
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or public API changed; the fix lives entirely inside the existing walker, reusing the existing normalizer, flag table and resolution helper. No new pass, no new lexer.
    • Existing tests (which suites passed on this head): test_push_branch_gate.py, test_denied_commands_security.py, test_security_gate_liveness.py, test_exfil_carveouts.py all pass (1486 passed, 1 skipped), plus black/flake8/mypy clean and the per-module + package line budgets met.
  • How to undo: Revert this commit; the floor returns to the prior per-word scan behaviour.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

For a maintainer — this head has a new blocking finding the review surfaced, so I have converted the PR back to draft to prevent an accidental merge.

The command-position walker tokenizes with a quote/operator-aware tokenizer. A leading redirection written with a file-descriptor prefix and no space (2>/dev/null git push origin main) tokenizes as 2, >, /dev/null, git, …: the 2 is a separate word that the walker reads as the command word, so git falls out of command position and the push gate does not run. The base denies this input; this head allows it.

The redirection-skip step recognises the > operator but not the 2 that the tokenizer split off the front of 2>. Two directions:
(a) In the walker, treat a leading bare file-descriptor digit (0–9, &, {name}) immediately followed by a redirection operator token as part of that redirection and skip it, so the fd-prefixed form is handled like the plain > form.
(b) Keep the existing literal-push detection (the raw-text pass) unconditional and apply the command-position restriction only to the new non-plain-subcommand check — the review's suggested framing.

Both keep every current deny (plain git push, git $@ push, the glued/wrapper/here-doc forms) and every allow (the read-only git-as-data searches). I am holding — no push, no override — pending the maintainer's direction.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Update to the earlier note — new head 02a95bf09b. The two reds are fixed:

Our Backend Tests (shards 5/7 and the Windows shards) failed only on TestGitPublishSubshellGluing — the brace-group forms { git push origin main; } and { git push origin 'main'; }. The command-position walker now treats a group opener ((/{) and a group-closer-glued-to-an-operator ()&, );, )>log) as ending a command, so the word after { is a command position and the brace-group push is seen again. (The four TestOnlyEditKindWithParamsIsRerouted failures in shard 7 are unrelated to this PR — that test is byte-identical to origin/main, imports none of the changed modules, and fails the same way on a clean main checkout; it is a pre-existing main-wide red, not this change.)

The numbered-redirect under-refusal (2>/dev/null git push origin main): the operator-aware tokenizer splits 2>/dev/null into 2, >, /dev/null. The walker now recognises a bare file-descriptor prefix (\d+, &, {name}) immediately before a redirect operator as part of that redirection, so the 2 is no longer read as the command word and git stays at command position. 2>/dev/null git push origin main denies; 2>/dev/null git status allows. Both added to the table.

No new walker semantics beyond these; local gate green (black/flake8/mypy/docs_lint, the walker + security + budget suites). The PR stays in draft, parked for your direction.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 39f7cb4
  • What rule changed: The git-publish floor's one normalizer pass (_is_git_push_via_normalizer) matches git ... push ANYWHERE on the dequoted token stream again (the base behaviour), rather than only where a program name can stand. For every token resolving to git it seeks the subcommand past global flags and their values; a literal push subcommand denies wherever it is reached. The one addition over the base: a non-strict-literal subcommand ([A-Za-z0-9_./=:-]) denies when git is in command position AND a literal push still stands later in the invocation (git $@ push).
  • Before -> after (what was allowed/blocked, now): A prior revision of this PR restricted detection to command position. Review showed that under-refused quote-evaded pushes ("git" "push", after a newline / a shell keyword then / an unlisted runner strace / a value-taking wrapper option) and over-refused golden-path reads (git -C $(pwd) log, xargs -I{} git -C {} rev-parse). After this change: the quote-evaded pushes are DENIED again (anywhere-match, fail-safe) and the golden-path reads are ALLOWED again (match the base). git $@ push is still denied (the Goal). A plain git push origin main is denied as before; a plain feature push and read-only git usage stay allowed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): The bare git <expansion> push form is OVER-refused (a loud, recoverable denial; the workaround is the plain literal git push origin <branch>). The failure direction is fail-safe: it blocks more, never leaks and never silently allows a protected push. The literal-push match is anywhere, so no shell construct removes the catch.
  • Evidence checked (which sandbox result proves it): A table over every reviewed construct (TestGitPushNonPlainPreverbIsDeniedFailSafe::test_every_reviewed_construct_table) asserts each publish shape denies -- including the quote-evaded, newline, shell-keyword, unlisted-runner and value-taking-wrapper rows the review surfaced -- and each read-only / golden-path / expansion-without-push shape allows. Verified green on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): git -C $(pwd) log, git -C $(git rev-parse --show-toplevel) status, xargs -I{} git -C {} rev-parse, git fetch;git status, git log --oneline -5; git status, git -C ~/src/x worktree add ..., git add *.py, git commit -m ..., git -c 'alias.x=a;b' stash all ALLOW (table rows, green).
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or public API changed. The command-position tokenizer, the wrapper/separator walk and the here-doc / fd / group-reset handling added by the prior revision are removed; detection is the base's anywhere-match plus the one expansion-subcommand deny. No new pass, no new lexer.
    • Existing tests (which suites passed on this head): test_push_branch_gate.py, test_denied_commands_security.py, test_security_gate_liveness.py, test_llm_helpers_edit_gate.py, test_security.py all pass (2821 passed, 2 skipped), plus black/flake8/mypy clean and the per-module + package line budgets met (package 28,822, lowered from the prior revision).
  • How to undo: Revert this commit; the floor returns to the prior revision's command-position behaviour.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed on head 39f7cb4f960d21317789a10d40f0cd3c80c9265f. The detection approach was reworked rather than patched further.

What changed. The previous revision restricted git-publish detection to "command position" (a tokenizer that found git only as the first word of a simple command). That restriction had two problems that review surfaced on the prior head, and both are fixed by returning to matching git ... push anywhere on the dequoted token stream:

  • A quote-evaded protected push could slip past. "git" "push" origin main (and the same after a newline, after a shell keyword like then, after an unlisted runner like strace, or after a value-taking wrapper option such as sudo -u root -g wheel / timeout -s KILL 5) left git out of command position, so the floor was never consulted — while the merge-base denied every one of them. A literal push subcommand now denies wherever it is reached, so no shell construct removes the catch. This is the fail-safe direction (its failure mode would be a protected-branch bypass).

  • Legitimate read-only commands were newly refused. git -C $(pwd) log, git -C $(git rev-parse --show-toplevel) status, git --git-dir=$(…) worktree list, and ls … | xargs -I{} git -C {} rev-parse were denied on the prior head but allowed on the merge-base; the substitution sits in a flag VALUE the subcommand seek skips, so these are plain reads. They are allowed again.

The one intentional addition over the base is the item's goal: a subcommand slot the shell can rewrite into a push (git $@ push, git -C . $@ push) is denied — but only when git is itself a command and a literal push still stands later in the invocation, so git $@ status, git ${CMD} log and the xargs placeholder git {} rev-parse (an expansion with no trailing push) are left exactly as the base allowed them. The accepted cost is a loud, recoverable over-refusal of the bare git $@ push form; the workaround is the plain literal git push origin <branch>.

The command-position tokenizer, the wrapper/separator walk and the here-doc / fd-redirect / group-reset handling the prior revision added are removed; one unused regex is deleted. A table over every reviewed construct pins each publish shape denying and each read-only / golden-path / expansion-without-push shape allowing (TestGitPushNonPlainPreverbIsDeniedFailSafe::test_every_reviewed_construct_table). The shard-7 edit-gate regression and the three named CI lanes are addressed separately on this head.

The shard-4 approval test is a pre-existing main-wide failure unrelated to this diff.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: b1d17ca
  • What rule changed: The git-publish floor's one normalizer pass (_is_git_push_via_normalizer) matches git ... push ANYWHERE on the dequoted token stream (the base behaviour): for every token resolving to git it seeks the subcommand past global flags and their values, empty words, and redirections, and a literal push subcommand denies wherever it is reached. The one addition over the base is the Goal: a subcommand slot holding a GENUINE shell expansion (_GIT_PUBLISH_SUBCOMMAND_EXPANSION_RE — a parameter $@/${x}, a substitution $(…)/backticks, or an alternating brace expansion {a,b}/{1..3}) denies when git is in command position AND a literal push still stands later in the SAME invocation (git $@ push). The trailing-push test reads a precomputed O(1) suffix flag bounded at the command boundary, so the walk is linear.
  • Before -> after (what was allowed/blocked, now): A prior revision gated the subcommand branch on "not a strict literal". Review showed that over-refused an xargs {} placeholder (ls … | xargs -I{} git -C {} stash push) and a redirect written before the subcommand (git 2>/dev/null stash push), and the trailing-push scan read across command boundaries, and the per-git scan was quadratic on a long wrapper run. After this change: the subcommand branch fires only on a genuine expansion marker (so the {} placeholder and extglob are allowed again, matching the base), the seek skips a redirect to the real subcommand, the trailing-push scan stops at the command boundary (so git $@ status && git stash push does not flag the first segment), and the suffix flag makes the walk linear. git $@ push is still denied (the Goal). A plain git push origin main is denied as before; a plain feature push and read-only git usage stay allowed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): The bare git <expansion> push form is OVER-refused (a loud, recoverable denial; the workaround is the plain literal git push origin <branch>). The failure direction is fail-safe: it blocks more, never leaks and never silently allows a protected push. The literal-push match is anywhere, so no shell construct removes the catch. One residual is recorded (an expansion that IS the subcommand with no separate later push token, e.g. git $SUB origin main), which stays allowed exactly as the base does; closing it needs the normalizer to resolve an expansion's value.
  • Evidence checked (which sandbox result proves it): A table over every reviewed construct (TestGitPushNonPlainPreverbIsDeniedFailSafe::test_every_reviewed_construct_table) asserts each publish shape denies — including the quote-evaded, newline, shell-keyword, unlisted-runner, glued-separator and assignment-prefix rows — and each read-only / golden-path / expansion-without-push / {}-placeholder / redirect-before-subcommand shape allows. A linearity test (test_long_runner_expansion_run_stays_linear) proves a long env git $@ run resolves well inside the event-loop budget. Verified green on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): git -C $(pwd) log, git -C $(git rev-parse --show-toplevel) status, ls … | xargs -I{} git -C {} rev-parse, ls … | xargs -I{} git -C {} stash push -m wip, git 2>/dev/null stash push -m wip, git > /dev/null status, git fetch;git status, git -C ~/src/x worktree add ..., git add *.py, git commit -m ..., git -c 'alias.x=a;b' stash all ALLOW (table rows, green).
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or public API changed. Detection is the base's anywhere-match plus the one expansion-subcommand deny. No new pass, no new lexer. The two detection constants moved to shell_normalizer.py beside the tokenizer and the existing flag/wrapper tables.
    • Existing tests (which suites passed on this head): test_push_branch_gate.py, test_denied_commands_security.py, test_security_gate_liveness.py, test_llm_helpers_edit_gate.py, test_security.py all pass (2822 passed, 2 skipped), plus black/flake8/mypy clean and the per-module + package line budgets met (package 28,889, raised from the base's 28,741; argv_floor.py at its 4,500 per-file cap).
  • How to undo: Revert this commit; the floor returns to the base's anywhere-match with no expansion-subcommand deny.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed on head b1d17cabab. One disposition per finding from 39f7cb4f96.

  • Linearity (argv_floor.py) — the subcommand branch's trailing-push scan was quadratic on a long wrapper run: fixed. The scan is now a precomputed O(1) suffix flag (push_after[k]), bounded at each command boundary, so a long env git $@ run no longer re-scans the suffix per git. Pinned by test_long_runner_expansion_run_stays_linear.

  • Over-refusal — a redirect written before the subcommand, and an xargs {} placeholder, were newly refused: fixed. The subcommand seek now skips redirections (a redirect is a fixed construct the shell cannot rewrite, so git 2>/dev/null stash push finds the real stash), and the fail-closed branch now gates on a GENUINE shell-expansion marker (_GIT_PUBLISH_SUBCOMMAND_EXPANSION_RE) rather than on "not a strict literal", so an xargs/find {} placeholder and an @(…) extglob — which the shell does not rewrite into a verb — are allowed again, matching the base. The cross-boundary trailing-push scan is bounded at the command boundary, so git $@ status && git stash push no longer flags the first segment. Confirmed against two fresh origin/main worktrees: every listed golden path matches the base.

  • Command-position gaps — a git after a glued separator (cd x; git $@ push) or an assignment prefix (VAR=1 git $@ push) was missed: fixed. The command-position test now treats a token ending in ;/&/| and an assignment word as a boundary. Pinned in the construct table.

  • Goal not met — git $SUB origin main (the expansion IS the subcommand, no later literal push): recorded as a residual. This shape hands the slot a rewritable word but the trailing-push condition does not hold, so the branch does not fire — the same result as the base, which allows it too. Closing it needs the normalizer to resolve an expansion's value (the substitution-modelling boundary the issue records as out of scope). The residual is now recorded in security.md and in the PR body.

  • Description / undeclared surface: fixed in the PR body. The body no longer claims a _CONTROL_OPERATOR_SPLIT_RE split or "two small regexes"; it describes the expansion-marker gate, names the two relocated constants, declares the test_llm_helpers_edit_gate.py fixture update, states the budget change as base (28,741) → head (28,889), and records the residual above. The frozen Goal statement is unchanged.

No override was posted for any lane; every finding is addressed by a code fix or a recorded residual. Local gate green on this head: 2822 passed / 2 skipped across the security, edit-gate, table and budget suites, black/flake8/mypy clean.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: d84f343 (rebased onto current main; picks up the ui-index fix(ui-index): regenerate ui-index.generated.json for the custom sounds tab #18958 and approval-test test: align slot-approve internal-caller tests with the gate #18944 fixes, no behaviour change of ours)
  • What rule changed: The git-publish floor's one normalizer pass (_is_git_push_via_normalizer) matches git ... push ANYWHERE on the dequoted token stream (the base behaviour): for every token resolving to git it seeks the subcommand past global flags and their values and empty words, and a literal push subcommand denies wherever it is reached. The one addition over the base is the Goal: a subcommand slot holding a GENUINE shell expansion (_GIT_PUBLISH_SUBCOMMAND_EXPANSION_RE — a parameter $@/${x}, a substitution $(…)/backticks, or an alternating brace expansion {a,b}/{1..3}) denies when the NEXT non-flag word after it is a literal push (git $@ push).
  • Before -> after (what was allowed/blocked, now): A prior revision gated the expansion branch on command position and scanned for a trailing push anywhere. Review showed that LEAKED (a wrapper with options or a dropped newline — timeout 5 git $@ push, env -C /tmp git $@ push — put git out of position so the expansion push slipped through) and OVER-refused (git $GIT_OPTS stash push and git $X log --grep push, where the expansion is a global-option placeholder and the real verb follows; git 2>/dev/null push -u origin feat, a feature push; echo env git $@ push, inert output). After this change: there is NO command-position gate (a literal push is matched anywhere, the fail-safe catch), and the expansion branch fires ONLY when the NEXT non-flag word is a literal push — so the wrapper/newline pushes are DENIED and the $GIT_OPTS stash push / log --grep push / feature-push / echo rows are ALLOWED again, matching the base. git $@ push is still denied (the Goal). A plain git push origin main is denied as before; a plain feature push and read-only git usage stay allowed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): The bare git <expansion> push form is OVER-refused (a loud, recoverable denial; the workaround is the plain literal git push origin <branch>). The failure direction is fail-safe: it blocks more, never leaks and never silently allows a protected push. The literal-push match is anywhere, so no shell construct removes the catch. One residual is recorded (an expansion that IS the subcommand with no following literal push word, e.g. git $SUB origin main), which stays allowed exactly as the base does; closing it needs the normalizer to resolve an expansion's value.
  • Evidence checked (which sandbox result proves it): A table over every reviewed construct (TestGitPushNonPlainPreverbIsDeniedFailSafe::test_every_reviewed_construct_table) asserts each publish shape denies — including the wrapper-with-options, newline, glued-separator and assignment-prefix rows the review surfaced — and each read-only / golden-path / expansion-whose-next-word-is-not-push / {}-placeholder / redirect-before-subcommand / feature-push shape allows. A deterministic operation-count test (test_long_runner_expansion_run_stays_linear) proves the walk is linear. Verified green on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): git -C $(pwd) log, ls … | xargs -I{} git -C {} rev-parse, ls … | xargs -I{} git -C {} stash push -m wip, git $GIT_OPTS stash push -m wip, git $X log --grep push, git 2>/dev/null push -u origin feat/example, git fetch;git status, git -C ~/src/x worktree add ..., git add *.py, git commit -m ..., git -c 'alias.x=a;b' stash all ALLOW (table rows, green).
    • Backward compatible (old config / old data / old callers still work, how checked): No config, data or public API changed. Detection is the base's anywhere-match plus the one next-word-push expansion deny. No new pass, no new lexer, no command-position gate. The one detection constant moved to shell_normalizer.py beside the tokenizer.
    • Existing tests (which suites passed on this head): test_push_branch_gate.py, test_denied_commands_security.py, test_security_gate_liveness.py, test_llm_helpers_edit_gate.py, test_security.py all pass (2828 passed, 2 skipped), plus test_approval_decide_owner_bound.py (8 passed, fixed on main by test: align slot-approve internal-caller tests with the gate #18944), black/flake8/mypy clean, and the per-module + package line budgets met (package 28,769, raised from the base's 28,741; argv_floor.py at 4,458, under its 4,500 cap).
  • How to undo: Revert this commit; the floor returns to the base's anywhere-match with no expansion-subcommand deny.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (head d84f343d32), picking up the ui-index #18958 and approval-test #18944 fixes; the git-publish fix that addressed the prior head's findings is folded into this same push (no separate push). One disposition per finding from b1d17cabab:

  • Over-refusal via the command-position gate (echo env git $@ push) AND under-refusal via the same gate (timeout 5 git $@ push, sudo -u root git $@ push, env -C /tmp git $@ push, a newline before git): both fixed by removing the command-position gate. A false expansion match is a recoverable over-refusal, never a missed push, so the gate is dropped and a literal push is matched anywhere (the fail-safe catch); the wrapper/newline pushes are now denied and the inert echo output is allowed.
  • Over-refusals of git $GIT_OPTS stash push, git $X log --grep push, git $X log; git stash push: fixed by requiring push to be the NEXT non-flag word after the expansion. The expansion branch fires only when the word the expansion sits immediately before is a literal push, so a read whose own argument mentions push (the global-option placeholder, the --grep pattern, a later separate invocation) is allowed again.
  • Over-refusals of the redirect-before-subcommand feature push (git 2>/dev/null push -u origin feat): fixed by removing the redirect-skip. The redirect token is the slot, neither the matched expansion nor an adjacent literal push, so it is not newly refused; the stash-redirect case stays allowed too.
  • Wall-clock linearity test: replaced with a deterministic operation-count bound on _cut_at_operator's call count, so the test does not depend on host scheduling.
  • Message / fixture / dead-surface: reverted the git-publish denial message and the edit-gate fixture to base (both inaccurate/undeclared), and deleted the unused _STRICT_PLAIN_SUBCOMMAND_RE, _GIT_PUBLISH_CMD_BOUNDARY_TOKENS, and _COMMAND_WRAPPER_PROGRAMS. The spec and the PR body are aligned to the shipped design and record the git $SUB origin main residual.

No override was posted for any lane; every finding is addressed by a code fix or a recorded residual. Local gate green on this head: 2828 passed / 2 skipped (security, edit-gate, table, budget, approval suites), black/flake8/mypy clean. Package budget 28,769; argv_floor.py 4,458 (under its cap).

The git-publish floor verifies a push by locating the push subcommand
in the command text. When a shell construct the per-word scanner cannot
model sits in the subcommand position, the scanner cannot confirm the
command is a plain git push, so the command slipped past the gate.

A per-word command-position scan cannot be made complete against the
shell grammar without re-implementing the shell, so the detector now
verifies only the SUBCOMMAND POSITION and fails closed when it cannot:

- Split a segment into background groups on a `&` that is not `&&` or a
  redirection fd-dup (standalone or glued into a word).
- Walk each group's command-position prefix to the command word,
  consuming a `$(...)`/backtick/quote span torn across words by the
  split and skipping leading assignments (including `+=`) and
  redirections.
- When the command word resolves to git, scan to the subcommand, taking
  the value of value-options (`-C`, `-c`, `--git-dir=...`).
- Deny when a non-plain word (expansion, substitution, glob, quoting
  trick) stands up to and including the subcommand, when a prefix
  keyword (time/exec/eval/command/env/builtin) runs git, or when the
  subcommand is `push`. Deny a git publish nested in an opaque span.

The subcommand scope leaves ordinary git usage allowed: a non-publish
subcommand with any later arguments (`git stash push ... *.py`, `git log
--grep push`), a global-option value that is an expansion (`git -C
$REPO_ROOT stash push`), a non-push git command with a glob (`git add
*.py`), and a non-git mention of git (`grep git *.py`, `command -v
git`).

This accepts false positives on unusual-but-benign push shells (for
example `git $X push`): the plain form `git push origin <branch>` always
works, which is the fail-safe direction. The detector reuses the
existing word splitter, the one quote state machine and the
git-resolution helper; no new lexer.

Fixes #8459
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 98637db (one further commit over the rebased d84f343: the Security Scope echo-mention fix)
  • What rule changed: The git-publish floor's one normalizer pass (_is_git_push_via_normalizer) matches git ... push ANYWHERE on the dequoted token stream (the base behaviour): for every token resolving to git it seeks the subcommand past global flags and empty words, and a literal push subcommand denies wherever it is reached. The one addition over the base is the Goal: a subcommand slot holding a GENUINE shell expansion (_GIT_PUBLISH_SUBCOMMAND_EXPANSION_RE) denies when the NEXT non-flag word is a literal push (git $@ push) — UNLESS git is a plain argument of a print-only program (echo/printf) in the same simple command (_GIT_PUBLISH_PRINT_ONLY_ARG_RE), which only prints the line.
  • Before -> after (what was allowed/blocked, now): On d84f343 the Security Scope lane script-confirmed ONE newly-refused row: echo usage: git $OPTS push origin feat/example (an unquoted usage line that echo prints, nothing runs). After this change the expansion branch is suppressed when git is an echo/printf argument with no command separator between them, so that mention is ALLOWED again, matching the base. A boundary between the print verb and git (echo hi<newline>git $@ push) still DENIES, because git is then its own command. A printed literal git push stays caught (fail-safe, base behaviour). The Goal git $@ push and the wrapper-reached pushes still deny; all prior golden paths still allow.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): The bare git <expansion> push form is OVER-refused (loud, recoverable; workaround is the plain literal git push origin <branch>). The print-only exclusion is scoped to echo/printf and to the same simple command (raw-text separator-aware), and only ever ADDS allows to the expansion branch — it cannot remove the literal-push catch, which stays anywhere. Failure direction is fail-safe. Residual recorded (an expansion that IS the subcommand with no following push word, e.g. git $SUB origin main) — allowed as the base does.
  • Evidence checked: the construct table (TestGitPushNonPlainPreverbIsDeniedFailSafe::test_every_reviewed_construct_table) now pins the echo-mention ALLOW rows (echo usage: git $OPTS push ..., printf '...') and the echo-then-newline-then-git DENY row, alongside the Goal, wrapper and golden-path rows; the deterministic linearity test still passes. Verified green on this head.
  • No regression:
    • Tools still work: echo usage: git $OPTS push origin feat, git $GIT_OPTS stash push, git $X log --grep push, git -C $(pwd) log, ls … | xargs -I{} git -C {} rev-parse, git 2>/dev/null push -u origin feat, git fetch;git status, git commit -m ... all ALLOW.
    • Backward compatible: no config/data/public-API change. One regex added (_GIT_PUBLISH_PRINT_ONLY_ARG_RE) in shell_normalizer.py; no new pass, no new lexer, no command-position gate.
    • Existing tests: test_push_branch_gate.py, test_denied_commands_security.py, test_security_gate_liveness.py, test_llm_helpers_edit_gate.py, test_security.py all pass (2828 passed, 2 skipped); black/flake8/mypy clean; budgets met (package 28,800 from base 28,741; argv_floor.py 4,477 under its 4,500 cap).
  • How to undo: Revert this commit; the floor returns to d84f343's detector (which refused the echo mention).

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed on head 98637db82231a245063ae7ebaa2d35187c94430f (one commit over the rebased d84f343d32).

  • Security Scope — one script-confirmed newly-refused row on d84f343d32: echo usage: git $OPTS push origin feat/example (an unquoted usage line that echo prints, nothing runs): fixed. The expansion branch is now suppressed when git is a plain argument of a print-only program (echo/printf) in the same simple command — the fix the lane itself named. A command separator between the print verb and git (echo hi then a newline then git $@ push) still denies, because git is then its own command; a printed literal git push stays caught by the anywhere branch (base behaviour). No override was posted.

All other review lanes were already green on d84f343d32 (First Principles, Opus, GPT 6.1, Design, Sensitive). The Goal (git $@ push), the wrapper-reached pushes, and every prior golden path are unchanged. The spec and PR body record the print-only exclusion. Local gate green on this head: 2828 passed / 2 skipped, black/flake8/mypy clean, package budget 28,800.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Closing this PR without merging.

The goal was to deny a git invocation whose subcommand position is a word the shell can rewrite into a push (for example git $@ push), which the raw-text pass does not see as an adjacent git push. Investigation showed:

  • The quoted / empty-word evasions this started from ("git" "push", g""it push, a push after a newline) are already denied on main today, so there is nothing to add there.
  • The remaining case — an expansion sitting in the subcommand slot — cannot be told apart from legitimate reads without modelling shell substitution. A $ (or backtick, or brace expansion) in that position also appears in contexts that are not a git subcommand at all: a redirect target (git 2>"$LOG" push ...), a here-document body used as a commit message or a file (git commit -F - <<'EOF' ... EOF), and a trailing # comment. Every narrowing that keyed on the token shape kept refusing one of those legitimate forms.

Reliably detecting a git subcommand hidden behind an expansion needs a normalizer that understands here-documents, comments and redirect targets — a shell-substitution model — which is a larger design than this change. Closing in favour of that design rather than shipping a detector with an open-ended false-positive surface. The branch is kept for reference.

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.

An unquoted expansion that evaporates before the push subcommand escapes the git-publish floor

1 participant