Repository navigation
fix: deny a git push whose subcommand hides behind a non-plain word - #17374
chenmingwei23 wants to merge 1 commit into
Conversation
Sensitive Change ReviewSensitive files changed:
|
First Principles Review (Opus 5.5) — 🟡 CONCERNSPremise-level review of 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 Not justified as shipped
What this change shipsInventory (6 items) — 3 justifiedIntent: 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.
[FIRST-PRINCIPLES-REVIEWED] 98637db Description read[DESCRIPTION-READ] 37910e58099cdbfc9edd9a27438aec42c415b61a1aa273bb1dd2634c90d3f479 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS The print-only suppression covers the whole command rather than each segment, so prefixing Watch
[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 |
Opus 5.5 Review — ✅ no blocking findingsReviewed Review detailsAdvisory only: the new FINDING — src/kiro_crew/security/argv_floor.py:3566 — [OPUS-REVIEWED] 98637db Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
Security Scope Review -- 🔴 BLOCK (blocking)Which legitimate operations does Verdict basis: a script-confirmed newly-refused operation. Security scope review -- adjudicated candidates
Newly refused (confirmed by the real classifier at both refs)
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 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
No row is 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 A narrower mechanism is possible. The regex treats any [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."
}
]
} |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
9a1e3b4 to
1a3e135
Compare
1a3e135 to
800a18b
Compare
800a18b to
d130dce
Compare
|
Addressed on head
Local gate on |
|
Addressed on head
Tests added for all four (the three wrapped-publish declines, and the glued-option-value + quoted-newline allows). Local gate on E2E: the one failing spec is |
|
On
Both are tracked in #18520 (now extended with these two cases); neither is fixed in this PR. The remaining BLOCKING item is handled separately. |
|
Addressed on head
Local gate on |
|
For a maintainer — a design decision this PR keeps running into. Base behaviour. On current 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 The choice.
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. |
|
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 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 ( |
|
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 ( So Only the words before the subcommand are checked, so a subcommand's own arguments are untouched: |
|
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 (
Read-only commands the earlier pass over-refused now pass: |
|
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 Because the walker reads normalized, dequoted tokens:
A token with a glued control operator is split first, so |
|
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 ( The design choice: (a) Drop the token split entirely. The walker then no longer sees a command glued after a (b) Split only outside quoted option values — track quote state so a No change is applied here pending that decision; the branch is held as draft so the regression cannot merge. |
|
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 ( 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 New head |
Sensitive change review
|
|
Re: the GPT 6.1 blocking finding on Fixed on new head 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 ( So |
Sensitive change review
|
|
Re: the Security Scope review (newly-refused rows): Fixed on new head The over-refusals are resolved by making the walker command-position only. It now tokenizes quote- and operator-aware ( Each confirmed row now allows:
Still denied: |
Sensitive change review
|
|
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 ( The redirection-skip step recognises the Both keep every current deny (plain |
|
Update to the earlier note — new head Our Backend Tests (shards 5/7 and the Windows shards) failed only on The numbered-redirect under-refusal ( 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. |
Sensitive change review
|
|
Addressed on head What changed. The previous revision restricted git-publish detection to "command position" (a tokenizer that found
The one intentional addition over the base is the item's goal: a subcommand slot the shell can rewrite into a push ( 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 ( The shard-4 approval test is a pre-existing main-wide failure unrelated to this diff. |
Sensitive change review
|
|
Addressed on head
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. |
Sensitive change review
|
|
Rebased onto current main (head
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; |
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
Sensitive change review
|
|
Addressed on head
All other review lanes were already green on |
|
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
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. |
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 literalpushas 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
pushas 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
gitand 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
case/if/fordeny 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_normalizerinargv_floor.py— the SAME walker that already tokenizes vianormalize_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.normalize_shell_command(so"git" "push",g""it push,'g'it pushresolve to their true tokens) and, for every token resolving togit, seeks the subcommand past global flags, their values, and empty words.pushsubcommand denies anywhere it is reached (quote-evaded"git" "push", after a newline, a shell keyword, an unlisted runner, or a wrapper WITH options such astimeout 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 howgitis reached — the fail-safe choice, since its only failure mode is an over-refusal, never a missed push.$@,${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 literalpush(git $@ push). Requiringpushto 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.gitout of position so an expansion push slipped through) AND over-refused (anechoargument named like a wrapper). The single forward pass is linear.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 inshell_normalizer.pybeside the tokenizer and the existing_GIT_ARG_FLAGSit goes with, soargv_floor.pystays well within its per-file cap.Accepted fail-safe cost (false positives, by design)
The one accepted false positive is the bare
git <expansion> pushform — 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 literalgit push origin <branch>.Commands the fix leaves ALLOWED, matching the base exactly:
pushnames 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 isstash),git $X log --grep pushandgit $X log; git stash push(the next word islog).git -C $(pwd) log,git --git-dir=$(git rev-parse --git-common-dir) worktree list.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.echo usage: git $OPTS push origin feat,printf 'git $OPTS push origin main') — the expansion branch is suppressed whengitis a plain argument ofecho/printfin the same simple command, since it only prints. A command separator between the print verb andgit(echo hithen a newline thengit $@ push) makesgitits own command and still denies, and a printed literalgit pushstays caught.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 literalpushadjacent 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-cwhose 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
pushword —git $SUB origin mainorgit $(echo push) origin main, where the expansion itself evaporates topushand no separatepushword 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 literalpushas 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-cvalue containing a;).test/test_push_branch_gate.py::TestGitPushNonPlainPreverbIsDeniedFailSafe::test_long_runner_expansion_run_stays_linear— a long run ofenv git $@repeats resolves well inside the event-loop budget (the trailing-pushtest 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-cvalue 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 ofenv git $@ pushrepeats must grow linearly with the token count (doubling the input at most ~doubles the work), so a return of a quadratic per-gitscan fails regardless of host speed.test/test_denied_commands_security.pyandtest/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 intest_security_gate_liveness.pydescribes that base → head change).test_push_branch_gate.py,test_denied_commands_security.py,test_security.py,test_llm_helpers_edit_gate.py,test_security_gate_liveness.pyall pass (2822 passed, 2 skipped), with black/flake8/mypy clean.Manual verification
Each reviewed input was run through
is_denieddirectly 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 freshorigin/mainworktrees. 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
origin/mainare tracked as a follow-up in git-publish gate: compound shell constructs and arg-derived payloads are not verified #17745.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
docs/system-specs/modules/security.md), including the accepted residual.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.