Repository navigation
fix(security): read the program word of every command in the publish floor - #18871
cruisercohen wants to merge 2 commits into
Conversation
Sensitive Change ReviewSensitive files changed:
How to clear this check:
Only the author's comment counts this way. A reviewer can instead |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No blocking design issue: the subject really is a shell command line, the sandbox does not hold pushes, and the change only adds detection that fails closed. Reverting it is clean. Notes
[DESIGN-REVIEWED] fde505b Description read[DESCRIPTION-READ] 41c3c142780c9816259996b366633984ee3968300351393e8a8b9a49307362d1 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS No item fails on reading alone. The heredoc exception lists are the sort of spelling-chase AGENTS.md calls a review smell, but whether they are the cause or a symptom is a judgement call, and they can be deleted later. Notes
What this change shipsInventory (10 items) — 6 justifiedIntent: stop an agent from reaching a protected branch through a push whose program word the shell resolves at run time. FIX.
[FIRST-PRINCIPLES-REVIEWED] fde505b Description read[DESCRIPTION-READ] 02c29124c4ea46648291ef0b5569c7eae4d60e3a7cdd06554e1d5ad5d1d3168e That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — 🔴 changes requested (blocking)Reviewed Blocks: a here-doc inside a BLOCKING — src/kiro_crew/security/publish_heredoc.py:458 Notes:
[BLOCK-MERGE] fde505b Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
Sensitive change review
|
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: PASS Reason: No candidate came back script-confirmed as newly refused, so nothing meets the BLOCK bar. The patch itself names two narrowings as accepted costs, which are argued and not confirmed. First, an unquoted variable path to a non-git tool followed by TIGHTENING: the git-publish floor's detector ADJUDICATED: 31 candidates, 0 confirmed newly-refused PLATFORM COVERAGE:
[SCOPE-REVIEWED] fde505b The confirmed rows, in the committed corpus's own shape{
"golden_paths": [
{
"kind": "shell",
"command_or_flow": "npx eslint src/ --max-warnings 0 && git commit -m \"$(cat <<'EOF'\nfix(ui): example\n\n* push notifications render once\nEOF\n)\"",
"platform": "any",
"reason": "A worker runs the frontend lint gate (already a corpus row) and commits in one call. npx is neither an inert companion nor a listed plain runner, so the body is read as command text and the '* push' bullet may become an unverifiable publish."
},
{
"kind": "shell",
"command_or_flow": "python3 scripts/docs_lint.py && git commit -m \"$(cat <<'EOF'\ndocs: example\n\n* push guard steps documented\nEOF\n)\"",
"platform": "any",
"reason": "The docs gate (a corpus row) chained before a heredoc commit. For git sinks the patch accepts only the stricter companion list, not the python-script sibling, so the bullet line sits right at the boundary."
},
{
"kind": "shell",
"command_or_flow": "$ANDROID_HOME/platform-tools/adb push app-debug.apk /sdcard/Download/",
"platform": "posix",
"reason": "The unquoted spelling Android docs and READMEs give for the sideload; the patch names it an accepted cost. Submitted so the loss is measured, not assumed."
},
{
"kind": "shell",
"command_or_flow": "\"$DOCKER\" push registry.example.com/kirocrew-crew-base:ci",
"platform": "posix",
"reason": "An operator with DOCKER=podman publishing the crew base image (scripts/publish_crew_base_image.sh pushes the same tag); the patch names quoted-variable docker push an accepted cost."
},
{
"kind": "shell",
"command_or_flow": "& $env:LOCALAPPDATA\\Android\\Sdk\\platform-tools\\adb.exe push app-debug.apk /sdcard/Download/",
"platform": "windows",
"reason": "The unquoted PowerShell spelling of the sideload. PowerShell does not word-split a variable, but the floor's POSIX split-into-words rule may still treat it as unverifiable."
}
]
} |
GPT 6.1 Review — ✅ no blocking findings (all downgraded on adjudication)GPT 6.1 flagged blocking issues on This comment is updated in place on each push. Review detailsBLOCKING -- src/kiro_crew/security/shell_normalizer.py:1316 -- Limit flock payload extraction to its own command option
Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 — LOW. The failure is a false denial of a harmless command, and it is loud: False positive or not applicable? A repository writer can comment: |
Sensitive change review
|
b2d916c to
9ce2f9a
Compare
Sensitive change review
|
9ce2f9a to
daa9801
Compare
Sensitive change review
|
daa9801 to
c715612
Compare
Sensitive change review
|
|
span=47f81b5dc672
|
|
span=35be53b639ba
|
Sensitive change review
|
|
span=f45b8903c18c
|
|
span=8777d0bf16e6
|
|
span=c59845e61b5e
|
|
span=c98d1df910b1
|
|
span=0628b72d94b4
|
|
span=1068a77932a8
|
|
span=aeb3770523ed
|
Sensitive change review
|
Sensitive change review
|
Sensitive change review
|
Sensitive change review
|
Sensitive change review
|
Sensitive change review
|
Sensitive change review
|
Sensitive change review
|
Sensitive change review
|
Sensitive change review
|
Status: handing this to maintainersHead
We've stopped iterating: each fix round on this normalizer has surfaced a new AI-lane finding, so the next step needs a maintainer's direction. Two ways forward:
@iamwhatever @bolichen97, which would you prefer? |
…floor A push run under a program word the shell resolves at run time (a quoted expansion, a path around one, a glob that can name git, a substitution) is now detected in every program position of the line: after newlines, glued separators and background operators, inside compound constructs, behind precommands and redirections. Such a segment is unverifiable and cannot defer to, or borrow a verdict from, a feature push in its own arguments.
Move the program-position reading into publish_program_word.py. Split
commands quote- and substitution-aware, read the program's top-level
basename, model precommand operands, and read git's argv with the
literal-push grammar when the program word is one double-quoted
expansion.
Read each word ANSI-C decoded, a long option by any prefix of a
value-taking one, and value options across GNU, BSD and util-linux
spellings. Once a word of unknown arity is read (a runtime dispatcher or
operand, an option spelled with an expansion or glob, an option value an
expansion can split, an abbreviation that may be a no-value option), a
later runtime word running push is unverifiable. A closer closes only the
opener it matches, and --config-env takes a value.
Read a floor line that starts inside a quote in that quote. Treat git
fetch and git push without a transport-program option, and cat, as inert
companions; glab as a sink; cat piped into a sink as feeding it; a plain
${NAME} and a sink option's value as voiding nothing; a CRLF printer as a
printer; and a body cat or tee only writes to a plainly named file,
beside sinks, companions, chmod and mkdir alone, as data. Beside a plain
test or build runner, or a git beside a file write, read only a leading
markdown bullet as ":", in a sink's body and in a file-written body alike.
A gh or glab body gets that bullet reading beside git checkout, switch or
stash, a plain git rebase onto refs, or a .py or .sh script run by its
path, too:
neither sink runs a hook on its body. A git commit, notes or tag body keeps the stricter list. A file
path is git's when a component carries .git, but .github is not one.
A redirection target ends at the next unquoted operator, so a chained
</dev/null> leaves its last target to the next word, as bash reads it,
and a literal git with a redirection before its subcommand is read here
and judged by its target. An unquoted variable path program word is
unverifiable whatever argv follows: split, its first word can be any
program, so an argv git would reject proves nothing.
A ${...} parameter expansion holding whitespace stays one shell word, as
$(...) and backticks already do, so the word after it is not misread as
the program. A target-neutral flag may carry its one-word value attached
(--git-dir="$REPO/.git"), and push glued to a letter (pushed) is another
word, not the subcommand.
A >| noclobber redirection is one operator, not a pipeline boundary, so
the program word before it and push after it are one command. A heredoc
body written to an executable a sibling command then runs by its basename
(> ~/.local/bin/sleep; chmod +x; sleep) stays command text, so companion
membership does not exempt the installed script. git branch is a read-only
companion, so a gh or glab body bullet beside it is text.
Bash ends a heredoc body only at a line that matches its delimiter case
for case, while the floor reads the command lowercased. Where a body line
matches its delimiter only in another letter case, the floor also reads
the command with no heredoc and line by line, and judges each reading as a
publish source like any other. A heredoc with no protected publish keeps
its reading, and operator opt-outs apply as they do to any publish.
Inside a substitution body, decide whether a case arms and an esac
disarms by shell_normalizer_walk's _arms_case_context and
_in_command_position, the rules _matching_close_paren uses, rather than
a local command-position test, and derive the program lead words from
_KEEPS_COMMAND_POSITION less the precommands time and coproc.
Beside a sink, a join of the two standard streams (2>&1, >&2) opens no
file and does not void the exemption, head and tail are inert companions,
mypy is a plain runner, and a plainly named file may carry a Git Bash
drive letter (c:/...).
The rm floor reads dequoted words, so it reads a leading redirection
unchained, as main does: _push_token_redirection(chained=False). The
chained-target reading needs the token's quoting.
The segment splitter opens a substitution span only on an unescaped
active $, and a span the text never closes (an opener in a quoted
heredoc body or a comment) falls back to the split without spans, as
main splits.
|
Status on fde505b (nothing pushed). Opus's new blocking finding on this head (publish_heredoc.py:458, a here-doc inside a command substitution that ends on a tag-plus-closer line) is a gap in the runtime-program push coverage this PR adds. It is not a regression against main. We ran 10 rows (the exact shape, variants and controls) through scripts/deny_diff.py against main d579985. Main allows that shape too, because main does not judge runtime-program pushes at all, so 0 rows are newly allowed. This head refuses the variants. A fail-closed fix is ready and only refuses more: inside a substitution, end the body at a tag-plus-closer line or refuse the read. It is not pushed. The PR is also CONFLICTING with main again. We're holding the branch until you pick from 6435558132: option 1 (accept as-is and track this residual plus the over-blocks as follow-ups) or option 2 (we push this fix and a conflict-only rebase first). |
|
Thank you for this work, @cruisercohen. On 2026-11-08 the maintainers decided to keep the current shell reader and to stop patching shell spellings one at a time in the command-text checks, including the git publish floor. The OS sandbox is the enforcement point, and known spelling gaps are recorded as stated residuals: #21682 (comment) . The linked issue #17745 was closed under that decision, so I am closing this PR too. Please comment if you think it covers more than a spelling gap. |
Problem / Motivation
Goal: The git-publish floor judges every publish whose program word the shell resolves at run time, wherever it sits on the command line.
The floor recognised a runtime-resolved program word (
$G push ...) only in a few top-level spellings. The same publish was not judged when the word was quoted ("$G","${G}"), wrapped in a path ("/usr/bin/$G"), spelled as a glob that can name git (g?t), or placed in a compound construct (if/case/for/whilebodies, subshells, brace groups, function bodies), behind a precommand (sudo,env,nice -n 5,timeout), after a newline, a glued separator or a background&. A literal feature push elsewhere on the line, or among the command's own arguments, could also stand in for the unjudged one. In each caseis_deniedreturned allow for a command that publishes to a branch the gate cannot determine.Why it matters
The git-publish floor is the only enforcement for pushes. An agent command that reaches a protected branch through one of these spellings is not stopped.
Not a goal
git "$P" origin main,git pu$X ...): a separate class.gitand its subcommand, andtrap '<cmd>' EXITpayloads: existing gaps in other parts of the walk, tracked separately.Backwards compatibility
Compatible: only commands that run
pushunder a runtime-resolved program word change verdict. Another tool's push behind a variable whose argv reads as a bare or single-positional git push ("$DOCKER" push img,"$HG" push) is refused by the bare / single-arg rows, which operators can disable; the unquoted$DOCKER push imgis already refused on main. Accepted fail-closed costs of the same kind: a program word carrying an unquoted expansion ($ANDROID_HOME/platform-tools/adb push app.apk /sdcard/,$VENV/bin/dvc push -r storage), whose value is split into words and may name any program first, so even an argv git would reject proves nothing (the quoted"$VENV/bin/dvc" push -r storagestays allowed);"$GIT" -C "$WORKTREE" push, since lowercased-Ccannot be told from-c; and a runtime tool's push after an option and a runtime value ("$TOOL" --flag "$V" push).Removes nothing: the change only adds detection; no rule, key or public function is removed or renamed.
What changed (motivation → approach → change)
Symptom: the publish detector matched the program word textually, so quoting, nesting and precommands moved it out of the shapes it knew. Root cause: there was no notion of PROGRAM POSITION on the raw, quote-aware command text.
Change:
publish_program_word.pyin the security package (kept apart so the argv floor's modules stay under the per-module cap)._runtime_publishessplits the text into the commands the shell runs at top level (;,|, newline, non-redirection&, bare(/); never inside$(...),${...},<(...)or backticks, which the payload walk judges as their own sources), folds line continuations, and walks each command's raw words. Program position opens at the first word, after! { do elif else if then until while, afterfunction NAME, and after a precommand's options and positional operands; assignments and redirections keep it open._is_git_publish(_is_git_push_via_normalizer, as on main) and the_GIT_ARG_FLAGSset it reads move into a new sibling module,publish_subcommand.py, andargv_floor_git.pyre-binds both names;publish_program_word.pyreads the flag set from there too. The pass moves unchanged. The flag set gains git's three other value-taking global options,--attr-source,--config-envand--super-prefix, so the word after one is read as its value, as git reads it, and a runtime-program publish after one ("$G" --super-prefix x push origin feature) is judged by its target, as one after-Cis.$or a backtick, or is an unquoted glob that can name git, followed by thepushsubcommand, is a runtime-program publish. A literal basename behind a variable directory ("$SDK/platform-tools/adb") is that program._git_publish_floor_tagsjudges each runtime-program publish on its own, so a sibling command or a feature push in its arguments cannot answer for it. When the program word is ONE double-quoted parameter expansion and the words up topushare literal, git's argv is known and is read with the literal-push grammar (protected / bare / single-arg rows as usual); otherwise the existing ungated unverifiable deny applies."$G" push origin feature; git \<newline> push origin main) still reaches the unverifiable fallback, as on main.$(...)/${...}/ backtick span whole, so a;/&/|/newline inside a command substitution is read as the substitution's own and does not cut the surrounding command; a publish glued to such a span (git$(echo ' ';)push origin main) is then judged as the one command it is rather than left in an unrecognised fragment. A plain(subshell or{group is unchanged._is_git_publishdocstring, the security spec and the package line budget are updated.#to its newline) are cut before the read, with the quote state restarted after them, so a quote inside a comment cannot hide the next line. Every heredoc body is cut from the command text around it, so a quote inside it cannot reopen that text, and is then read as command text of its own (up to a fixed nesting depth, past which the text is unverifiable). The delimiter is read by bash's quote removal ($'EOF',E\OFandE""OFareEOF;"E\OF"isE\OF;$Xis literal); a delimiter this reading cannot reproduce exactly is unverifiable. A body fed to a data sink (gh issue|pr|release,git commit|notes|tag, no editor option) is data, but only when the rest of the text runs inert companions alone (cd,ls,pwd,true,test,echo,sleep,git add|diff|log|rev-parse|show|status, no assignment before them) and carries no>,$(, backtick,<(,${or function definition: any other program could install a hook, filter, editor orPATHentry that runs the body. An unquoted delimiter's body is joined across trailing backslashes before the delimiter comparison, as bash joins it, and is never data when it carries an expansion.$(...), backticks,<(...),>(...),${...}) is read in a quote context of its own, as bash reads it even inside double quotes, so a quote, comment or heredoc inside one cannot reopen the command text around it; each command substitution body is read again as command text. A program word carrying an unquoted expansion anywhere ($G/repo) is a runtime program, since the value is split into words.getoptreads them (env -iu NAME), andcommand -v/-Vare lookups that run nothing."$HOME\bin\git.exe","$env:ProgramFiles\Git\cmd\git.exe") is one word and is judged by its target.NAME+=value,NAME[i]=value) keep program position open, and an&is a redirection only beside an active<or>(an escaped\>&still ends the command).xargs,parallel,watch) makes a runtime-program publish behind it unverifiable, and a program word's ANSI-C quoting is decoded before it is classified ($'adb'isadb).g"i"[t]keeps its active[t]; a\is read both as a Windows separator and as a POSIX escape.nice -n,sudo -u,timeout -s, ...), socommand -p echo "$G" pushandnice -n5 echo ...readechoas the program."$G"</dev/null,push>log) is cut off it, a redirection target is consumed whole (>$(echo /dev/null)),coproc NAME { ... }reads its group, and an extglob group in the program basename (g@(i)t) is a runtime program word."${GIT}") no longer counts as expansion glue for the segment, and a_GIT_ARG_FLAGSvalue that is one quoted parameter expansion (-C "$REPO") keeps the argv known.$(...)whose body is onlycatprinting one quoted-delimiter heredoc, inside a command text whose other commands are sinks or inert companions, is message text: its body is data, andis_denieddoes not read the payload walk's lifted copy of it on its own.xargs -l/-L,sudo -p/-P) is read both ways on the lowercased text. A word that can expand to no word (${x:-${y:-}},"$@$@", an extglob undernullglob) leaves program position open. The sink editor check matches abbreviations (--edi).\as an escape, a program word's$counts only while the literal text after its last expansion could endgitorgit.exe, so"$env:ProgramFiles\...\docker.exe" push imgnamesdocker.exeon both readings of\.$'env'isenv). Precommand value options are listed across the GNU, BSD and util-linux spellings (env -a, BSDenv -P,sudo --chroot,watch -q), a long option is read by any prefix of a value-taking one (env --un NAME), and--attr-sourcejoins git's value-taking global flags. A word taken as an option's value that itself runspushunder a runtime program is unverifiable.sudo --login, any option ofparallel), any later runtime word runningpushis unverifiable:"${1:-env}" -i "${2:-git}" push origin main,flock "$F" echo "$G" push origin main,env -u $1 "$2" push origin feature.--config-envand--super-prefixtake git's next word, and a)or}closes only the opener it matches ("${1:-x)/adb}"has no top-level/).echo "athenb"; "$G" push origin main), and a line wholly inside a quoted argument (a multi-line--body "... * push the branch", a PowerShell here-string) is marked as text when no other segment is spelled like it.git fetchandgit push(unless they carry a transport-program option,--upload-pack,--receive-pack,--exec, or a prefix of one) andcatare inert companions beside a sink;glab issue|mr|releaseis a sink;cat <<'EOF' | gh pr create --body-file -feeds the sink; a plain${NAME}and the word after a sink's value-taking option (--head "$BRANCH") void nothing; a CRLF printer is a printer.catorteeonly writes to a plainly named file (not a device path, not a path git reads, not in a pipeline), in a whole command text beside only sinks and companions, is data: it runs only through a reader set up before the command, which would run whatever any command writes there. Beside agit,ghorglab(which run hooks a repository may keep executable, such as.husky/pre-commit), and in a sink body beside a plain test or build runner (make test,uv run pytest -q), the body stays command text and only a leading markdown bullet is read as:.cat <<'A'; bash <<'B'), a line continuation between a substitution opener's two characters ($\<newline>() still opens it, and an unquoted glob that can expand to an option name (--[e]dit,*) counts as the editor option. The plain runners a sink's bullet is text beside aremake,pytest,ruff check|format,npm|pnpm|yarn test,npm|pnpm|yarn run <script>andpre-commit run, with plain words only;chmodof plainly named paths beside a body only written to a file leaves that body data."$DVC" push -r storage) whose argv afterpushopens with a short optiongit pushdoes not take publishes nothing as a git push: git exits with a usage error before it reads a remote. An unquoted variable path ($VENV/bin/dvc push -r storage) stays refused, a deliberate fail-closed cost: split, its value can be any program first (bash -cwith a payload of its own), so an argv git would reject proves nothing about it.endunder<<END) keeps its reading and operator opt-outs apply as usual.Alternatives considered and rejected:
_GIT_PUBLISH_SUBST_PROGRAM_RE: a whole-string regex cannot track quoting or compound grammar. It stays as the existing cheap first pass; the new pass is the canonical reader for this class.normalize_shell_commandtokens: those are dequoted and drop newlines, so quoted)/;read as syntax and newline-separated commands merge.pushas unverifiable: refuses"$G" push origin feature,"$HELM" push chart oci://...and similar commands whose argv is fully known.sudo echo "$x" push; precommand operands are modelled instead.>&3, a FIFO or link set up in the same command, a write inside a substitution whose output a shell reads, or a hook agitbeside it runs hands the body back to a program. Only a plain file write in a whole command text beside sinks and companions is data. A heredoc fed to another program, or to a sink beside a program that can run code the text carries, whose text itself reads as a runtime-program push ("$X" push origin main) over-refuses.$ANDROID_HOME/platform-tools/adb push ...) by its literal basename, as the quoted form is: split, its value may be git with options of its own that move the target the written words name (-c remote.origin.push=feature:mainturns a writtenorigin featureinto an update ofmain).catas a sink in general: its output is the body, and a process substitution read by a shell (bash <(cat <<'EOF' ...)),bash -c "$(cat <<'EOF' ...)",eval, a pipe into a shell or an unquoted substitution runs or re-splits it. Only the double-quoted printer feeding a sink or companion is data, andis_deniedskips the payload walk's lifted copy of exactly that body.Tests
test/test_git_publish_program_word.py(713 cases): one-word runtime programs judged by target; multi-word, glob and substitution program words unverifiable; every program position (newline, glued and background separators, continuation, redirections, precommands with options, ANSI-C and abbreviated options, words of unknown arity, split option values, mismatched closers, every compound construct, functions,casepatterns glued to the program, quoted backticks, substitution-valued flag operands, pipes inside substitutions, lines that start inside a quote, sibling and argument-carried feature pushes, nested payloads); ordinary commands and the legitimate operations the scope lane listed (adb, dvc, helm, cachix, multi-line quoted bodies, push or fetch beside a sink, file writes,catinto a sink,glab, CRLF printers, bullets beside a plain runner) stay allowed, and each new exemption has refusal cases for the spellings that could run the body. Every case added for the last two review rounds fails on the head before it and passes here.test_security_gate_liveness.py: package budget re-pinned with its reason.Security suites (push branch gate, security, denied-commands, hooks, deny guidance, argv floor, regex linearity, facade, rule seam, read-only filters, gate liveness and the program-word suite; 3,902 tests) pass locally on this head.
Manual verification
N/A — the gate is a pure function of the command text and the cases drive
is_deniedend to end.Related Issues
Fixes #17745
Pattern harvest
Rule candidate: review-prompt
Pattern: a command-shape detector that matches a program name textually instead of reading program position on quote-aware shell words misses quoted, nested and precommand spellings.
Checklist
Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.