Skip to content

fix(security): refuse every git command on a no-approver hook surface - #23287

Closed
JLargent42 wants to merge 1 commit into
mainfrom
fix/no-approver-hook-refuses-git
Closed

JLargent42 wants to merge 1 commit into
mainfrom
fix/no-approver-hook-refuses-git

Conversation

@JLargent42

@JLargent42 JLargent42 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

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, timeout and 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 wc or a for loop 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_permission refused 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

  • Changing the read-only classifier (security/readonly_bash.py is untouched: is_read_only_bash keeps its git prefixes and command_invokes_git is unchanged), per the ruling on Drop git prefixes from is_read_only_bash and delete command_invokes_git #20792.
  • A new shell-grammar walker. The check reuses name_grant.program_names, the walk the name grants and the heartbeat approver's git exclusion already use, and name_grant's _DISPATCHERS table. Grammar that walk does not model refuses; it is not extended here.
  • Reading a program that writes and runs git from its own data (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.
  • Refusing builtins that run no named program (export, set, printf, read, source ...): they keep the default. hash, alias, unalias and shopt stay refused, since each can change which program a later name runs.
  • Changing attended surfaces: where an approver exists, git still reaches it.
  • History of the matching rule: earlier heads matched git anywhere 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.py checked command_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 in src/kiro_crew/name_grant.py) why the command may run git. It returns RUNS_GIT, a reason the program cannot be read, or "". The first refuses as git_headless_reject ("this command runs git ..."); the second refuses as git_unreadable_headless_reject and names its reason in the refusal. The existing read refusal stays after it.

no_approver_git_refusal matches the program by exact name, never by searching the text:

  • The programs come from name_grant.program_names: every command position (each side of |, &&, ||, ;, each line, a subshell), after VAR= prefixes, redirections and 2> descriptors. It is the reader the name grants and the gateway heartbeat's git exclusion already trust. The value of find -exec and rg --pre is read as a program too, every occurrence, with a glued redirect split off (-exec git>/dev/null is git).
  • Every line is walked, a heredoc body's included. This check only refuses, and two heads that skipped bodies were each bypassed by a << bash does not open (in a comment, behind a backslash, inside ${...} / $[...]) or a terminator bash reads differently (a backslash-newline continuation), which hid a git commit on the next line. So a body line that reads as git, a keyword or a substitution refuses (cat > notes.md <<'EOF' holding git is great or if x: refuses), and a body of plain words keeps the default.
  • Each program's basename is lower-cased once and tested with in against 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, so GIT status runs git there; it is refused and pinned.
  • A word that only contains the letters is an argument: grep digit, make docs VCS=git, cat .gitignore, cd ~/git/app && npm test keep the default. So do rm *.tmp and echo {a,b}, whose program is readable.

A program it cannot read may be git, so it refuses with its own named reason:

  • a command or process substitution anywhere ($(, a backtick, <(, >(, name_grant's _UNENUMERABLE), redirection operands included;
  • grammar program_names does not model: a keyword (if, while, case, time), a function, an unclosed quote, a trailing backslash;
  • a name the shell expands: $EDITOR, $'\x67it', /usr/bin/g?t, {g,}it ([ and [[, the test builtin, are exempt);
  • a dispatcher from name_grant's _DISPATCHERS plus flock and chronic: shells (sh -c, bash -c -e, cmd /c, pwsh), eval, env, xargs, timeout, nice, watch, parallel and 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. _DISPATCHERS builtins 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/cmd argument (_no_approver_shell_commands, the same fallback as the hook gate's raw_shell_commands). The DeepSeek harness streams bash as kind other, 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 as Running: 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 as if), 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_reject and git_unreadable_headless_reject sit beside git_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_exists and the non-shell-kind and MCP cases: non-read git is refused with this branch's own reason text, and an MCP tool's command argument is not read as shell text.
  • test_command_names_git_reads_git_as_the_program and test_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, and find -exec / rg --pre values (each one, also after an escaped \;).
  • test_command_names_git_names_why_a_program_cannot_be_read and test_a_command_whose_program_cannot_be_read_is_refused_where_no_approver_exists: dispatchers (including env -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 (including cat <<< "$(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_git and test_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 pytest and bash <<EOF refuse as dispatchers.
  • test_the_windows_model_reads_a_git_exe_path_as_git: under the Windows model, C:\tools\git.exe and 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_exists and test_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 -exec options under a 60s timeout.

Revert proof: with main's name_grant.py the new tests cannot import no_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 / --pre and 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 read
Sibling: 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_git and program_names.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@JLargent42
JLargent42 requested review from a team and KiroCrewCaptain as code owners October 23, 2026 02:14
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 23, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 4aa381c562e98832cc825d27f443b40186b6fa63 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 4aa381c562e98832cc825d27f443b40186b6fa63 — 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 does not.

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

  • Item 5 — duplicate of src/kiro_crew/hook_runtime/gate_tiers.py:184: the new _no_approver_shell_commands docstring says it judges the argument "as the hook gate's GateFacts.raw_shell_commands does". That makes it a second copy of the same fallback, with the same MCP-server exclusion, and the two copies will drift apart. Subtraction: read the one fallback from both sites and delete _no_approver_shell_commands and its llm_helpers.py export.
  • Item 1 — point patch, 1 unfixed sibling. I grepped program_names( outside name_grant.py and found one inline git test, at slack/gateway_runtime/tool_policy.py:235 (p.rsplit("/", 1)[-1].lower() == "git"). It does not catch .exe/.cmd names or -exec/--pre values, so the name _GIT_PROGRAMS now has two spellings that disagree. Subtraction: replace that inline test with the _git_program_refusal name match.

What this change ships

Inventory (9 items) — 7 justified

Intent: 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.

  1. Git commands that are not reads (commit, checkout, merge) are now refused on a hook surface with no approver — justified
  2. Commands whose program can't be read (wrappers, sh -c, timeout, substitutions, keywords, globbed names) are refused there, and no grant can lift it — justified
  3. Heredoc body lines are checked too, so body text that reads as git or a keyword refuses — justified
  4. The values of find -exec and rg --pre are read as programs — justified
  5. The tool's raw command/cmd argument is judged when a harness streams its shell tool as kind other — duplicate of hook_runtime/gate_tiers.py raw_shell_commands
  6. Separate refusal texts and audit reasons (git_headless_reject, git_unreadable_headless_reject) that name the remedy — justified
  7. The existing git-read refusal is reworded — justified
  8. New name_grant.no_approver_git_refusal / RUNS_GIT, with one consumer — justified
  9. The security spec's paragraph on readonly_bash.py now describes the broader refusal — justified

[FIRST-PRINCIPLES-REVIEWED] 4aa381c

Description read

[DESCRIPTION-READ] 8bd339a2dcef9a63ddbb360ab6e6fcc2fef3a0589a3aada139f8e25d36b52bdb

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 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 4aa381c562e98832cc825d27f443b40186b6fa63 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. The only no-approver hook surface is the Meetings dispatch; cron, heartbeat and nudge all pass on_tool_approval. The owner chose this scope, and a revert undoes it.

Notes

  • The owner approved this scope believing wrappers could be granted, which the description shows is false: on Meetings, timeout 60 pytest, xargs and loops cannot run at all. Get the owner to sign off on that corrected cost on security: should a no-approver hook surface refuse every git command? #21559 before this merges.
  • The git_read_headless_reject branch still runs after the new check. The new check already refuses every git command and every unreadable one, so that branch probably never fires. If so, delete it instead of rewording its text.

[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 .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 23, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 4aa381c562e98832cc825d27f443b40186b6fa63 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 4aa381c

Verdict parsed from the review's SHA-scoped output markers for commit 4aa381c562e98832cc825d27f443b40186b6fa63.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 4aa381c562e98832cc825d27f443b40186b6fa63 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 4aa381c562e98832cc825d27f443b40186b6fa63 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4aa381c

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 4aa381c562e98832cc825d27f443b40186b6fa63 false-positive: <reason, 20 to 500 characters>

@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 23, 2026
@JLargent42

Copy link
Copy Markdown
Contributor Author

CI note for head 472efce: Backend Tests (Windows) (4) failed on two xdist worker crashes in test/test_config_api.py (recorded as #23294); that job has been re-run once. Backend Tests (Windows) (7) is the main-side failure tracked in #23259 and fixed by #23264; it is not caused by this diff.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Rebased once onto main for the #23264 Windows fix.

@JLargent42
JLargent42 force-pushed the fix/no-approver-hook-refuses-git branch from 472efce to 5fe9d34 Compare October 23, 2026 06:31
@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 23, 2026
@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 3fc4834
  • What rule changed: on a hook-based surface with no approver, a shell command the hook gate did not grant is refused when it names git at a command position, a substitution's included, read or not; before, only a git read was refused there.
  • Before -> after (what was allowed/blocked, now): before, a non-read git command such as a commit reached the surface's default approve when the hook allowed it; now it is refused. A command whose program cannot be read from its text is refused only when it is also a read, exactly as before, and otherwise keeps the default approve.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a git command on an unattended hook-based surface (a Meetings dispatch) is refused when an operator expected it to run; the remedy is a hook grant. No attended surface, credential path or login is affected.
  • Evidence checked (which sandbox result proves it): no sandbox rule changes. test_read_only_shell_git_exclusion.py drives the permission resolver on the no-approver surface: git writes and git inside a substitution are refused with the branch's own reason, unreadable non-git writes and plain writes keep the default, and an approver still decides.
  • No regression:
    • Tools still work (which tools/commands were run, result): the read-only classifier, heartbeat approver, name-grant surface and tool-gate suites pass; command_invokes_git and its other callers are unchanged.
    • Backward compatible (old config / old data / old callers still work, how checked): no config or data format changes; hook grants still approve git first, checked by the existing resolver tests.
    • Existing tests (which suites passed on this head): test_read_only_shell_git_exclusion.py, test_facade_mirror_guards.py, test_campaign_facades_base_public_names.py, test_llm_helpers_tool_gate.py, test_llm_helpers_deny_notice.py, test_name_grant_surfaces.py, test_heartbeat_safe_tools.py and test_security*.py (the security-conductor verifier failures also fail on main locally), plus isort, flake8, mypy, black, semgrep and docs lint.
  • How to undo: revert the single commit; the no-approver branch returns to refusing git reads only.

@JLargent42
JLargent42 force-pushed the fix/no-approver-hook-refuses-git branch from 5fe9d34 to 3fc4834 Compare October 23, 2026 07:34
@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 23, 2026
@JLargent42

Copy link
Copy Markdown
Contributor Author
  • fixed: span=4538e27d7327 non-git commands with a substitution or an expansion as the program were refused as git

Fixed in 3fc4834: the branch refuses a command only when it names git at a command position, a substitution included (readonly_bash.command_names_git), which does not count an unreadable command as git.
A command whose program cannot be read is refused only when it is also a read, the rule before this PR, and otherwise keeps the default approve.
Regression tests test_an_unreadable_non_git_write_keeps_the_hook_based_default, test_git_inside_a_substitution_is_refused_where_no_approver_exists and test_command_names_git_reads_only_what_it_can_see.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 23, 2026
@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: a95a95b
  • What rule changed: on a hook-based surface with no approver, a shell command the hook gate did not grant is refused when it names git at a command position, a substitution's included, read or not; before, only a git read was refused there.
  • Before -> after (what was allowed/blocked, now): before, a non-read git command such as a commit reached the surface's default approve when the hook allowed it; now it is refused. A command whose program cannot be read from its text is refused only when it is also a read, exactly as before, and otherwise keeps the default approve.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a git command on an unattended hook-based surface (a Meetings dispatch) is refused when an operator expected it to run; the remedy is a hook grant. No attended surface, credential path or login is affected.
  • Evidence checked (which sandbox result proves it): no sandbox rule changes. test_read_only_shell_git_exclusion.py drives the permission resolver on the no-approver surface: git writes and git inside a substitution are refused with the branch's own reason, unreadable non-git writes and plain writes keep the default, and an approver still decides.
  • No regression:
    • Tools still work (which tools/commands were run, result): the read-only classifier, heartbeat approver, name-grant surface and tool-gate suites pass; command_invokes_git and its other callers are unchanged.
    • Backward compatible (old config / old data / old callers still work, how checked): no config or data format changes; hook grants still approve git first, checked by the existing resolver tests.
    • Existing tests (which suites passed on this head): test_read_only_shell_git_exclusion.py, test_facade_mirror_guards.py, test_campaign_facades_base_public_names.py, test_llm_helpers_tool_gate.py, test_llm_helpers_deny_notice.py, test_name_grant_surfaces.py, test_heartbeat_safe_tools.py and test_security*.py (the security-conductor verifier failures also fail on main locally), plus isort, flake8, mypy, black, semgrep and docs lint.
  • How to undo: revert the single commit; the no-approver branch returns to refusing git reads only.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Rebased onto main to resolve a conflict in test/test_security_gate_liveness.py (the package line budget, which main raised for an unrelated rule); the budget now carries both raises.

@JLargent42
JLargent42 force-pushed the fix/no-approver-hook-refuses-git branch from 3fc4834 to a95a95b Compare October 23, 2026 08:00
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

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

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 13 classified, 0 newly refused, 13 still allowed.
  • ubuntu-latest (platform posix): 13 classified, 0 newly refused, 13 still allowed.
  • windows-latest (platform windows): 7 classified, 0 newly refused, 7 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

Reason: The tightening is in llm_helpers._resolve_permission's no-approver HOOK_BASED branch, not in the shell deny composite. The classifier only judges the composite, so it cannot give this change a verdict, and no regression is confirmed. Some ordinary operations are clearly refused by design on that one surface (Meetings dispatch with no approver). They are named under UNADJUDICATED and do not block.

TIGHTENING: The no-approver git refusal used to refuse only git reads (command_invokes_git(...) and is_read_only_bash(...)). It now refuses any command where command_names_git returns non-empty. That covers every git command, any program in a command position that cannot be read (an expansion, a glob, a brace list, quoting it cannot resolve), and any $(...), backtick or <(...) anywhere in the text. It also judges the raw command/cmd argument when no shell command was recovered. The ONE threat it refuses is git running programs named in repository config with no approver: "Every git command runs programs its repository config names (core.fsmonitor, core.hooksPath, commit and checkout hooks) that no text classifier sees, read or not … With no approver on a hook-based surface (a Meetings dispatch), the default below would run it unchecked, so it is refused instead."

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 (xargs, nice, env, watch), inside bash -c, after find -exec and rg --pre, and in $VAR/glob/$(...) program forms. windows rows cover the diff's Windows assumptions: the PATHEXT suffix set (git.exe), the backslash-keeping second reading (C:\tools\rg.exe, a quoted C:\Program Files\Git\bin\git.exe), cmd /c and pwsh -Command script walking, %VAR% in the program position, and findstr. No any rows: every row names an executable. Not covered by any row: the diff's case-insensitive lower-casing (macOS spelling like GIT status). The composite does not change on that axis, so no posix-vs-macOS leg can tell them apart.

UNADJUDICATED: Guard: _resolve_permission → policy == HOOK_BASED and hooks and on_tool_approval is None → _no_approver_shell_commands(event) (the recovered shell command, or else raw_tool_params["command"/"cmd"] when mcp_server_name is empty) → command_names_git → _steer_host_deny + reject_tool. This runs after the hook gate and outside SHELL_DENY_TIERS, so none of the rows above can flip there. These inputs would have been my candidates on that surface, and the code as written refuses them:

  • Runner followed by the word git (find . -name '*.md' | xargs grep -ln git, nice -n 10 grep -rn git src/, env LC_ALL=C grep -c git CHANGELOG.md): every word after a runner counts as a possible program. The tests list these in RUNNER_ARGUMENT_GIT_COMMANDS as "the accepted cost".
  • Command substitution anywhere (echo "build $(date +%Y%m%d)" > build-stamp.txt, pytest $(ls tests/test_*.py | head -5), and per the tests even a single-quoted literal echo '$(git log)' > out.txt).
  • Expansion or glob as the program ("$PYTHON" -m pytest -q, ./scripts/run-*.sh --help).
  • Every git command, including a plain git status, git log or git commit done by a Meetings-dispatched agent. Before this change, git writes kept the hook-based default (approval).
  • Raw command/cmd arguments of a non-MCP tool streamed as kind other that are not shell text: now judged as shell.

Narrowing to consider, argued but not confirmed:

  • Limit the runner-argument rule to the first non-option word after the runner, instead of treating every later word as a possible program.
  • Treat $(...) and backticks inside single quotes as text, not as unreadable.

The PR's stated escape is a grant in the hook's auto_approve_tools.

[SCOPE-REVIEWED] 3734286

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 23, 2026
@JLargent42

Copy link
Copy Markdown
Contributor Author
  • owner decision, for the GPT and Opus security lanes: shell-written spellings of git are an accepted residual

    On 7983dea (366e341 rebased onto main, no code change) the owner's decision (largjaco, 2026-11-02) still stands: the glob, brace list, extglob and ANSI-C $' refusal is removed from command_names_git. Earlier reviews of d2bcb0a, a636188, be11d78 and 053bee6 had asked for it. So /usr/bin/g?t commit, {g,}it commit, +(gi)t, @""(g|gi)t and $'\x67it' commit keep the surface default on a no-approver hook surface. That is the same as main, and the same as ${x}t. This is a human Goal amendment, recorded under Not a goal in the PR description and pinned by SHELL_WRITTEN_RESIDUAL_COMMANDS. It is not a defect for these lanes to re-raise. The PR still only refuses more than main: every literal git left after quote and backslash removal is refused, and nothing is newly approved.

@JLargent42

Copy link
Copy Markdown
Contributor Author
  • deferred: The DeepSeek command/cmd fallback duplicates GateFacts.raw_shell_commands

    A note on a PASS verdict, not a blocker, carried over from 366e341 and 5ca8e25 (this head is that commit rebased onto main, with no code change). The two sites read different input types: an ACP tool event here, gate facts in src/kiro_crew/hook_runtime/gate_tiers.py. Sharing one extractor means changing the gate's own API, which is outside this fix. Left as is for a follow-up.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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 example github or digit) 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/cmd on any non-MCP tool; keying it on the tool kind would narrow it.

AI-assisted, approved by bolichen97

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_bash already 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 == or in, 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.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 3734286
  • What rule changed: on a hook-based surface with no approver, a shell command the hook gate did not grant is refused when its program is git, read or not, or when its program cannot be read from the text; before, only a git read was refused there. command_names_git splits the command into words and operators with shlex (punctuation_chars), reads the program at each command position (and inside bash -c, cmd /c, eval, env -S, find -exec, rg --pre and after a runner), and refuses when its basename, lower-cased once, is in the fixed set {git, git.exe, git.com, git.bat, git.cmd}. No regex, casefold or substring test decides the name. A program it cannot read (a glob, brace list or extglob, an ANSI-C quote or expansion, a command or process substitution, unresolvable quoting, nesting past eight) refuses with its own named reason. This replaces the earlier head's case-blind substring test, per the review at 7983dea. command_invokes_git and is_read_only_bash are unchanged from main. This head is rebased onto current main (3ef2da3).
  • Before -> after (what was allowed/blocked, now): before, a non-read git command such as a commit reached the surface's default approve when the hook allowed it; now it refuses, as does GIT status (case-insensitive filesystems run git) and an unreadable program such as $EDITOR notes or /usr/bin/g?t commit. A command that only names git as an argument (grep digit, make docs VCS=git, cat .gitignore) keeps the default, except after a runner (xargs grep git), where any later word may be the program. Globs and brace lists outside the program position (rm *.tmp, echo {a,b}) keep the default.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): an ordinary command is refused on an unattended hook-based surface (a Meetings dispatch) when the operator expected it to run, for example a non-git command holding a command substitution; the refusal names the reason and the remedy, a hook grant. A git run hidden inside a program's own data (python -c) keeps the surface default, as on main. No attended surface, credential path or login is affected. Compared with main the check only refuses more, so it cannot newly approve anything.
  • Evidence checked (which sandbox result proves it): no sandbox rule changes. test_read_only_shell_git_exclusion.py drives command_names_git and the no-approver resolver; 343 of 343 pass on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): pytest -n 2 on test_read_only_shell_git_exclusion.py, test_security_gate_liveness.py, test_auto_approve.py, test_approval_threading.py, test_dashboard_approval.py, test_channel_approval_meta.py, test_facade_mirror_guards.py, test_facade_mirror.py, test_llm_helpers_facade.py and test_trust_reads.py: 771 passed; and the llm_helpers, gate, deny-notice, KAS, governance and cron suites: 462 passed, 0 failed, on this head. black and flake8 are clean on the changed Python files.
    • Backward compatible (old config / old data / old callers still work, how checked): no config or data format changes; hook grants still approve first, and an approver still decides git and unreadable commands, checked by the approver-present tests in test_read_only_shell_git_exclusion.py.
    • Existing tests (which suites passed on this head): test_read_only_shell_git_exclusion.py, test_trust_reads.py and test_security_gate_liveness.py (line budget 34,224, the true count: main plus 257), with the approval, facade and deny-notice suites listed above.
  • How to undo: revert the single commit; the no-approver branch returns to refusing git reads only.

@JLargent42

Copy link
Copy Markdown
Contributor Author

@bolichen97 thanks, done on 3734286 (rebased onto main 3ef2da3).

  • "git" in text.casefold() is gone. command_names_git now splits the command with shlex (the reader is_read_only_bash uses, with punctuation_chars so operators end words as bash ends them), takes the program at each command position, basenames it, and tests exact membership in {"git", "git.exe", "git.com", "git.bat", "git.cmd"}. It also reads the command line inside bash -c, cmd /c, eval, env -S, find -exec, rg --pre and after a runner. No regex or substring test decides the name.
  • GIT status: refused, and pinned. macOS and Windows filesystems are case-insensitive, so GIT runs git there. It is still exact set membership: the basename is lower-cased once, the one documented normalisation, and then tested with in. The text is never searched.
  • An unreadable program position refuses with its own reason, named in the refusal (git_unreadable_headless_reject): a glob, brace list or extglob, an ANSI-C quote or expansion, a command or process substitution, unresolvable quoting, or nesting past eight. This also closes the shell-written residual the earlier head accepted.
  • Pinned: grep digit README.md and make docs VCS=git keep the default; /usr/bin/git status and GIT status refuse; $EDITOR notes, /usr/bin/g?t commit and {g,}it commit refuse with their own reason; with an approver present each still reaches it.
  • One over-refusal remains on purpose: after a runner (xargs grep git) any later word may be the program, because a runner's option values sit before it. A hook grant lifts it.
  • Your earlier non-blocking notes: the refusal now names its reason. The spelling lists are now grouped by outcome (runs git, cannot be read, keeps the default). The command/cmd fallback still applies to any non-MCP tool: keying it on the tool kind would miss DeepSeek's bash, which arrives as kind other.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 89a099c
  • What rule changed: on a hook-based surface with no approver, a shell command the hook gate did not grant is refused when one of its programs is git, read or not, or when a program cannot be read; before, only a git read was refused there. The check is name_grant.no_approver_git_refusal. It takes the programs from name_grant.program_names (the walk the name grants and the heartbeat approver's git exclusion use) plus the value of find -exec and rg --pre, and refuses when a basename, lower-cased once, is in the fixed set {git, git.exe, git.com, git.bat, git.cmd}. No regex, casefold or substring test decides the name. A program it cannot read refuses with its own reason: a substitution anywhere (_UNENUMERABLE), grammar the walk does not model, a name the shell expands, or a dispatcher from _DISPATCHERS plus flock and chronic, whose flag grammar it does not model. security/readonly_bash.py is now unchanged from main, so command_invokes_git and is_read_only_bash are untouched. This head is rebased onto main 3ef2da3.
  • Before -> after (what was allowed/blocked, now): before, a non-read git command such as a commit reached the surface's default approve when the hook allowed it; now it refuses, as does GIT status (case-insensitive filesystems run git). A dispatcher (sh -c, env, xargs, timeout), a keyword (if, while), an expanded name ($EDITOR, /usr/bin/g?t) and a substitution also refuse, with their own reason. A command that only names git as an argument (grep digit, make docs VCS=git, cat .gitignore) keeps the default, as do rm *.tmp and echo {a,b}.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): an ordinary command is refused on an unattended hook-based surface (a Meetings dispatch) when the operator expected it to run, for example timeout 60 pytest or an if block; the refusal names the reason and the remedy, a hook grant. A git run hidden inside a program's own data (python -c) keeps the surface default, as on main. No attended surface, credential path or login is affected. Compared with main the check only refuses more, so it cannot newly approve anything.
  • Evidence checked (which sandbox result proves it): no sandbox rule changes. test_read_only_shell_git_exclusion.py drives no_approver_git_refusal and the no-approver resolver; 336 of 336 pass on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): pytest -n 2 on test_name_grant.py, test_name_grant_facade.py, test_name_grant_surfaces.py, test_name_grant_windows.py, test_read_only_shell_git_exclusion.py, test_security_gate_liveness.py, test_auto_approve.py, test_approval_threading.py, test_dashboard_approval.py, test_channel_approval_meta.py, test_facade_mirror_guards.py, test_facade_mirror.py, test_llm_helpers_facade.py and test_trust_reads.py: 1207 passed, 6 skipped; the llm_helpers, gate, deny-notice, KAS, governance and cron suites: 462 passed; test_security_posture.py, test_chat_runner_coverage_approval.py, test_host_isolation_floor_restores.py and test_platform_context.py: 176 passed; 0 failed, on this head. black and flake8 are clean on the changed Python files.
    • Backward compatible (old config / old data / old callers still work, how checked): no config or data format changes; program_names and every existing name_grant function are unchanged, checked by the four name_grant suites; hook grants still approve first, and an approver still decides git and unreadable commands, checked by the approver-present tests in test_read_only_shell_git_exclusion.py.
    • Existing tests (which suites passed on this head): the name_grant suites, test_read_only_shell_git_exclusion.py, test_trust_reads.py and test_security_gate_liveness.py (package line budget unchanged from main), with the approval, facade and deny-notice suites listed above.
  • How to undo: revert the single commit; the no-approver branch returns to refusing git reads only.

@JLargent42

Copy link
Copy Markdown
Contributor Author

@bolichen97 an update on my earlier reply: the head is now 89a099c, and the approach changed after the review lanes ran on 3734286.

  • 3734286 had its own shlex walker in readonly_bash.py. GPT found four ways past its runner and shell argument reading (env -u bash git ..., bash -c -e '...', env -S 'bash -c' '...', and a substitution in a redirection operand). First Principles called it a second command-position walker. Both were right.
  • This head drops that walker and leaves readonly_bash.py unchanged from main. The check is name_grant.no_approver_git_refusal (about 70 lines). It takes the programs from name_grant.program_names, the word reader the name grants and the heartbeat approver's git exclusion already use, plus the value of find -exec and rg --pre. Each basename is tested with exact membership in {"git", "git.exe", "git.com", "git.bat", "git.cmd"}. No regex, casefold or substring test.
  • GIT status is refused and pinned. macOS and Windows filesystems are case-insensitive, so GIT runs git there. The basename is lower-cased once, the one documented normalisation, and then tested with in. The text is never searched.
  • Unreadable programs refuse with their own named reason (git_unreadable_headless_reject): a substitution anywhere, grammar program_names does not model (a keyword, a function), a name the shell expands ($EDITOR, /usr/bin/g?t, {g,}it), or a dispatcher from name_grant's _DISPATCHERS (sh -c, env, xargs, timeout). Dispatchers refuse whatever follows, the same rule the name grants apply, instead of modelling each one's flags.
  • Pinned: grep digit README.md and make docs VCS=git keep the default; /usr/bin/git status and GIT status refuse as git; $EDITOR notes, /usr/bin/g?t commit and bash -c -e 'git commit' refuse with their own reason; with an approver present each still reaches it.
  • The cost is on the no-approver surface only: an ungranted dispatcher or keyword command (timeout 60 pytest, an if block) is refused there, and a hook grant lifts it.

@JLargent42

Copy link
Copy Markdown
Contributor Author
  • fixed: Redirection targets discard executable substitutions

    Fixed on 89a099c. The walker that skipped redirection operands is gone. name_grant.no_approver_git_refusal first refuses any $(, backtick, <( or >( anywhere in the command line (name_grant._UNENUMERABLE), redirection operands included. cat <<< "$(git status --porcelain)" and cat < `git rev-parse --git-path x` are pinned in UNREADABLE_COMMANDS and refused with their own reason.

@JLargent42

Copy link
Copy Markdown
Contributor Author
  • fixed: A hypothetical runner program prematurely ends inspection

    Fixed on 89a099c. Runners are no longer unwrapped. A dispatcher from name_grant._DISPATCHERS (plus flock, chronic) refuses with its own reason whatever follows, so env -u bash git commit ..., env --unset sh git ... and xargs -I sh git commit ... refuse at env / xargs. Every find -exec and rg --pre value is read, not only the first, so find . -exec sh -c true {} + -exec git status {} + and rg --pre sh --pre git pattern README.md refuse. All are pinned in DISPATCHER_COMMANDS.

@JLargent42

Copy link
Copy Markdown
Contributor Author
  • fixed: Shell options after -c hide the executed script

    Fixed on 89a099c. The -c script reader is gone. A shell (sh, bash, zsh, cmd, pwsh ...) is a dispatcher in name_grant._DISPATCHERS and refuses with its own reason, whatever options follow, so bash -c -e 'git commit ...', bash -c -x ..., bash -c -o errexit ... and sh -c -e ... all refuse. bash -c -e 'git commit -m wip' is pinned in DISPATCHER_COMMANDS.

@JLargent42

Copy link
Copy Markdown
Contributor Author
  • fixed: env split-string inspection omits trailing argv

    Fixed on 89a099c. The env -S reader is gone. env is a dispatcher in name_grant._DISPATCHERS and refuses with its own reason, so env -S 'bash -c' 'git commit ...', env --split-string='sh -c' '...' and env -S 'sh -c' 'git status' refuse at env. env -S 'bash -c' 'git commit -m wip' is pinned in DISPATCHER_COMMANDS.

@JLargent42

Copy link
Copy Markdown
Contributor Author
  • fixed: Framing contradicted by the diff: the shipped walker is the approach the Goal excludes

    Fixed on 89a099c. The verdict read the description of an earlier head. The text check it describes was replaced at a reviewer's request (@bolichen97, CHANGES_REQUESTED on 7983dea: exact name matching, unreadable programs refused with their own reason, no pattern matching over text). The 257-line walker is removed and security/readonly_bash.py is unchanged from main. The new check, name_grant.no_approver_git_refusal (about 70 lines), reuses name_grant.program_names and _DISPATCHERS and adds no command-position walker. The description now says this and records the history of the owner's earlier residual decision, which this head closes rather than accepts.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@JLargent42

Copy link
Copy Markdown
Contributor Author

CI note for 65d7b0b: this push only pins the POSIX shell model on the FOO=1 git merge topic test row, which failed on the Windows runners because the Windows model reads FOO=1 as a command. No code changed.

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 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: c1672eb
  • What rule changed: on a hook-based surface with no approver, a shell command the hook gate did not grant is refused when one of its programs is git, read or not, or when a program cannot be read; before, only a git read was refused there. The check is name_grant.no_approver_git_refusal. It takes the programs from name_grant.program_names plus the value of find -exec and rg --pre, and refuses when a basename, lower-cased once, is in the fixed set {git, git.exe, git.com, git.bat, git.cmd}. No regex, casefold or substring test decides the name. A program it cannot read refuses with its own reason: a substitution, grammar the walk does not model, a name the shell expands, or a dispatcher or wrapper from _DISPATCHERS plus flock and chronic. New on this head, against 65d7b0b: a heredoc body is input and its lines are not walked (an unquoted body is still searched for substitutions); builtins that run no named program (export, declare, typeset, readonly, local, set, printf, read, mapfile, readarray, getopts, let, source, .) are no longer dispatchers there, while hash, alias, unalias and shopt still are; a redirect glued to an option's program (-exec git>/dev/null) is split off and the program is read as git. This scope is the owner's option A (largjaco): refuse any program that cannot be read exactly, dispatchers and wrappers included. security/readonly_bash.py is unchanged from main. This head is on main 3ef2da3.
  • Before -> after (what was allowed/blocked, now): before, a non-read git command such as a commit reached the surface's default approve when the hook allowed it; now it refuses, as does GIT status. A dispatcher or wrapper (sh -c, bash script, env, xargs, timeout), a keyword (if, for), an expanded name and a substitution also refuse, with their own reason. A command that only names git as an argument (grep digit, make docs VCS=git, cat .gitignore) keeps the default, as do export X=1, printf x > f and a heredoc whose body mentions git.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): an ordinary command is refused on an unattended hook-based surface (a Meetings dispatch), for example timeout 60 pytest, ls | xargs wc or a for loop. Measured on this head, a hook grant in auto_approve_tools does not lift that refusal for a dispatcher or a substitution, because the name-grant check (name_grant.refusal_for_event) withholds the grant for the same classes and the surface has no approver, so those commands cannot run there at all; this is open on the review below. A git run hidden inside a program's own data (python -c) keeps the surface default, as on main. No attended surface, credential path or login is affected. Compared with main the check only refuses more, so it cannot newly approve anything.
  • Evidence checked (which sandbox result proves it): no sandbox rule changes. test_read_only_shell_git_exclusion.py drives no_approver_git_refusal and the no-approver resolver; 372 of 372 pass on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): pytest -n 2 on test_read_only_shell_git_exclusion.py, test_name_grant.py, test_name_grant_facade.py, test_name_grant_surfaces.py, test_name_grant_windows.py, test_trust_reads.py, test_security_gate_liveness.py and test_auto_approve.py: 959 passed, 6 skipped, 0 failed, on this head. black and flake8 are clean on the changed Python files.
    • Backward compatible (old config / old data / old callers still work, how checked): no config or data format changes; program_names and every existing name_grant function are unchanged, checked by the four name_grant suites; an approver still decides git and unreadable commands, checked by the approver-present tests in test_read_only_shell_git_exclusion.py.
    • Existing tests (which suites passed on this head): the eight files above.
  • How to undo: revert the single commit; the no-approver branch returns to refusing git reads only.

@JLargent42

Copy link
Copy Markdown
Contributor Author
  • owner decision, for the GPT and Opus security lanes: unreadable programs refuse on a no-approver surface; the remedy text is confirmed open

    The scope is the owner's decision (largjaco, option A): on a hook-based surface with no approver, any program that cannot be read exactly refuses, dispatchers and wrappers included. The PR description and security: should a no-approver hook surface refuse every git command? #21559 carry the amended Goal. The stated cost is that such a surface needs hook grants for wrappers like timeout 60 pytest. c1672eb narrows the class: builtins that run no named program (export, set, printf, source ...) no longer count as dispatchers, and a heredoc body is no longer walked as commands, so export X=1, printf 'x\n' > f and a heredoc with an apostrophe now pass this check.
    Opus BLOCKING (tool_approval.py:826, false remedy): the second half of that finding still holds on c1672eb. Measured with name_grant.refusal_for_command_off_loop, the name-grant check withholds a hook grant for timeout 60 pytest, bash run_tests.sh, ls | xargs wc, echo $(date), a for loop, and also export X=1. With no approver that ends in name_grant_headless_reject, so the refusal's "grant it in the hook's auto_approve_tools" remedy does not work for these commands. This needs a fix or an owner call before merge: drop the false remedy from the message and security.md, or let a hook grant lift these classes on this surface.

  • accepted, fails closed: --pre= / -exec operands of other programs read as a program (GPT F1, downgraded)

    Not changed. grep -e --pre=git README.md is refused as running git. This is a visible false refusal that fails closed, which matches option A (refuse what cannot be read exactly). Scoping the options to their owning find / rg would mean per-program flag parsing, which bolichen97 asked this PR to avoid.

  • deferred: second git-basename check at slack/gateway_runtime/tool_policy.py:235

    A note on a PASS verdict, not a blocker. That line is the heartbeat approver's own git exclusion. Pointing it at name_grant._git_program_refusal would change what the heartbeat path refuses (git.exe, git.cmd and the rest), which is outside this fix. Left for a follow-up.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: c6010e8
  • What rule changed: on a hook-based surface with no approver, a shell command the hook gate did not grant is refused when one of its programs is git, read or not, or when a program cannot be read; before, only a git read was refused there. The check is name_grant.no_approver_git_refusal. It takes the programs from name_grant.program_names plus the value of find -exec and rg --pre, and refuses when a basename, lower-cased once, is in the fixed set {git, git.exe, git.com, git.bat, git.cmd}. No regex, casefold or substring test decides the name. A program it cannot read refuses with its own reason: a substitution, grammar the walk does not model, a name the shell expands, or a dispatcher or wrapper from _DISPATCHERS plus flock and chronic. A heredoc body is input and its lines are not walked (an unquoted body is still searched for substitutions); builtins that run no named program (export, set, printf, source ...) are not dispatchers there, while hash, alias, unalias and shopt still are; a redirect glued to an option's program (-exec git>/dev/null) is split off. New on this head, against c1672eb: a heredoc opener is accepted only when it has one reading (<<WORD, <<-WORD or << WORD, the word letters, digits and _, bare or in one pair of quotes, ended by a blank, an operator or the line end) and the rest of its line holds no quote, backslash or #. Any other << refuses as unmodelled, so a commented, escaped or quoted << or a concatenated / ANSI-C delimiter can no longer drop the lines after it from the walk. This scope is the owner's option A (largjaco). security/readonly_bash.py is unchanged from main. This head is on main 3ef2da3.
  • Before -> after (what was allowed/blocked, now): before, a non-read git command such as a commit reached the surface's default approve when the hook allowed it; now it refuses, as does GIT status. A dispatcher or wrapper (sh -c, bash script, env, xargs, timeout), a keyword (if, for), an expanded name, a substitution and a heredoc opener it cannot read exactly (echo hi # <<EOF, echo a\<<EOF, <<'E'OF, <<$'EOF') also refuse, with their own reason. A command that only names git as an argument (grep digit, make docs VCS=git, cat .gitignore) keeps the default, as do export X=1, printf x > f and cat > notes.md <<'EOF' with a body that mentions git.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): an ordinary command is refused on an unattended hook-based surface (a Meetings dispatch), for example timeout 60 pytest, ls | xargs wc, a for loop or a heredoc whose opener line also has a quote. Measured on c1672eb, a hook grant in auto_approve_tools does not lift that refusal for a dispatcher or a substitution, because the name-grant check withholds the grant for the same classes and the surface has no approver; this is open on the review. A git run hidden inside a program's own data (python -c) keeps the surface default, as on main. No attended surface, credential path or login is affected. Compared with main the check only refuses more, so it cannot newly approve anything.
  • Evidence checked (which sandbox result proves it): no sandbox rule changes. test_read_only_shell_git_exclusion.py drives no_approver_git_refusal and the no-approver resolver, including the eight heredoc rows from the review; 394 of 394 pass on this head. On c1672eb five of those rows returned "" (keep the default).
  • No regression:
    • Tools still work (which tools/commands were run, result): pytest -n 2 on test_read_only_shell_git_exclusion.py, test_name_grant.py, test_name_grant_facade.py, test_name_grant_surfaces.py, test_name_grant_windows.py, test_trust_reads.py, test_security_gate_liveness.py and test_auto_approve.py: 981 passed, 6 skipped, 0 failed, on this head. black and flake8 are clean on the changed Python files; scripts/docs-lint.sh passes.
    • Backward compatible (old config / old data / old callers still work, how checked): no config or data format changes; program_names and every existing name_grant function are unchanged, checked by the four name_grant suites; an approver still decides git and unreadable commands, checked by the approver-present tests in test_read_only_shell_git_exclusion.py.
    • Existing tests (which suites passed on this head): the eight files above.
  • How to undo: revert the single commit; the no-approver branch returns to refusing git reads only.

@JLargent42

Copy link
Copy Markdown
Contributor Author
  • fixed, for the GPT and Opus security lanes: heredoc stripping hid git after a << bash does not open

    Fixed on c6010e8. name_grant._heredoc_openers replaces the token scan. It accepts an opener only when it has one reading: <<WORD, <<-WORD or << WORD, the word letters, digits and _, bare or in one pair of quotes, ended by a blank, an operator or the line end. The rest of the line must hold no quote, backslash or #. Any other << raises _Unmodelled, so no_approver_git_refusal refuses rather than dropping the next lines. That covers both review triggers (echo hi # <<EOF, echo a\<<EOF) and GPT's sites (<<'E'OF, <<$'EOF'), plus <<\EOF and a quoted '<<EOF'. Each one is a row in UNMODELLED_COMMANDS, and both the check and the resolver are asserted to refuse it. On c1672eb five of those rows kept the default. <<< is still read as a here-string. The recovered-shell and raw command / cmd paths share this function.

  • still open from 65d7b0b (Opus): the "grant it in auto_approve_tools" remedy

    Unchanged on this head. The scope is the owner's option A, and the Goal is amended in the PR description and security: should a no-approver hook surface refuse every git command? #21559. But a hook grant does not lift the refusal for dispatchers or substitutions on this surface (measured: name_grant.refusal_for_command_off_loop withholds it), so the remedy text is wrong for those. This is waiting on the owner.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 09a1a76
  • What rule changed: on a hook-based surface with no approver, a shell command the hook gate did not grant is refused when one of its programs is git, read or not, or when a program cannot be read; before, only a git read was refused there. The check is name_grant.no_approver_git_refusal. It takes the programs from name_grant.program_names plus the value of find -exec and rg --pre, and refuses when a basename, lower-cased once, is in the fixed set {git, git.exe, git.com, git.bat, git.cmd}. No regex, casefold or substring test decides the name. A program it cannot read refuses with its own reason: a substitution, grammar the walk does not model, a name the shell expands, or a dispatcher or wrapper from _DISPATCHERS plus flock and chronic, now matched lower-cased like git (/bin/BASH). Builtins that run no named program (export, set, printf, source ...) are exempt by exact name; a redirect glued to an option's program is split off. New on this head, against c6010e8: the heredoc-body reader (_heredoc_openers, _without_heredoc_bodies) is removed, so every line is walked, a heredoc body's included; and the refusal for an unreadable command no longer tells the operator to add a hook grant, since the name-grant check refuses the same classes. Scope is the owner's option A (largjaco). security/readonly_bash.py is unchanged from main. This head is on main 3ef2da3.
  • Before -> after (what was allowed/blocked, now): before, a non-read git command such as a commit reached the surface's default approve when the hook allowed it; now it refuses, as does GIT status. A dispatcher or wrapper in any case (sh -c, /bin/BASH -c, env, xargs, timeout), a keyword, an expanded name, a substitution, and a heredoc body line that reads as git, a keyword or a substitution also refuse, with their own reason. A command that only names git as an argument (grep digit, make docs VCS=git, cat .gitignore) keeps the default, as do export X=1, printf x > f and a heredoc of plain words.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): an ordinary command is refused on an unattended hook-based surface (a Meetings dispatch), for example timeout 60 pytest, ls | xargs wc, a for loop, or cat > notes.md <<'EOF' whose body has a line starting git or if. A hook grant does not lift the unreadable refusal there, and the refusal now says so. A git run hidden inside a program's own data (python -c) keeps the surface default, as on main. No attended surface, credential path or login is affected. Compared with main the check only refuses more, so it cannot newly approve anything.
  • Evidence checked (which sandbox result proves it): no sandbox rule changes. test_read_only_shell_git_exclusion.py drives no_approver_git_refusal and the no-approver resolver, including every bypass row from the c1672eb and c6010e8 reviews (commented, escaped, quoted and ${...} / $[...] <<, concatenated delimiters, continued terminators, upper-case dispatchers), each of which kept the default on c1672eb or c6010e8; 406 of 406 pass on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): pytest -n 2 on test_read_only_shell_git_exclusion.py, test_name_grant.py, test_name_grant_facade.py, test_name_grant_surfaces.py, test_name_grant_windows.py, test_trust_reads.py, test_security_gate_liveness.py, test_auto_approve.py, test_llm_helpers_facade.py and test_approval_threading.py: 1033 passed, 6 skipped, 0 failed, on this head. black and flake8 are clean on the changed Python files; scripts/docs-lint.sh and pr-description-check.sh pass.
    • Backward compatible (old config / old data / old callers still work, how checked): no config or data format changes; program_names, _program_key and every existing name_grant function are unchanged (the lower-casing is local to _git_program_refusal), checked by the four name_grant suites; hook grants still approve first, and an approver still decides git and unreadable commands, checked by the approver-present tests in test_read_only_shell_git_exclusion.py.
    • Existing tests (which suites passed on this head): the ten files above.
  • How to undo: revert the single commit; the no-approver branch returns to refusing git reads only.

@JLargent42

Copy link
Copy Markdown
Contributor Author
  • fixed, for the GPT and Opus security lanes: heredoc stripping hid git (${x:-<<EOF }, $[1<<2 ], continued terminators)

    Fixed on 09a1a76 by removing the heredoc reader, as Opus's second option proposed and as First Principles item 4 asked. _heredoc_openers and _without_heredoc_bodies are gone, and every line is walked, a heredoc body's included. This check only refuses, so leaving a body out could only hide a command after a misread opener or terminator. Two heads in a row were bypassed that way, each time through a different edge. Every review trigger is now a pinned row: echo hi # <<EOF, echo a\<<EOF, <<'E'OF, ${x:-<<EOF } and $[1<<2 ] refuse as git, and a continued terminator refuses as unmodelled. The cost is that a heredoc body line that reads as git, a keyword or a substitution refuses.

  • fixed: mixed-case dispatchers (/bin/BASH -c, /bin/SH, /usr/bin/ENV, XARGS)

    Fixed on 09a1a76. _git_program_refusal lower-cases the key for the dispatcher lookup, as it already did for git, without changing the shared _program_key. Inert builtins still match only their exact name (EXPORT is not the export builtin). All four are pinned in DISPATCHER_COMMANDS.

  • fixed: the advertised recovery cannot authorize shell dispatchers (upheld F3, and Opus on 65d7b0b)

    Fixed on 09a1a76 as the adjudication proposed. On the existing _unread flag, the refusal for an unreadable command now says that a hook grant cannot lift it, because the name check refuses the same command, and that the program should be named directly or the command run where an approver exists. The git refusal keeps "grant it in auto_approve_tools", which works. security.md, the resolver comment, the two expected strings in the tests and the PR description now say the same. The wider cost this exposes, that wrappers such as timeout 60 pytest cannot run on a surface with no approver at all, is recorded in the PR description as open with the owner.

  • fixed: item 4, the heredoc reader went beyond the Goal

    Removed on 09a1a76, as proposed. A heredoc is walked like any other text.

  • deferred: item 5, the kept git_read_headless_reject branch, and item 6, the second git-basename check at slack/gateway_runtime/tool_policy.py:235

    Notes on a PASS verdict. Both are subtractions outside the change that closes the finding. Item 6 would change what the heartbeat path refuses. Left for a follow-up.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 4aa381c
  • What rule changed: on a hook-based surface with no approver, a shell command the hook gate did not grant is refused when one of its programs is git, read or not, or when a program cannot be read; before, only a git read was refused there. The check is name_grant.no_approver_git_refusal. It takes the programs from name_grant.program_names plus the value of find -exec / -execdir / -ok / -okdir and rg --pre, and refuses when a basename, lower-cased once, is in the fixed set {git, git.exe, git.com, git.bat, git.cmd}. No regex, casefold or substring test decides the name. A program it cannot read refuses with its own reason: a substitution, grammar the walk does not model, a name the shell expands, a dispatcher or wrapper from _DISPATCHERS plus flock and chronic (matched lower-cased, so /bin/BASH), or, new on this head against 09a1a76, a program-valued option whose next word is a redirection (empty, all digits, or starting with one of <>&|;()), as in -exec </dev/null git or -exec 2>&1 git. Builtins that run no named program (export, set, printf, source ...) are exempt by exact name. Every line is walked, a heredoc body's included. A refusal for an unreadable command says a hook grant cannot lift it. Scope is the owner's option A (largjaco). security/readonly_bash.py is unchanged from main. This head is on main 3ef2da3.
  • Before -> after (what was allowed/blocked, now): before, a non-read git command such as a commit reached the surface's default approve when the hook allowed it; now it refuses, as does GIT status. A dispatcher or wrapper in any case, a keyword, an expanded name, a substitution, a heredoc body line that reads as git, a keyword or a substitution, and a redirection between -exec / --pre and its program also refuse, with their own reason. A command that only names git as an argument (grep digit, make docs VCS=git, cat .gitignore) keeps the default, as do export X=1, printf x > f, find . -name x -exec touch {} + and a heredoc of plain words.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): an ordinary command is refused on an unattended hook-based surface (a Meetings dispatch), for example timeout 60 pytest, ls | xargs wc, a for loop, find . -exec 2>/dev/null touch {} +, or a heredoc whose body has a line starting git or if. A hook grant does not lift the unreadable refusal there, and the refusal says so. A git run hidden inside a program's own data (python -c) keeps the surface default, as on main. No attended surface, credential path or login is affected. Compared with main the check only refuses more, so it cannot newly approve anything.
  • Evidence checked (which sandbox result proves it): no sandbox rule changes. test_read_only_shell_git_exclusion.py drives no_approver_git_refusal and the no-approver resolver, including the eight OPTION_REDIRECT_COMMANDS rows from the 09a1a76 review (-exec, -execdir, -ok, -okdir, --pre, --pre=; <, >, 2>&1, 2>, glued -exec>), which kept the default on 09a1a76; 422 of 422 pass on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): pytest -n 2 on test_read_only_shell_git_exclusion.py, test_name_grant.py, test_name_grant_facade.py, test_name_grant_surfaces.py, test_name_grant_windows.py, test_trust_reads.py, test_security_gate_liveness.py, test_auto_approve.py, test_llm_helpers_facade.py and test_approval_threading.py: 1049 passed, 6 skipped, 0 failed, on this head. black and flake8 are clean on the changed Python files.
    • Backward compatible (old config / old data / old callers still work, how checked): no config or data format changes; program_names, _program_key and every existing name_grant function are unchanged, checked by the four name_grant suites; hook grants still approve first, and an approver still decides git and unreadable commands, checked by the approver-present tests in test_read_only_shell_git_exclusion.py.
    • Existing tests (which suites passed on this head): the ten files above.
  • How to undo: revert the single commit; the no-approver branch returns to refusing git reads only.

@JLargent42

Copy link
Copy Markdown
Contributor Author
  • fixed: interposed redirections hid git in program-valued options

    Fixed on 4aa381c as the finding proposed. When the word after -exec / -execdir / -ok / -okdir / --pre, or the value of --pre=, is empty, all digits, or starts with one of <>&|;(), no_approver_git_refusal refuses it as unreadable ("the program after '-exec' cannot be read past a redirection") and does not read that word as the program. Every site named in the finding is a pinned row in OPTION_REDIRECT_COMMANDS, and the check and the resolver are both asserted to refuse it: -exec </dev/null git, -exec 2>&1 git, glued -exec>/dev/null git, -execdir >, -ok <, -okdir 2>, --pre < and --pre=<. On 09a1a76 each of these kept the default.

  • CI note: the other 09a1a76 lanes did not review

    Opus, Design, First Principles, UX, Sensitive Change Review, Dependency License and Publish readiness failed at 03:09-03:12Z with "API rate limit exceeded for installation", the repo-wide GitHub App quota (checked in the Opus, Design and SCR job logs). Those are not verdicts. This push starts fresh runs of every lane.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Closing per the maintainer security sign-off (not adopted: we do not raise security strictness). Thanks @bolichen97 for the review.

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.

security: should a no-approver hook surface refuse every git command?

2 participants