Skip to content

fix(security): keep self-host detection when the ssh verb is a glob - #34056

Merged
buluoray merged 1 commit into
mainfrom
crew/slack/ssh-self-glob-verb
Nov 17, 2026
Merged

buluoray merged 1 commit into
mainfrom
crew/slack/ssh-self-glob-verb

Conversation

@buluoray

@buluoray buluoray commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An agent can no longer reach this machine over ssh, outside the sandbox, by naming the ssh program through a glob such as s?h.

The ssh-to-self floor (sandbox-escape-ssh-self) stopped reading a glob destination as this host whenever the verb itself was a bare glob. The GPT review lane found this on #33675 (comment 6732935991, head 79cad72), and the Opus lane upheld it:

With localhost key auth, an unattended shell runs s?h -F /dev/null local* id in a directory containing files named ssh and localhost; is_denied -> _is_ssh_to_self disables destination-glob detection; base denied it, HEAD allows it; shell expansion runs SSH to self outside the governance mounts.

An agent can create both files itself, so this needs no help from the user.

Why it matters

The ssh-to-self floor is what keeps an agent from re-entering the host outside its sandbox mounts. With this hole, any agent turn that can write two files in its working directory can run a command on this machine with none of the governance mounts applied. The bug is on main and on release/0.12.0 (the pick f24c5dc from #34021 carries it), so 0.12.x users get it.

Not a goal

  • Keeping every star-led line allowed. A word made only of * that bash runs as the program can name ssh (touch ssh && * lvh.me id), so it is refused like s*; a five-field cron schedule that starts with a digit (0 * * * *) keeps passing, and one that starts with * goes to approval.
  • Closing the escape for interpreter or script-file indirection; that is the OS network fence in Sandbox network fence: block loopback sshd from inside the sandbox (netns or connect-filter on self:22) #9806.
  • The release backport itself; it is a separate pick into release/0.12.0 once this lands.

What changed (motivation → approach → change)

Root cause. #33299 added glob_verb in src/kiro_crew/security/argv_floor_ssh.py (_is_ssh_to_self) so cron schedules quoted in MCP arguments stop reading as ssh localhost. It set glob_verb for any bare glob verb and passed match_globs=not glob_verb to both operand checks. So s?h local* turned the self-host check off. But a glob is only an ssh invocation when the shell runs it; a glob that sits in another program's operands is a file name.

Fix: read the glob verb by where bash runs it. argv_rules._executed_program_indices marks the word bash runs in each command: the program, or the program a command wrapper runs (env, sudo, time, nice, timeout, nohup, command, xargs, through the existing _program_index, split out of _program_args with no change in behaviour). glob_verb now also needs the glob to be outside those positions, so a glob verb that bash runs keeps glob host matching, and every other glob keeps main's reading. Three smaller parts make the run position visible: the verb gate splits words at ;, |, &, parentheses and backticks with one plain character walk (_gate_words), so a glob verb in a subshell, a command substitution or after a glued ; is seen; an assignment that opens a $(, a backtick or an array literal (files=$(ls s* l*), n=`ls s* *.*` , files=( s* *.* )) hands the program position to the substitution's own program, or to none; and a case arm's pattern list (s* | r* )) is never a run position.

Command main this PR
s?h -F /dev/null local* id, env/sudo/time/nice/timeout/xargs s?h local*, s[s]h local* id allowed refused
(s?h local* id), echo $(s?h local* id), x=$(s?h local* id), cd /tmp;s?h local* (because of the /; cd tmp;s?h local* id is still allowed, #37438) allowed refused
tar … s* *.*, find s* l*, mypy src/*, pytest test/*, files=$(ls s* l*), watch -n 5 ls -la logs/* same answer same answer
0 * * * * / * * * * * cron lines, * lvh.me id, s* example.com id depends on hash seed the same answer as main under each seed

Nothing else in the floor changes: no program list, no runner list, no heredoc or array reader, and multi-program globs keep main's (hash-seed-dependent) reading. An earlier, wider version of this PR is kept at 23a3ff4663d676cbbe8ef520509c8e47470b8c52 (branch tip before this change, recoverable with git fetch origin 23a3ff4663d676cbbe8ef520509c8e47470b8c52).

Backwards compatibility

Breaking: src/kiro_crew/security/argv_rules.py:_executed_program_indices -- chat, cron -- besides the fix itself (s?h local* and its wrapper, subshell and substitution forms, now refused), a few rare commands that main allows are refused, because the floor reads their glob the same way as an attack it must refuse. Each fails closed (a loud refusal that goes to an approval, never an allowed ssh to this host) and is recoverable by naming the files or writing the line another way: x=`s* l*` ; command -v s?h local*; a heredoc body line that starts with a glob pair (cat <<'EOF' with r* l*); a trailing comment that holds a spaced ; before a glob pair (ls # x ; s* l*); a ^ line join before a glob line; and a ; or | glued to ls s* l*. All of them, with the attack each is read the same as, are tracked in #37438. A wrapper option inside a nested reading is still read lower-cased, so echo "$(sudo -H ls s* l*)" and the same sudo -H line inside bash -c '…' or a function body are refused; that is tracked in #37543. Gaps that main shares stay open and are tracked in #37009: a * or multi-program glob that a runner starts (strace * id, strace -k s?h …), multi-program globs (s*, *s*) whose reading depends on the hash seed, a glob copied by cp/mv/ln/install and then run, and a quoted > in a one-program -o proxycommand= value.
Reader: src/kiro_crew/security/argv_floor_ssh.py:_is_ssh_to_self -- cron -- an unattended MCP call quoting a schedule keeps main's answer: test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_an_unattended_mcp_call_quoting_a_cron_schedule_is_approved
Reader: src/kiro_crew/security/argv_floor_ssh.py:_is_ssh_to_self -- chat -- a glob in a program's operands still passes: test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_a_glob_host_after_a_glob_verb_is_not_this_host
Reader: src/kiro_crew/security/argv_rules.py:_program_args -- chat -- unchanged: now calls the extracted _program_index: test_argv_rules.py

Tests

test/test_denied_commands_security_ssh_self.py:

  • test_a_run_glob_verb_keeps_its_glob_host (DENY, new): s?h -F /dev/null local* id, s?h local*, s?h local* id, s[s]h local* id, env/sudo/time/xargs s?h local*, echo $(s?h local* id), x=$(s?h local* id), x=$(true) s?h local* id, (s?h local* id), cd /tmp;s?h local* (refused because of the /; cd tmp;s?h local* id is allowed here and on main, ssh-to-self floor: read sudo -e, comments, heredocs and glued separators the way bash runs them #37438), echo case in x; s?h local* id, echo test case in prod; s?h local* id, case x in a) :;; esac; s?h local* id, case x in a) true; s?h local* id;; esac, echo "$(s?h localhost id)", echo "$(s?h local* id)", x="$(s?h local* id)" (a glob verb right after a quoted $(: the gate now also cuts words at the floor's quoted-separator markers). 13 of its rows were red on main. A case opens a case statement only in command position, and the first word of each arm body is read as that arm's program: case x in x) s?h -F /dev/null local* id;; esac, case x in x) env s?h local* id;; esac, case x in (x) s?h local* id ;; esac and case x in a) :;; x) s?h local* id;; esac are deny rows, and case "$f" in docs) ls s* *.* ;; esac is an allow row.
  • test_a_glob_host_after_a_glob_verb_is_not_this_host (ALLOW): s?h local* moved out of it; operand globs after other programs and the four $( assignments (files=$(ls s* l*), hashes=$(sha256sum s* *.*), n=$(ls s* *.* | wc -l), count=$(ls r* *.* 2>/dev/null | wc -l)), red before the assignment fix; echo "$(ls s* *.*)" is a new allow row. The glued-; guard row is git add sc?; curl -s localhost:3000/healthz, which goes red on every hash seed with the guard removed.
  • Wrapper options are read in the case they were written. sudo -H ls -l s* *.*, sudo -H du -sh s* l*, sudo -E ls s* *.*, sudo -e s* and cd /etc/ssh && sudo -e s* *.* are allow rows (sudo -e edits files and runs no program). env -C . s?h local*, sudo -D /tmp s?h local*, xargs -P 4 s?h local*, sudo -H s?h local* id and sudo -E s?h local* id are deny rows. test_an_upper_case_program_or_verb_is_still_read keeps upper-case program and verb names refused. The backtick assignment, array literal and |-split case arm rows are allow rows, red before their fix.
  • test/test_denied_commands_security_cost.py::TestSshGateBracketWordsAreLinear (new): runs _gate_words on long runs of [ and asserts, with no timing, that it visits each character at most twice and that its words never add up to more than the input (red on a re-appending variant); a second test keeps s[s)]h, s[sx]h, [rs]s* and s[s]h one word each. A slower fnmatch path on the same input is on main too and is tracked in ssh-to-self floor time grows quadratically on a long run of [ (fnmatch) #37373.
  • test/security_line_budget/ssh-self-glob-verb.txt: a +302 row for this change's own net lines under src/kiro_crew/security/, so test_security_gate_liveness.py's package budget holds.
  • test/test_mcp_listing_import_budget.py: each MCP server's module ceiling rises by 1, because the new ssh gate owner loads on every listing path.
  • src/kiro_crew/security/argv_floor_ssh_gate.py (new): _gate_words, _glob_can_name_ssh_verb, _cannot_name_ssh_verb (from fix(security): keep a quote in a $( ) from hiding a later ssh #37558) and the constants they read move here, so argv_floor_ssh.py stays under 1,600 lines; the facade lists it in _OWNERS and security.md names it. _cannot_name_ssh_verb also probes the text with every quoted-separator key blanked, so it agrees with the gate's sentinel cut. The case-kept text goes through the same _mask_quoted_separators(..., blank_bodies=True) as the lowered text, and the per-call cache key includes it. New tests pin all three.

The rows in the glob tests pass under PYTHONHASHSEED 0 to 31. Against main under 32 hash seeds, with the resolver stubbed to fail closed and no network, over 840 rows (631 ssh-to-self test rows, 181 of them again with each loopback spelling replaced by lvh.me, and 28 ordinary lines): no row that main refuses is allowed here, compared seed by seed. 46 rows are refused here that main allows under every seed, all of them attacks that point at this host (measured with the command passed in its written case, as is_denied does). 32 rows change with the hash seed, the same 32 as on main. Local runs on this head (-n 8 --dist loadgroup): the 24 test files that import the ssh floor, argv_rules, deny_gate or shell_commands pass (3,110 passed), including #37558's main-refused corpus; test_flake_pattern_ratchet.py passes; isort, black, flake8, docs-lint, comment-history, brand and file-line-cap gates are clean; mypy --platform linux src/kiro_crew is clean.

Proof: PROVEN test/test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_a_run_glob_verb_keeps_its_glob_host[s?h -F /dev/null local* id], test/test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_a_run_glob_verb_keeps_its_glob_host[s?h local*], test/test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_a_run_glob_verb_keeps_its_glob_host[s?h local* id], test/test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_a_run_glob_verb_keeps_its_glob_host[s[s]h local* id], test/test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_a_run_glob_verb_keeps_its_glob_host[env s?h local*] (head cdca772)

Manual verification

N/A — the floor is a pure function of the command text; the tests call is_denied on each command directly.

Related Issues

Follow-up to #33299. Found on #33675. Gaps main shares are tracked in #37009 (runner-started globs, the strace -k option reading, multi-program globs whose answer depends on the hash seed, the cp/mv/ln/install copy path, and a quoted > in a one-program -o proxycommand=). Interacts with #33418 (which makes _ssh_family_verb deterministic): the two touch the same function and conflict textually, so whichever merges second rebases; #33418 is also what removes the hash-seed dependence. Needed on release/0.12.0 too: the pick f24c5dc from #34021 carries the same glob_verb line.

Sibling sweep

Swept: git grep -n "match_globs=not|glob_verb" -- src/
Sibling: src/kiro_crew/security/argv_floor_ssh.py:1320 -- changed here -- the first operand check reads the same glob_verb flag
Sibling: src/kiro_crew/security/argv_floor_ssh.py:1457 -- changed here -- the second operand check reads the same glob_verb flag

Pattern harvest

Not generalizable: the exemption was one predicate's trade; the fix moves it to the shell's own run position, resolved by the existing wrapper resolver.

Sensitive change review

Draft for the PR author to confirm on the current head; the author posts it.

  • What rule changed: sandbox-escape-ssh-self keeps glob host matching for a glob verb that bash runs (program position or a wrapper's program), instead of turning it off for every bare glob verb.
  • Before -> after: s?h -F /dev/null local* id and its wrapper, subshell and substitution forms were allowed; now refused. A glob in another program's operands keeps main's answer.
  • Worst case if wrong: a false refusal of a rare line whose glob the reader takes for a run position (listed under Backwards compatibility); it goes to approval.
  • Evidence checked: the GPT finding and Opus uphold on fix: 0.12.1 late batch 2 (6 fixes merged 11-09 01:56-03:49Z) #33675; the 840-row measure against main under 32 hash seeds.
  • No regression:
    • Tools still work: cron schedules, tar/git add/find/mypy/pytest lines over globs and files=$(ls s* l*) keep main's answers.
    • Backward compatible: not fully; the rare shapes listed under Backwards compatibility are newly refused.
    • Existing tests: fix(security): five hook, approval, floor and sandbox fixes #33299's ssh-self tests pass unchanged except s?h local*, moved to refused on purpose.
  • How to undo: revert this commit.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (docs/system-specs/modules/security.md)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 9, 2026 18:52
@buluoray
buluoray requested a review from tim-finnigan November 9, 2026 18:52
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/argv_floor.py

  • src/kiro_crew/security/argv_floor_ssh.py

  • src/kiro_crew/security/argv_floor_ssh_gate.py

  • src/kiro_crew/security/argv_rules.py

  • src/kiro_crew/security/deny_gate.py

  • @buluoray posted a complete reasoning template for 01088f1.

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

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 01088f19c810a2b3eca5d37015d49fd611c2815e 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 Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 01088f19c810a2b3eca5d37015d49fd611c2815e — 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

Every item either closes the reported s?h local* escape or keeps the fix from refusing lines main allows. A bare-verb pin was deleted, but the description says so and gives the reason.

Notes

  • Item 5 — inherited-adjacent: _case_arm_pattern_indices is a third case/esac reader. The other two are deny_gate._nested_past_cap and shell_normalizer_walk. Those two walk raw text and this one walks token indices, so it is not a second spelling of either. Subtraction: none smaller is available. Keep _COMPOUND_OPENERS to the words the deny tests actually use.

What this change ships

Inventory (9 items) — 9 justified

Intent: stop an agent reaching this host over ssh by naming the ssh program through a glob (s?h local*). This is a FIX.

  1. A glob ssh verb in program position with a glob host is now refused (s?h -F /dev/null local* id) — justified
  2. The same verb behind a wrapper (env/sudo/time/xargs), in a subshell, in a $(…) substitution or after a glued ; is refused — justified
  3. The verb gate also cuts words at ;&|(), backticks and the quoted-separator sentinels (_gate_words) — justified
  4. Glob operands in array literals, $(/backtick assignments and case arm patterns are still read as filenames — justified
  5. A case arm body's first word is read as a program — justified
  6. sudo -H/-h options are read in the case they were typed: deny_gate passes the raw text and the memo key holds it. sudo -e runs no program — justified
  7. A non-run glob glued to ; no longer starts an ssh operand scan (git add sc?; curl localhost:3000) — justified
  8. The gate moves into a new argv_floor_ssh_gate.py, and the import ceilings rise by 1 — justified
  9. The security spec paragraph is rewritten to the new glob-verb reading — justified

[FIRST-PRINCIPLES-REVIEWED] 01088f1

Description read

[DESCRIPTION-READ] 2fe6c7f508f236d29dbdcca904eb6fb70d1958a0f0e8ed86fff5a9451312c59a

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 Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the fix closes a fail-open regression in a floor that no OS fence covers yet (#9806). Each new refusal fails closed, is listed and accepted, and reverts cleanly.

Notes

[DESIGN-REVIEWED] 01088f1

Description read

[DESCRIPTION-READ] 121abf17ebaeb19eba9ca01551d8e4e6fda23375836508dfa2dd51911685fd18

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 Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 01088f19c810a2b3eca5d37015d49fd611c2815e — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 01088f1

Verdict parsed from the review's SHA-scoped output markers for commit 01088f19c810a2b3eca5d37015d49fd611c2815e.

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

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 01088f19c810a2b3eca5d37015d49fd611c2815e and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 01088f1

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 01088f19c810a2b3eca5d37015d49fd611c2815e 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 Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ human override accepted

@buluoray overrode this lane for 01088f19c810a2b3eca5d37015d49fd611c2815e via /ai-review override (this commit only).

[SCOPE-REVIEWED] 01088f1

@buluoray
buluoray force-pushed the crew/slack/ssh-self-glob-verb branch from 3cca03e to e72e3c0 Compare November 9, 2026 20:59
@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 Nov 9, 2026
@buluoray
buluoray force-pushed the crew/slack/ssh-self-glob-verb branch from e72e3c0 to 392fdd6 Compare November 9, 2026 21:07
@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 Nov 9, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 10, 2026
@buluoray
buluoray force-pushed the crew/slack/ssh-self-glob-verb branch from 392fdd6 to ed268bf Compare November 10, 2026 03:23
@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 Nov 10, 2026
@buluoray buluoray closed this Nov 10, 2026
@buluoray buluoray reopened this Nov 10, 2026
@buluoray
buluoray force-pushed the crew/slack/ssh-self-glob-verb branch 2 times, most recently from af76c20 to 73c00a3 Compare November 10, 2026 04:02
@github-actions github-actions Bot removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 10, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

Thanks, Bolin. Pushed 0e8c16cabc3e (rebased on main). Both parts are addressed, with one row and a few related shapes left refused for a reason below.

Part 2, no new re.compile: done. _GATE_WORD_SPLIT_RE and _GATE_BRACKET_WORD_RE are gone. One plain character walk, _gate_words(probe, *, group_brackets), replaces both: a blank always ends a word, ;&|() and a backtick end it unless a [ is open, [ opens a class, ] closes it, and a [ inside an open class reopens it at that point. Its word set is the same as the old two-regex set over the 840 test rows plus the bracket cases. TestSshGateBracketWordsAreLinear now checks the walk with no timing: each character is visited at most twice, and the words never add up to more than the input (a re-appending variant fails it).

Part 1, no new refusals where main passes:

Row main this head
n=`ls s* *.* | wc -l` allowed allowed
files=( s* *.* ); printf … allowed allowed
targets=( r* l* ); tar -czf handoff.tgz … allowed allowed
bash -c 'files=( s* *.* ); …' allowed allowed
case "$f" in s* | r* ) wc -l *.* ;; esac (and inside a for loop) allowed allowed
cd /etc/ssh && sudo -e s* *.* allowed refused

_executed_program_indices no longer marks a run position after an assignment that opens a $(, a backtick or an array literal, nor in a case arm's pattern list. Every row in test_a_run_glob_verb_keeps_its_glob_host stays refused.

Why sudo -e stays refused. _is_ssh_to_self reads the lower-cased command, so sudo -e (edit) and sudo -E (keep the environment, then run the program) are the same tokens by the time the run-position reader sees them. Skipping the word after sudo -e would also allow sudo -E ssh localhost. It fails closed to an approval and is pinned in test_a_glob_read_as_a_run_verb_is_a_known_over_block.

Other shapes main allows that stay refused, each because the floor reads it the same way as the attack beside it:

Refused here Read the same as
x=`s* l*` x=`s?h local*`
command -v s?h local* command s?h local*
a heredoc body line r* l* a body line read as a command (bash <<EOF)
ls # x ; s* l* ls ; s* l*
a ^ line join before s* l* a new line s* l*
cd /tmp;ls s* l*, true|ls s* l* cd /tmp;s?h local*, true|s?h local*

Telling these apart needs the original-case text in the floor and a token walk that splits glued separators and knows comments, heredocs and line joins. That is a change to the floor's walk, so I filed #37438 with these rows, the matching attacks and that direction, rather than widen this PR.

Checks on this head: over the 840 rows and 32 hash seeds, compared seed by seed, no row main refuses is allowed; the only non-attack row refused here that main allows under every seed is sudo -e. The 20 security, shell, argv and ssh-config-route test files pass (2,772 passed), and the line budget is a +182 row in test/security_line_budget/ssh-self-glob-verb.txt.

Could you take another look?

@buluoray

Copy link
Copy Markdown
Contributor Author

@bolichen97 ;& (case fall-through) is fixed in a59f93e, with a failing-first test; could you re-review?

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the narrowed design. One defect in the new case reader blocks merge.

  1. src/kiro_crew/security/argv_rules.py:232: _case_arm_pattern_indices opens a case state on any word equal to case, even when that word is only an argument. Trigger: echo case in x; s?h local* id, run in a directory that holds files named ssh and localhost. Outcome: the in moves the state to pattern, and every later word counts as a case pattern until a word contains ). That includes s?h. _executed_program_indices skips it at line 201, so the ssh-to-self floor allows the command. The bare s?h local* id is refused on this head, so a trivial prefix undoes the Goal. echo test case in prod; s?h local* id gets through the same way. Main allows these too, so nothing regresses against main, but this reader is new code in this PR. Smallest fix: open a case state only when case is the program word of its command (for example, check it against the command starts from _split_commands_indexed). Add echo case in x; s?h local* id as a DENY row in test_a_run_glob_verb_keeps_its_glob_host. The allow rows for real case arms stay as they are.

Optional:

  • The new case reader is only tested from the allow side. A DENY row such as case x in a) :;; esac; s?h local* id would fail if someone later removed stack.pop() or the arm close transition.
  • The run-position reader gets lower-cased tokens, but _WRAPPERS lists uppercase value options. So env -C . s?h local*, sudo -D /tmp s?h local* and xargs -P 4 s?h local* are still allowed. This has the same root cause as the sudo -e over-block. You could list them in #37438 with a pinning test rather than fix them here.
  • The cd /tmp;s?h local* row passes because of the / in the glued word, not because of the run-position reader. cd tmp;s?h local* id is allowed. A slash-free row, or a narrower claim in the body, would make this clear.

bolichen97
bolichen97 previously approved these changes Nov 15, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

@KiroCrewCaptain Thanks. Fixed in 415a52d, with the tests written first.

  • _case_arm_pattern_indices now opens a case only when case is in command position. That means the first word of a command from _split_commands_indexed, a word after then/do/else/elif/{/(/! in command position, or the first word of an arm body (a nested case).
  • New DENY rows in test_a_run_glob_verb_keeps_its_glob_host: echo case in x; s?h local* id and echo test case in prod; s?h local* id (both red before the fix). Also case x in a) :;; esac; s?h local* id, which goes red without stack.pop(), and case x in a) true; s?h local* id;; esac, which goes red without the arm-close step.
  • New allow rows: a nested case, and a case inside if … then.
  • The uppercase wrapper value options (env -C, sudo -D, xargs -P) are pinned as a known gap and listed in ssh-to-self floor: read sudo -e, comments, heredocs and glued separators the way bash runs them #37438, together with cd tmp;s?h local* id (the cd /tmp; row is refused only because of its /) and case x in a) s?h local* id;; esac. Main allows all of them too.

The 23 related test files give 2,863 passed and 1 skipped. Could you re-review?

@buluoray

Copy link
Copy Markdown
Contributor Author

Security Scope Review on 415a52d: fixed in 0b0a071, with the tests written first.

  • The cause: the floor lowercased -H to -h, which _WRAPPERS["sudo"] lists as a value option. So ls was read as that value and s* as the program sudo runs.
  • The fix: the run-position reading now reads wrapper option words in the case they were written, and program names still match in any case. sudo -e (edit mode) runs no program, so no word after it is a run verb.
  • New allow rows: sudo -H ls -l s* *.*, sudo -H du -sh s* l*, sudo -E ls s* *.*, sudo -e s* and cd /etc/ssh && sudo -e s* *.*. All five were red or pinned as refused before.
  • New deny rows: env -C . s?h local*, sudo -D /tmp s?h local*, xargs -P 4 s?h local*, sudo -H s?h local* id and sudo -E s?h local* id.
  • Upper-case program and verb names are still caught, and a test pins that.
  • Results: the 23 related test files give 2,873 passed and 1 skipped. The 840-row measure (command passed in its written case) has 0 rows opened against main; the 46 newly refused rows are all attacks.

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fixes. The earlier blocking item is fixed on this head, but one gap of the same kind remains in the new run-position reader.

Earlier request at a59f93e:

  • echo case in x; s?h local* id: fixed. It is refused on this head, and a DENY row pins it.
  • Optional, upper-case wrapper options (env -C, sudo -D, xargs -P): addressed. Reading option words in the case they were written closes them, and DENY rows pin them.
  • Optional, the cd /tmp;s?h local* row: answered in your comment. The body still says this row is closed without naming the / (see the notes below).

Still blocking:

  1. security/argv_rules.py:204 (_executed_program_indices). The first word of a case-arm body is never marked as run. Trigger: with files named ssh and localhost in the working directory, run case x in x) s?h -F /dev/null local* id;; esac. Outcome: _split_commands_indexed gives one command that starts with case, so _program_index marks only case. s?h keeps the glob-verb exemption, local* is never matched as this host, and is_denied returns None. Bash then runs ssh -F /dev/null localhost id. The same happens with case x in x) env s?h local* id;; esac, case x in (x) s?h local* id ;; esac and case x in a) :;; x) s?h local* id;; esac. The bare s?h -F /dev/null local* id is refused on this head, so a one-word case wrapper defeats the Goal. Main allows these too, so this is not a regression. But the reader is new in this PR, _case_arm_pattern_indices already sets program_position = True right after the arm's ), and the test comment near test/test_denied_commands_security_ssh_self.py:827 says arm-body commands are covered. Its only row is the form after ;. Smallest fix: have _case_arm_pattern_indices also return the index of each arm body's first word, and in _executed_program_indices run _program_index from that index so wrappers such as env s?h resolve too. Then add DENY rows for the four spellings above. If you would rather defer it to #37438, add a known-gap row that pins the current allow, narrow the test comment and the security.md sentence to match the code, and ask a maintainer to record the decision on this head.

Optional:

  • A ; glued inside a word (cd tmp;s?h local* id) is still allowed, and cd docs;ls s* *.* is newly refused. Both come from one cause: _gate_words cuts the word at the ;, but the run-position reader does not. The body discloses both. The Security Scope block on this head still has no recorded decision.
  • sudo -T 5 s?h local* id is still allowed because -T is missing from the sudo value options in _WRAPPERS.
  • The "What changed" table row cd /tmp;s?h local* reads as closed only because of the /. Naming that, and listing the case-arm body as open until item 1 lands, would make the body match the code.

@buluoray

Copy link
Copy Markdown
Contributor Author

@KiroCrewCaptain Thanks. The case-arm body is fixed in 61b1a7e, using your smallest fix, with the tests written first.

  • _case_arm_pattern_indices also returns the index of each arm body's first word, the word right after the arm's ). Its pattern set is unchanged.
  • _executed_program_indices runs _program_index from each of those indices too, so a wrapper in the arm (env s?h) resolves.
  • New DENY rows, all four red before the fix: case x in x) s?h -F /dev/null local* id;; esac, case x in x) env s?h local* id;; esac, case x in (x) s?h local* id ;; esac, case x in a) :;; x) s?h local* id;; esac.
  • New ALLOW row: case "$f" in docs) ls s* *.* ;; esac. Every existing case allow row still passes.
  • The PR body no longer says the glued-; row is closed without naming the /. cd tmp;s?h local* id and cd docs;ls s* *.* are tracked in ssh-to-self floor: read sudo -e, comments, heredocs and glued separators the way bash runs them #37438 and ssh-to-self floor refuses sudo -H in nested scripts and a glued ; before a glob pair #37543. I left the optional _gate_words and glued-; changes out of this PR.

The 23 related test files give 2,878 passed and 1 skipped. On the 840-row measure, 0 rows are newly allowed against main, and the 46 newly refused rows are all attacks. Could you re-review?

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the case-arm fix. One gap of the same kind is left, in the verb gate this PR adds.

This is the third review round on one class (a glob verb the run-position reader does not see), after case in x and the case-arm body. AGENTS.md asks that a finding which repeats a class change the approach rather than patch another spelling, so please pick one of the two routes in item 1 that closes the class (gate the unmasked text), or defer it with a known-gap row. Another one-spelling patch is not what this asks for.

Earlier request at 0b0a071:

  • First word of a case-arm body not marked as run: fixed. On this head, case x in x) s?h -F /dev/null local* id;; esac, case x in x) env s?h local* id;; esac, case x in (x) s?h local* id ;; esac and case x in a) :;; x) s?h local* id;; esac are all refused, and DENY rows pin them.
  • Optional, the glued ; shapes (cd tmp;s?h local* id, cd docs;ls s* *.*): answered. They are tracked in #37438 and #37543.
  • Optional, the cd /tmp;s?h local* table row: answered in the body.

Still blocking:

  1. src/kiro_crew/security/argv_floor_ssh.py:127 (_GATE_WORD_SEPARATORS), which returns early at :1174. A glob verb at the start of a double-quoted $( ) never passes the verb gate. Trigger: with a file named ssh in the working directory (and localhost for the glob-host forms), run echo "$(s?h localhost id)", echo "$(s?h local* id)" or x="$(s?h local* id)". Outcome: _mask_quoted_separators turns the quoted ( into its mask sentinel, so the probe word is $\x05s?h. _gate_words does not cut at that sentinel, so _glob_can_name_ssh_verb returns False. The function then returns at :1174 before the double-quoted body reader at :1183 runs. That reader would refuse the body, because _is_ssh_to_self('s?h localhost id') is True. All three lines are allowed on this head, even with a literal localhost. The unquoted echo $(s?h local* id) is refused. Main allows these lines too, so this is not a regression. But the new docstring says a verb glued to a substitution opener ($(s?h) is still a word, and the Goal says a glob such as s?h can no longer reach this machine. Neither #37009 nor #37438 names this form. Smallest fix: add the mask sentinels the floor emits to _GATE_WORD_SEPARATORS, or also run the gate over the unmasked text. Then add DENY rows for the three lines above to test_a_run_glob_verb_keeps_its_glob_host, plus an ALLOW row such as echo "$(ls s* *.*)". If you would rather defer it, name it in the body's Backwards compatibility gaps and in #37438, and pin the current allow with a known-gap row.

Optional:

  • In a recursive frame, wrapper options are read lower-cased. So echo "$(sudo -H ls s* l*)" is newly refused (main allows it), and echo "$(sudo -H s?h local* id)" stays allowed. The Breaking: list does not name the first. #37543 also says a double-quoted $( ) is not affected, which is not what happens on this head. Passing the written-case body into the recursion at :1183 would fix both.
  • argv_floor_ssh.py grows from 1,537 to 1,631 lines, past the 1,600-line target. You could move _gate_words and _glob_can_name_ssh_verb into a sibling module.
  • The only row that pins the glued ;/| operand guard (git add *; curl -s localhost:3000/healthz) goes red only on some hash seeds. A row whose glob names exactly one verb, such as git add s?h; curl -s localhost:3000/healthz, would red on every run.

@buluoray

Copy link
Copy Markdown
Contributor Author

Thanks. All three items from your review on aaefd76 are in head 0a36723, which is also rebased onto current main (it keeps the nesting bound from #37820 and its tests):

  • Masked opener: _GATE_WORD_SEPARATORS now also cuts at the floor's quoted-separator markers, so a glob verb right after a quoted $( reaches the gate. echo "$(s?h localhost id)", echo "$(s?h local* id)" and x="$(s?h local* id)" are deny rows (red before the fix), and echo "$(ls s* *.*)" is an allow row.
  • File size: _gate_words, _glob_can_name_ssh_verb and the constants they read moved unchanged into argv_floor_ssh_gate.py. argv_floor_ssh.py is 1,578 lines.
  • Breaking list: it now names echo "$(sudo -H ls s* l*)" and the nested sudo -H forms (ssh-to-self floor refuses sudo -H in nested scripts and a glued ; before a glob pair #37543). ssh-to-self floor refuses sudo -H in nested scripts and a glued ; before a glob pair #37543's body no longer says a double-quoted $( ) is unaffected.
  • Guard row: the glued-; row is now git add sc?; curl -s localhost:3000/healthz. It goes red on seeds 0, 1 and 12345 with the guard removed. The s?h spelling stayed green there, because ssh reads localhost:3000/... as its command.

The 840-row measure still shows no row that main refuses allowed here. Could you re-review?

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Re-review of e111e14. Nothing from my review on aaefd76 still stands:

  1. Glob verb right after a quoted $(: fixed. _GATE_WORD_SEPARATORS in argv_floor_ssh_gate.py now cuts at the quoted-separator sentinels. echo "$(s?h localhost id)", echo "$(s?h local* id)" and x="$(s?h local* id)" are deny rows, and echo "$(ls s* *.*)" is an allow row.

I found no blocking defect. The review ran is_denied on this head and on main over the ssh-self test rows under several hash seeds, and no command that main refuses is allowed here. When the new guards were mutated one line at a time, most of the mutations turned a named test row red. The fix is tied to where bash actually runs the word, and when the reader cannot tell, it falls back to main's reading.

It cannot be approved yet because PR Readiness is red on this head. These items are still open:

  • The fenced security-class finding at argv_floor_ssh.py:1170. Nested readings read sudo -H lower-cased, so echo "$(sudo -H ls s?h l*)" is refused. This finding only over-refuses. It needs a code fix or an override from a repository writer, for example deferred #37543.
  • The Sensitive Change Review template has not been posted for e111e14.

Optional:

  • The same root cause also lets some commands through, as it does on main. echo "$(env -C . s?h local* id)", echo "$(sudo -H s?h local* id)" and f(){ env -C . s?h $1 id; }; f local* still reach this host. A deferred #37543 override would defer these too. Naming them in ssh-to-self floor refuses sudo -H in nested scripts and a glued ; before a glob pair #37543, with a known-gap row, would make that visible.
  • A separator glued to an operand word is still allowed, as on main: cd tmp;s?h local* id and cd tmp&&s?h local* id. A known-gap row, plus && in ssh-to-self floor: read sudo -e, comments, heredocs and glued separators the way bash runs them #37438, would pin it. The comment near test_denied_commands_security_ssh_self.py:816 cites cd /tmp;s?h local*. That row is refused because of the /, not because of the separator.
  • No test row covers the bracket-class word set in _glob_can_name_ssh_verb (argv_floor_ssh_gate.py:102). If you remove it, all tests stay green and (s[s\)]h local* id) is allowed. Deny rows for that line and for x=$(s[s\)]h local* id) would pin it.

@buluoray

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt e111e14 deferred #37543: A false refusal that fails closed, deferred to #37543. A nested read (a bash -c payload, a function body, a double-quoted $( ) or rsync's remote shell) still reads wrapper options lower-cased, so sudo -H is read as -h and the next word is skipped. It needs a nested script, an upper-case wrapper option, a glob that could spell an ssh verb as an operand and a self-host word, all together; the call goes to an approval and nothing reaches this host.

@buluoray

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: e111e14
  • What rule changed: the ssh-to-self floor (sandbox-escape-ssh-self, _is_ssh_to_self in src/kiro_crew/security/argv_floor_ssh.py) keeps glob host matching for a glob verb that bash runs: program position, or the program a command wrapper runs (argv_rules._executed_program_indices, over the existing _program_index). The wrapper option words are read in the case they were written (sudo -H takes no value, sudo -e runs no program); program names still match in any case. Before, every bare glob verb turned glob host matching off. Every other glob keeps main's reading.
  • Before -> after: before, s?h -F /dev/null local* id and its env/sudo/time/xargs, subshell and $( ) forms reached this host's sshd outside the sandbox when the folder held files named ssh and a loopback name. Now they are refused. Ordinary lines over globs (tar, git add, find, mypy, pytest, files=$(ls s* l*)) keep main's answer. A few rare shapes that main allows are refused on purpose; they are listed in ssh-to-self floor: read sudo -e, comments, heredocs and glued separators the way bash runs them #37438 and ssh-to-self floor refuses sudo -H in nested scripts and a glued ; before a glob pair #37543.
  • Worst case if wrong: a false refusal of a rare line whose glob the reader takes for a run position. It fails closed: the call goes to an approval, never a silent run. The opposite direction (an ssh to this host that main refused) was measured and not found. Gaps that main shares stay open and are tracked in security: a glob copied by cp/mv/ln/install keeps one program's reading in the ssh-to-self floor #37009.
  • Evidence checked: the GPT finding on fix: 0.12.1 late batch 2 (6 fixes merged 11-09 01:56-03:49Z) #33675 and its Opus uphold. The 840-row measure against main under 32 PYTHONHASHSEED values (631 ssh-to-self test rows, 181 of them with each loopback spelling replaced by lvh.me, and 28 ordinary lines; resolver stubbed to fail closed, no network): compared seed by seed, no row that main refuses is allowed here, and the 32 rows whose answer depends on the seed are the same 32 as on main. prove.py reports PROVEN: reverting the production hunks turns the new tests red.
  • No regression:
    • Tools still work: cron schedules quoted in an unattended MCP call keep main's answer, and tar, git add, find, ruff, mypy, pytest and $( ) assignment lines over globs pass (tests in test_denied_commands_security_ssh_self.py).
    • Backward compatible: not fully, on purpose. The rare shapes listed in ssh-to-self floor: read sudo -e, comments, heredocs and glued separators the way bash runs them #37438 and ssh-to-self floor refuses sudo -H in nested scripts and a glued ; before a glob pair #37543 are newly refused; each one fails closed and has a simple fix. _program_index is split out of _program_args, and its new options argument defaults to today's reading, so the other deny rules are unchanged (test_argv_rules.py passes). deny_gate.is_denied also hands the floor the command as submitted, for the option case.
    • Existing tests: the 21 test files that import the ssh floor, argv_rules or deny_gate pass on this head (2,497 passed). The package line budget is a +282 row in test/security_line_budget/ssh-self-glob-verb.txt. mypy, flake8, isort, black, Semgrep, docs-lint, the line cap and the flake ratchet are clean.
  • How to undo: revert the squashed commit. The change is one new helper in argv_rules.py, one condition and the case-kept frames in _is_ssh_to_self, the verb gate's word split and one elif in deny_gate.is_denied, so nothing else needs to be unwound.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@buluoray recorded a deferred release (class deferred) for the gpt AI finding on e111e14a07d0a7ad27ed72f21df74accf9602859.

A false refusal that fails closed, deferred to #37543. A nested read (a bash -c payload, a function body, a double-quoted $( ) or rsync's remote shell) still reads wrapper options lower-cased, so sudo -H is read as -h and the next word is skipped. It needs a nested script, an upper-case wrapper option, a glob that could spell an ssh verb as an operand and a self-host word, all together; the call goes to an approval and nothing reaches this host.

This decision applies only to this commit. A new push requires a new judgment.

@bolichen97

Copy link
Copy Markdown
Contributor

@buluoray the Captain's re-review on e111e14a07 found no blocking defect. Two items keep PR Readiness red:

  1. Sensitive Change Review: the template has not been posted for e111e14a07. Please post it for this head.
  2. The fenced finding at argv_floor_ssh.py:1170 (nested sudo -H read lower-cased, so echo "$(sudo -H ls s?h l*)" is refused): it only over-refuses, and ssh-to-self floor refuses sudo -H in nested scripts and a glued ; before a glob pair #37543 already tracks the root cause. Please add the shapes the Captain listed as still allowed (env -C . s?h, sudo -H s?h, the function form) to ssh-to-self floor refuses sudo -H in nested scripts and a glued ; before a glob pair #37543 with known-gap rows here, so the deferral is visible and the follow-up flips a test. With that in place, a deferred #37543 override from a maintainer is the right call.

Optional from the same review: deny rows for the bracket-class branch in _glob_can_name_ssh_verb ((s[s\)]h local* id)), which no test covers today.

AI-assisted, sent by Bolin Review bot

A verb read through a bare glob such as s?h turned glob host matching
off, so s?h -F /dev/null local* id was allowed. In a directory holding
files named ssh and localhost, which an agent can create, the shell
expands it into an ssh connection to this host outside the sandbox.

Keep glob host matching on when bash runs the glob verb: in program
position, or as the program a command wrapper runs (resolved by
argv_rules._program_index). A glob verb that only sits in another
program's operands keeps main's reading, so tar, git add and find lines
over globs stay allowed. The verb gate splits words at command
separators and parentheses, so a glob verb inside a subshell, a
command substitution or after a glued ";" is read too, and an
assignment that opens a $( hands the program position to the
substitution's own program.

The gate also cuts words at the sentinels that stand for a quoted
separator, so echo "$(s?h localhost id)" is read like its unquoted
form. The gate words, the glob test, the ssh-family verb set and the
quoted-separator sentinels live in a new owner module,
argv_floor_ssh_gate, which keeps argv_floor_ssh under the line cap.

The ssh gate is one more owner module on every MCP server listing path,
so each server ceiling in test_mcp_listing_import_budget.py rises by 1.
@buluoray

Copy link
Copy Markdown
Contributor Author

Owner decision for #34056 (head 01088f19c810). These commands are allowed on main and refused by this PR on purpose. The floor reads each one the same way as an ssh-to-self attack it must refuse, so it cannot allow one without the other yet. Each refusal fails closed: the call goes to an approval, never a silent run. Each has a simple fix, and #37438 tracks reading them the way bash runs them.

Refused here Read the same as Fix
x=`s* l*` x=`s?h local*` use $( ) with a named program
command -v s?h local* command s?h local* name the file
a heredoc body line that starts with a glob pair (cat <<'EOF' or sort -u <<'EOF' with r* l*) a body line read as a command start the line with a plain word
a spaced ; in a trailing comment before a glob pair (ls # x ; s* l*) ls ; s* l* remove the ;
a Windows line join (^ or a PowerShell backtick) before an s* l* line a new command line s* l* put the command on one line
a ; or | glued before a glob pair (cd /tmp;ls s* l*, true|ls s* l*) cd /tmp;s?h local*, true|s?h local* put a space after the ; or |
cd docs;ls s* *.* (a glued ; before a glob pair; tracked in #37543) cd docs;s?h local* put a space after the ;
sudo -H (or another upper-case wrapper option) inside a nested script: bash -c 'x=1; sudo -H ls s[s]h local*', f(){ sudo -H ls s[s]h $1; }; f local*, bash -c 'DIR=/srv/data; cd "$DIR" && sudo -H du -sh s* l*', sh -c 'X=1; sudo -P ls -l s* l*', echo "$(sudo -H ls -l s* *.*)" (tracked in #37543) sudo -h <host> s?h local* (a nested script is still read lower-cased) run the command outside the nested script, or name the files
Compress-Archive -Path s* -DestinationPath out.zip (refused under some hash seeds only, as main is under one; tracked in #37009) a multi-name glob read as one ssh-family program name the files

Gaps that main shares stay open and are tracked in #37009 (runner-started globs, seed-dependent multi-name globs, the copy path, -o proxycommand=) and #37373 (a slow fnmatch path on a long run of [). Over 840 rows and 32 hash seeds, compared seed by seed, no row main refuses is allowed here.

@buluoray

Copy link
Copy Markdown
Contributor Author

/ai-review override scope 01088f1 owner-decision: main allows, PR refuses, fail closed, each read the same as an ssh-to-self attack (rows in Decision, tracked in #37438 and #37543): backtick assign x=s* l*; command -v; heredoc body line starting with a glob pair; spaced ; in a comment; Windows line join; ; or | glued before a glob pair; sudo -H/-P inside bash -c, sh -c or a quoted $( ) (#37543); Compress-Archive -Path s* (seed-dependent, #37009). Decision: #34056 (comment)

@buluoray

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 01088f1
  • What rule changed: the ssh-to-self floor (sandbox-escape-ssh-self, _is_ssh_to_self in src/kiro_crew/security/argv_floor_ssh.py) keeps glob host matching for a glob verb that bash runs: program position, or the program a command wrapper runs (argv_rules._executed_program_indices, over the existing _program_index). The wrapper option words are read in the case they were written (sudo -H takes no value, sudo -e runs no program); program names still match in any case. Before, every bare glob verb turned glob host matching off. Every other glob keeps main's reading.
  • Before -> after: before, s?h -F /dev/null local* id and its env/sudo/time/xargs, subshell and $( ) forms reached this host's sshd outside the sandbox when the folder held files named ssh and a loopback name. Now they are refused. Ordinary lines over globs (tar, git add, find, mypy, pytest, files=$(ls s* l*)) keep main's answer. A few rare shapes that main allows are refused on purpose; they are listed in ssh-to-self floor: read sudo -e, comments, heredocs and glued separators the way bash runs them #37438 and ssh-to-self floor refuses sudo -H in nested scripts and a glued ; before a glob pair #37543.
  • Worst case if wrong: a false refusal of a rare line whose glob the reader takes for a run position. It fails closed: the call goes to an approval, never a silent run. The opposite direction (an ssh to this host that main refused) was measured and not found. Gaps that main shares stay open and are tracked in security: a glob copied by cp/mv/ln/install keeps one program's reading in the ssh-to-self floor #37009.
  • Evidence checked: the GPT finding on fix: 0.12.1 late batch 2 (6 fixes merged 11-09 01:56-03:49Z) #33675 and its Opus uphold. The 840-row measure against main under 32 PYTHONHASHSEED values (631 ssh-to-self test rows, 181 of them with each loopback spelling replaced by lvh.me, and 28 ordinary lines; resolver stubbed to fail closed, no network): compared seed by seed, no row that main refuses is allowed here, and the 32 rows whose answer depends on the seed are the same 32 as on main. prove.py reports PROVEN: reverting the production hunks turns the new tests red.
  • No regression:
    • Tools still work: cron schedules quoted in an unattended MCP call keep main's answer, and tar, git add, find, ruff, mypy, pytest and $( ) assignment lines over globs pass (tests in test_denied_commands_security_ssh_self.py).
    • Backward compatible: not fully, on purpose. The rare shapes listed in ssh-to-self floor: read sudo -e, comments, heredocs and glued separators the way bash runs them #37438 and ssh-to-self floor refuses sudo -H in nested scripts and a glued ; before a glob pair #37543 are newly refused; each one fails closed and has a simple fix. _program_index is split out of _program_args, and its new options argument defaults to today's reading, so the other deny rules are unchanged (test_argv_rules.py passes). deny_gate.is_denied also hands the floor the command as submitted, for the option case.
    • Existing tests: the 24 test files that import the ssh floor, argv_rules, deny_gate or shell_commands pass on this head (3,110 passed). The package line budget is a +302 row in test/security_line_budget/ssh-self-glob-verb.txt. mypy, flake8, isort, black, Semgrep, docs-lint, the line cap and the flake ratchet are clean.
  • How to undo: revert the squashed commit. The change is one new helper in argv_rules.py, one condition and the case-kept frames in _is_ssh_to_self, the verb gate's word split and one elif in deny_gate.is_denied, so nothing else needs to be unwound.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@buluoray recorded a owner-decision release (class owner-decision) for the scope AI finding on 01088f19c810a2b3eca5d37015d49fd611c2815e.

main allows, PR refuses, fail closed, each read the same as an ssh-to-self attack (rows in Decision, tracked in #37438 and #37543): backtick assign x=s* l*; command -v; heredoc body line starting with a glob pair; spaced ; in a comment; Windows line join; ; or | glued before a glob pair; sudo -H/-P inside bash -c, sh -c or a quoted $( ) (#37543); Compress-Archive -Path s* (seed-dependent, #37009). Decision: #34056 (comment)

This decision applies only to this commit. A new push requires a new judgment.

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving head 01088f1. The review ran is_denied on this head and on the merge base over more than 120 hand-written rows. It also ran main's ssh-self test file against this head's code: the only change is the intended flip of s?h local*. When run against main's code, this head's ssh-self test file fails all 30 rows of test_a_run_glob_verb_keeps_its_glob_host, which shows the tests pin the fix. The ssh-self and cost test files pass at this head (604 tests). PR Readiness is green, and every lane on this head passes.

Security: this changes the ssh-to-self deny floor, so the risk is a command that main refuses being allowed here. The review found no such command. Every glob-verb attack shape it tried that this head refuses, main allows. Main allows the shapes this head still lets through, so none of them is a regression. The new refusals all fail closed to an approval, and the description lists them.

Earlier review items: the echo case in x opener, the case-arm body first word and the glob verb inside a quoted $( ) are all fixed, and deny rows pin each one.

Done well: the exemption now follows where bash actually runs a word, through the existing wrapper resolver, rather than another spelling in a matcher.

Optional:

  • _case_arm_pattern_indices (argv_rules.py:257) closes a case only on a bare esac. In { case x in x) :;; esac;}; s?h local* id, the case never closes, so s?h is read as a pattern and the line is allowed. Main allows it too. A prefix match on esac plus a deny row would close this.
  • The glued-separator forms (cd tmp;s?h local* id, echo a;s?h local* id) and the nested sudo -H / env -C forms are still allowed, as on main. Known-gap rows citing #37438 and #37543 would make the follow-up flip a test. The comment above the cd /tmp;s?h local* row could say that row is refused because of the /.
  • No test covers the bracket-class read in _glob_can_name_ssh_verb (argv_floor_ssh_gate.py:106) or the open-backtick check (argv_rules.py:303). Deny rows for (s[s\)]h local* id) and x=`true` s?h local* id would pin them.

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.

3 participants