Repository navigation
fix(security): refuse every git command on a no-approver hook surface - #23287
JLargent42 wants to merge 1 commit into
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The owner chose this scope in the Goal and in #21559. Two small notes: one helper is written a second time, and one inline git check elsewhere was left unchanged. Notes
What this change shipsInventory (9 items) — 7 justifiedIntent: a Meetings dispatch, which has no approver, should never run git, or anything that might be git, without a person or a hook grant approving it. FIX.
[FIRST-PRINCIPLES-REVIEWED] 4aa381c Description read[DESCRIPTION-READ] 8bd339a2dcef9a63ddbb360ab6e6fcc2fef3a0589a3aada139f8e25d36b52bdb That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The only no-approver hook surface is the Meetings dispatch; cron, heartbeat and nudge all pass Notes
[DESIGN-REVIEWED] 4aa381c Description read[DESCRIPTION-READ] d2fbdde1fcc5d010eab84a46ef7efb582051ad0e21035239515a109c95a86f3f 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 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
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: |
|
Rebased once onto main for the #23264 Windows fix. |
472efce to
5fe9d34
Compare
Sensitive change review
|
5fe9d34 to
3fc4834
Compare
|
Sensitive change review
|
|
Rebased onto main to resolve a conflict in |
3fc4834 to
a95a95b
Compare
Security Scope Review -- ✅ PASSWhich legitimate operations does Verdict basis: adjudicated, zero confirmed regressions. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: PASS Reason: The tightening is in TIGHTENING: The no-approver git refusal used to refuse only git reads ( ADJUDICATED: 20 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix rows cover the cases where the walker reads git as a possible program after a runner ( UNADJUDICATED: Guard:
Narrowing to consider, argued but not confirmed:
The PR's stated escape is a grant in the hook's [SCOPE-REVIEWED] 3734286 |
|
|
bolichen97
left a comment
There was a problem hiding this comment.
[operator: bolichen97] Approving at 7983dea.
The new refusal sits inside the same no-approver guard main already uses for headless git reads (HOOK_BASED, hooks present, no on_tool_approval), so attended surfaces that pass an approver are unchanged, and a test pins that an approver is still reached. The check can only add refusals, has no crash path on odd tool params, and stays linear.
Non-blocking:
- The substring match also refuses words that merely contain
git(for examplegithubordigit) on the no-approver surface. That is the accepted fail-closed cost; naming the matched reason in the refusal text would help an operator see why. - The test catalogue of shell spellings is long for what is a deliberately coarse substring check; a representative handful would cover it.
- The non-shell fallback reads
command/cmdon any non-MCP tool; keying it on the tool kind would narrow it.
AI-assisted, approved by bolichen97
bolichen97
left a comment
There was a problem hiding this comment.
Requesting changes at 7983dea, and this replaces my earlier approval of this head. I have also turned off the auto-merge that approval set.
The project now has a standing rule that a fix must not rely on pattern matching over text, and that covers case-blind name matching. security/readonly_bash.py:1580 adds command_names_git, and lines 1597 to 1599 strip quotes and backslashes and then refuse when "git" in text.casefold() for any of three readings. That is a case-blind substring test on the whole command line. The docstring lists what it gets wrong in both directions: false refusals such as grep digit and make docs VCS=git, and bypasses such as globs, $'\x67it' and expansions.
Please replace it with exact name matching:
- Parse the command into its programs with the existing word reader (the one
is_read_only_bashalready uses), and take each program's name at the program position. - Compare that name, after taking the basename of a path, against a fixed set such as
{"git", "git.exe"}with an exact==orin, not a casefold or substring test. - Where the command can't be parsed into words (a glob, an ANSI-C quote, an expansion at the program position), refuse because it can't be read, as a named reason, rather than by searching the text for "git".
Tests for grep digit (allowed), /usr/bin/git status (refused), GIT status (decide and pin which), and an unparsable program position (refused, with its own reason) would pin the new behaviour.
The rest of the change (refusing git writes on a surface with no approver, and judging the raw command argument for a shell tool reported as kind other) reads right to me. This point is only about how the name is matched.
Sensitive change review
|
|
@bolichen97 thanks, done on 3734286 (rebased onto main 3ef2da3).
|
Sensitive change review
|
|
@bolichen97 an update on my earlier reply: the head is now 89a099c, and the approach changed after the review lanes ran on 3734286.
|
|
|
|
|
|
bolichen97
left a comment
There was a problem hiding this comment.
Thanks. The name match is exact now, with no regex and no substring test. This head has three concrete bugs, though, each raised by a lane or by CI:
1. A git command can still run through find -exec (GPT 6.1). find . -maxdepth 0 -exec git>/dev/null commit --allow-empty -m unattended \; on a no-approver HOOK_BASED surface. _walk_program_names returns only find, because the tokenizer keeps git>/dev/null as one word. The shell then strips the redirection, and find runs git commit with the repository's hook and no approval. Please read the program word after an attached redirection is removed. Add a test that this command is refused.
2. Non-git commands are now refused (Opus 5.5, First Principles). On a no-approver surface, ordinary commands that never start git are refused where main auto-approved them. Examples are a heredoc that writes text containing git (cat > n.md <<'EOF'\ngit is great\nEOF), source .venv/bin/activate && pytest, export FOO=1 && make, bash script.sh and timeout 60 npm test. Some of these are told "this command runs git" when no git runs. This contradicts the PR's own ## Not a goal, which says these "keep the surface's default, as on main". Please keep the default for a command whose programs are readable and are not git. Add tests that these examples keep the default, and that a heredoc body is not read as a command.
3. Backend Tests (Windows) (6) fails on test_read_only_shell_git_exclusion.py::test_a_git_write_is_refused_where_no_approver_exists[FOO=1 git merge topic]. The refusal text it gets does not match the one the test expects. Please make the reason the same on every platform, and keep the test pinning it.
Separately, whether to keep the shell-grammar walker at all, versus only an exact git-name match, is a maintainer decision that is still pending. These requests fix the walker as it stands; they do not decide that question.
|
CI note for 65d7b0b: this push only pins the POSIX shell model on the The First Principles, Opus 5.5 and GPT 6.1 reds on 89a099c are waiting on an owner decision about scope on the no-approver surface: refuse dispatchers and unmodelled grammar and amend the Goal, parse each dispatcher's flags, or refuse every ungranted non-read command. No scope change will be pushed until that decision is made. |
bolichen97
left a comment
There was a problem hiding this comment.
Thanks for the update. Two of the three points from my last review are still open on 65d7b0b:
1. The find -exec bypass has no test. The diff has no case like find . -maxdepth 0 -exec git>/dev/null commit --allow-empty -m unattended \;. Please add a test that this command is refused on a no-approver HOOK_BASED surface, so the attached-redirection word is proven to be read as git.
2. Non-git commands are still refused. Opus 5.5 blocks on this head. It measured that no_approver_git_refusal returns a "cannot be read" reason for everyday commands that never start git: printf 'x\n' > f, export X=1, set -e; make, bash run_tests.sh, ls | xargs wc, a for f in *.py; do ...; done loop, echo $(date), and a heredoc containing an apostrophe. On an unattended Meetings dispatch these turns now fail, which contradicts this PR's own ## Not a goal. The new test test_a_command_whose_program_is_not_git_keeps_the_hook_based_default covers only commands whose program can be read. Please keep the default for these, for example by refusing an unreadable program only when the text actually names git, as Opus suggests. Add tests for these examples.
The refusal's advice is false for these commands. The message, and security.md, tell the operator to grant the command in auto_approve_tools. For a command whose program cannot be read, that grant can never take effect, so following the advice changes nothing. Please fix the grant path, or remove that advice from the message and the spec for this class.
Point 3, the Windows refusal text, is still open: the Windows shards have not finished on this head. I will follow up on it once they do.
Whether to keep the shell-grammar walker at all is still a pending maintainer decision; these points do not decide it.
bolichen97
left a comment
There was a problem hiding this comment.
Maintainer decision (security sign-off): not adopted. The maintainer's rule for security changes is that we do not raise security strictness, so the maintainer will not add this restriction: refusing every git command, and every command whose program cannot be read, on a hook surface with no approver.
This decision replaces my earlier change request on this PR; the three bugs I raised there no longer need fixing, because the code they were in should go. Reviewed at 65d7b0b.
Please drop the program walker and the new refusals: no_approver_git_refusal, _git_program_refusal and the constants beside them in name_grant.py, _no_approver_shell_commands and the new refusal branch in tool_approval.py, and the tests and spec text that pin them. The existing refusal on main (a git read the read-only tier declined is not run unchecked when there is no approver) stays as it is.
If a part that does not tighten anything remains that you want to keep, push that alone and I will review it; otherwise please close the PR. Thank you for the careful work on this.
Sensitive change review
|
|
Sensitive change review
|
|
Sensitive change review
|
|
bolichen97
left a comment
There was a problem hiding this comment.
Maintainer decision (security sign-off): unchanged. The rule is that we do not raise security strictness, so the new git walker and its refusals on a no-approver surface are not adopted.
Reviewed at 09a1a76. This push keeps no_approver_git_refusal, _git_program_refusal, RUNS_GIT, _GIT_PROGRAMS and _no_approver_shell_commands, and widens them: heredoc bodies are now walked too, and the new remedy text says a hook grant cannot lift the unreadable-program refusal. The spec line "The owner chose this scope" does not match the maintainer's decision on this PR.
My earlier review still stands: please drop the walker and the new refusals, and keep main's existing git-read refusal as it is. If nothing else remains, please close the PR. Thank you.
Sensitive change review
|
|
|
Closing per the maintainer security sign-off (not adopted: we do not raise security strictness). Thanks @bolichen97 for the review. |
Problem / Motivation
Goal: On a hook-based surface with no approver, every command the hook gate did not grant is refused when a program it runs is git by exact name, or when the check cannot read a program exactly; dispatchers and wrappers (
sh -c,bash script.sh,env,xargs,timeoutand similar) count as unreadable and are refused.Goal amendment (owner, @largjaco, 2026-11-04): this scope (option A) was the owner's choice; the cost is that a surface with no approver needs hook grants for wrappers such as
timeout 60 pytest. The linked issue #21559 records the same decision.Open with the owner: that stated cost was measured to be wrong. A hook grant for an unreadable command goes through
name_grant.refusal_for_event, which refuses the same dispatcher, expansion, substitution and grammar classes, and with no approver the call is rejected (name_grant_headless_reject). So on a surface with no approver,timeout 60 pytest,ls | xargs wcor aforloop cannot run at all, granted or not. The refusal text and the spec now say this, not "grant it". A git command by name can still be granted.On a hook-based surface with no approver (a Meetings dispatch),
_resolve_permissionrefused a git read (git_read_headless_reject), but a git command that is not a read (git commit,git checkout,git merge) went to the default approve when the hook gate allowed it. Those commands run programs the repository config names (hooks,core.fsmonitor) just like a read does, and nobody is there to see an approval.Why it matters
An unattended Meetings dispatch could run repository-configured programs through any non-read git command without a person or a hook grant ever approving it. The read case was already closed; this closes the rest of git on the same path.
Not a goal
security/readonly_bash.pyis untouched:is_read_only_bashkeeps its git prefixes andcommand_invokes_gitis unchanged), per the ruling on Drop git prefixes from is_read_only_bash and delete command_invokes_git #20792.name_grant.program_names, the walk the name grants and the heartbeat approver's git exclusion already use, andname_grant's_DISPATCHERStable. Grammar that walk does not model refuses; it is not extended here.python -c,node -e), or a script file sourced into the current shell (source .venv/bin/activate). Their program is readable and is not git, so they keep the surface's default, as on main. A script run by a shell (bash script.sh,base64 -d | sh) is a dispatcher and is refused, per the Goal.export,set,printf,read,source...): they keep the default.hash,alias,unaliasandshoptstay refused, since each can change which program a later name runs.gitanywhere in the case-folded text, and @largjaco accepted the shell-written spellings (glob, brace list, extglob,$'...') as a residual on 2026-11-02. At 7983dea @bolichen97 asked for exact name matching under the standing rule against pattern matching over text. This head does that, and the shell-written spellings now refuse as unreadable programs, so that residual is closed rather than accepted.What changed (motivation → approach → change)
The no-approver branch in
src/kiro_crew/llm_helpers_parts/tool_approval.pycheckedcommand_invokes_git(cmd) and is_read_only_bash(cmd), so only git reads were refused. The read test was the wrong boundary: every git command runs repository-configured programs.The branch now first asks
name_grant.no_approver_git_refusal(new, about 70 lines insrc/kiro_crew/name_grant.py) why the command may run git. It returnsRUNS_GIT, a reason the program cannot be read, or "". The first refuses asgit_headless_reject("this command runs git ..."); the second refuses asgit_unreadable_headless_rejectand names its reason in the refusal. The existing read refusal stays after it.no_approver_git_refusalmatches the program by exact name, never by searching the text:name_grant.program_names: every command position (each side of|,&&,||,;, each line, a subshell), afterVAR=prefixes, redirections and2>descriptors. It is the reader the name grants and the gateway heartbeat's git exclusion already trust. The value offind -execandrg --preis read as a program too, every occurrence, with a glued redirect split off (-exec git>/dev/nullis git).<<bash does not open (in a comment, behind a backslash, inside${...}/$[...]) or a terminator bash reads differently (a backslash-newline continuation), which hid agit commiton the next line. So a body line that reads as git, a keyword or a substitution refuses (cat > notes.md <<'EOF'holdinggit is greatorif x:refuses), and a body of plain words keeps the default.inagainst a fixed set,{"git", "git.exe", "git.com", "git.bat", "git.cmd"}. Lower-casing is the one normalisation because macOS and Windows filesystems are case-insensitive, soGIT statusruns git there; it is refused and pinned.grep digit,make docs VCS=git,cat .gitignore,cd ~/git/app && npm testkeep the default. So dorm *.tmpandecho {a,b}, whose program is readable.A program it cannot read may be git, so it refuses with its own named reason:
$(, a backtick,<(,>(,name_grant's_UNENUMERABLE), redirection operands included;program_namesdoes not model: a keyword (if,while,case,time), a function, an unclosed quote, a trailing backslash;$EDITOR,$'\x67it',/usr/bin/g?t,{g,}it([and[[, the test builtin, are exempt);name_grant's_DISPATCHERSplusflockandchronic: shells (sh -c,bash -c -e,cmd /c,pwsh),eval,env,xargs,timeout,nice,watch,paralleland the rest. Each has its own flag grammar (env -u NAME,env -S 'sh -c' ...,xargs -I REPL), so the program it runs is not read from its arguments; the dispatcher refuses whatever follows. This is the same rule the name grants apply._DISPATCHERSbuiltins that run no named program (export,declare,local,set,printf,read,let,source,....) are exempt here, by exact name. A dispatcher is matched lower-cased, as git is, so/bin/BASH -c ...and/usr/bin/ENV git ...refuse on case-insensitive filesystems.No regex, casefold or substring test decides the name. The work is a tokenize plus one set lookup per program, linear in the command's length, and nothing is resolved on
PATH.The command judged is the recovered shell command, or, when none was recovered and the call names no MCP server, the tool's own
command/cmdargument (_no_approver_shell_commands, the same fallback as the hook gate'sraw_shell_commands). The DeepSeek harness streamsbashas kindother, so it has no recovered shell command.The refusal names the remedy that works. For a git command it is a grant in the hook's
auto_approve_tools(a title pattern such asRunning: git status*), which approves earlier in the same function after the name-grant check. For an unreadable command it says a hook grant cannot lift it, because the name-grant check refuses the same command, and to name the program directly or run it where an approver exists. The security spec (docs/system-specs/modules/security.md) and the resolver comment say the same.Backwards compatibility
Compatible: attended surfaces and hook-granted commands behave as before. On a no-approver hook surface, an ungranted command that runs git, or whose program cannot be read (a dispatcher such as
timeout 60 pytest, a keyword such asif), changes from approved to refused. A hook grant lifts the git refusal, not the unreadable one.Removes nothing: no key, record, function or route is removed; new audit reasons
git_headless_rejectandgit_unreadable_headless_rejectsit besidegit_read_headless_reject, and no code reads them.Tests
In
test/test_read_only_shell_git_exclusion.py, next to the existing git-read case:test_a_git_write_is_refused_where_no_approver_existsand the non-shell-kind and MCP cases: non-read git is refused with this branch's own reason text, and an MCP tool'scommandargument is not read as shell text.test_command_names_git_reads_git_as_the_programandtest_a_command_that_runs_git_is_refused_where_no_approver_exists: by name (/usr/bin/git status,GIT status,Git.EXE,git.cmd), quoted and escaped spellings, glued redirections, quoted executable paths, andfind -exec/rg --prevalues (each one, also after an escaped\;).test_command_names_git_names_why_a_program_cannot_be_readandtest_a_command_whose_program_cannot_be_read_is_refused_where_no_approver_exists: dispatchers (includingenv -u bash git ...,bash -c -e '...',env -S 'bash -c' '...',xargs -I sh git ...,find . -exec sh -c true {} + -exec git ...,rg --pre sh --pre git), keywords and functions, globs, brace lists, extglobs, ANSI-C quotes, expansions, substitutions (includingcat <<< "$(git status)") and unresolvable quoting each refuse with their own reason, not the git one.test_command_names_git_passes_a_command_whose_program_is_not_gitandtest_a_command_whose_program_is_not_git_keeps_the_hook_based_default:grep digit README.md,make docs VCS=git,cat .gitignore,findstr /n git,rm *.tmp,echo {a,b},[ -f a.txt ] && rm a.txt, a heredoc of plain words, and builtins (export FOO=1 && make,source .venv/bin/activate && pytest,set -e; make test,printf) keep the default.bash scripts/build.sh,timeout 60 pytestandbash <<EOFrefuse as dispatchers.test_the_windows_model_reads_a_git_exe_path_as_git: under the Windows model,C:\tools\git.exeand a quoted"C:\Program Files\Git\bin\git.exe"refuse as git. The shared rows pin the POSIX model, so a Windows host reads them as a POSIX host does.test_a_git_write_still_reaches_an_approver_that_exists,test_git_by_name_still_reaches_an_approver_that_existsandtest_an_unreadable_program_still_reaches_an_approver_that_exists: with an approver, nothing changes.test_command_names_git_stays_linear: 20,000 nested substitutions, 40,000 commands, 200,000 redirections, 200,000 arguments and 100,000-execoptions under a 60s timeout.Revert proof: with main's
name_grant.pythe new tests cannot importno_approver_git_refusal, and with the old branch (only git reads refused) the git-write cases fail. The heredoc rows from review (echo hi # <<EOF,echo a\<<EOF,<<'E'OF,${x:-<<EOF },$[1<<2 ], a continued terminator) and the upper-case dispatchers (/bin/BASH,/bin/SH,/usr/bin/ENV,XARGS) each kept the default on c1672eb or c6010e8 and refuse here. A redirection between-exec/--preand its program (-exec </dev/null git ...,-exec 2>&1 git ...,--pre=</dev/null git) kept the default on 09a1a76 and now refuses as unreadable. The file passes 422 of 422.Manual verification
N/A — unit coverage sufficient: the change is one refusal branch in the permission resolver and a check over an existing walk, driven directly by the tests above.
Related Issues
Closes #21559
Sibling sweep
Swept: git grep -n "command_invokes_git|program_names(" -- src/
Sibling: src/kiro_crew/slack/gateway_runtime/tool_policy.py -- not affected -- its heartbeat check already refuses git and any unestablished program set through
program_names, and requires a proven readSibling: src/kiro_crew/hook_runtime/gate_tiers.py -- not affected -- only excludes git from auto-approve, the surface approver decides
Sibling: src/kiro_crew/dashboard/chat_turn/tool_approval.py -- not affected -- attended surface, an approval card exists
Pattern harvest
Not generalizable: the defect was a single extra condition on one refusal branch; the class (git runs repository-configured programs) is already centralised in
command_invokes_gitandprogram_names.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)