Skip to content

fix(security): judge a glob program as every ssh-family verb it can name - #25993

Open
CrysisDeu wants to merge 2 commits into
mainfrom
fix/ssh-glob-verb-order-25848
Open

CrysisDeu wants to merge 2 commits into
mainfrom
fix/ssh-glob-verb-order-25848

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: the ssh-to-self deny floor gives the same verdict for a glob program word (s??, *, [rs]*) in every Python process, and refuses when any program the glob can name would reach this host.

_ssh_family_verb resolved a glob basename by looping over the _SSH_FAMILY_VERBS frozenset and returning the first match. Frozenset order follows PYTHONHASHSEED, so s?? was read as scp in some processes and ssh in others. scp checks every operand; ssh checks only the first. So /usr/bin/s?? x localhost was refused under seeds 0, 1, 3, 4 and allowed under 2 and 5.

The same cause flips * stash * (seen in a deny-corpus run): on main it is refused under seed 3, 4 and allowed under 0, 1, 2, 5, because * as a program was read as scp (checks the glob operand * as a host) or ssh (checks only stash). With this fix it is refused under every seed, like other glob hosts.

Why it matters

This is a sandbox-escape floor: an allowed s?? x localhost lets bash expand the glob to scp ssh x localhost (or similar) and open a channel back into this host. The same command could pass on one gateway start and be refused on the next.

Not a goal

  • Brace and extglob program words ({scp,ssh} x localhost, s@(cp|sh) ...). The review found these are allowed on main too; this PR does not change them.

  • A glob program glued to a substitution opener (echo $(s?? x localhost)). The pre-walk gate _glob_can_name_ssh_verb matches $(s?? as a whole word and skips the walk. Allowed on main under every seed too; unchanged here.

  • Changing which operands each verb checks.

  • A host given only by a run-time substitution, e.g. ssh $(case $x in *) echo ::1;; esac) id. This is the floor's documented run-time residual on main (_static_substitution_output resolves only echo/printf bodies); this PR does not try to close it.

A word ending in ) is judged like any other word

A case pattern and a program word split the same way: case $x in *) … gives *), $(which r*) gives r*), (xargs s??) gives s??). A case-context tracker and a "glob ) words name no program" rule were both tried, and blind reviews found bypasses in both. With the tracker, the words case/in passed as plain arguments made $(which ssh) localhost read as a pattern. With the glob rule, (s?h), $(which r*) and (xargs s??) stopped naming a program (294 commands main denies became allowed). So no ) word is skipped: ssh) is ssh, and *) is every verb it can name.

Safe-side cost (refused on this PR):

  • case $x in ssh) ssh localhost;; esac (a case line that names this host).
  • case "$mode" in clean) rm -f *.o ;; *) tar czf out.tgz * ;; esac
  • case "$1" in *) cp * /backup/ ;; esac
  • case "$1" in -h|--help) echo usage ;; *) ls -la * ;; esac
  • case "$f" in *.py) black "$f" ;; *) git add * ;; esac
  • case "$f" in *.py) ruff check "$f" ;; *) prettier --check * ;; esac
  • bash -c 'case "$1" in *) ls -la * ;; esac' (the same ls line inside bash -c; Security Scope Review's Windows leg on 41ec128. deny_diff.py, main 934f7a8 vs 41ec128, fresh process per ref, PYTHONHASHSEED 0 and 2: allowed on main, refused here; 0 commands main refuses become allowed.)

The *) lines are case arms with a later glob operand. On head 04d1bff Security Scope Review confirmed four of them (tar, cp, ls, prettier) as newly refused on both its macOS and Ubuntu legs (0 on Windows); deny_diff.py against main af11620 at PYTHONHASHSEED 0 and 2 gives allowed on main, refused here, for all five, and 0 main-refused commands allowed: read as scp/rsync, *) checks the * operand, which can expand to this host's name. On main their verdict depends on the hash seed: *) is read as whichever verb the frozenset yields first, so they are allowed under some seeds and refused under others.

Cost on extreme glob lines

Each multi-verb glob word walks the rest of its command once per verb it can name, so a line made almost only of glob words costs more than on main. Main's walk is already quadratic here. Verdicts match main.

Input main this PR
ssh + 300 glob words (1.4 KB) 0.19 s 0.27 s
ssh + 600 glob words (2.8 KB) 0.49 s 0.82 s
ssh + 3,900 glob words (18 KB) 14.0 s, allow 28.6 s, allow

A running gate call has no time limit; the only 15 s limit is the wait for a free worker. So the 18 KB line runs to its real verdict on both. This is an availability cost on an extreme input only, the same class as the self-kill window tracked in #18385 (numbers added there).

Intended? / Repro

Intended? No. The floor documents glob program words as "read toward deny, like a glob host"; a verdict that depends on the hash seed is not a design choice.

Repro (main 043dd9fd7f):

  • src/kiro_crew/security/argv_floor_ssh.py:564-566: for verb in _SSH_FAMILY_VERBS: if fnmatch.fnmatchcase(verb, base) ...: return verb.
  • PYTHONHASHSEED=0 → _is_ssh_to_self("/usr/bin/s?? x localhost") is True (read as scp). PYTHONHASHSEED=2 → False (read as ssh).

What changed (motivation → approach → change)

Symptom: seed-dependent verdict. Cause: first match from a set. Change: judge every verb the glob can name, at that token.

  • _ssh_family_verbs(token): every ssh-family verb a token can invoke, in sorted order (s?? → ("scp", "ssh"), * → all four).
  • _ssh_family_verb(token): the first of those in sorted order, never a set's order.
  • _frame_verb_choices: the operand walk visits a multi-verb token once per verb it can name and refuses if any reading reaches this host. The choice is local to the token, so no line-wide combination of choices is built.
  • A cp/mv/ln copy of a multi-verb glob binds its destination to the whole verb tuple.
  • _glob_can_name_ssh_verb iterates the sorted tuple too (its any answer was already order-free).
  • _is_ssh_to_self is wrapped by _shares_nested_verdicts, which keeps the verdicts of nested payloads (-e, proxycommand, RSYNC_RSH, xargs rebuilds) for the length of one outer call, in a ContextVar (_SSH_SELF_VERDICTS). The walk itself stays in _is_ssh_to_self, so its one frame loop and per-frame memo are where the cost test expects them.
  • The same per-call scope also keeps operand verdicts (_OPERAND_VERDICTS, keyed on the exact operand and position, around _judge_operand) and hosts-file verdicts (_HOSTS_FILE_VERDICTS in argv_floor_hosts, keyed on the exact host). Both are opened and reset in finally with _SSH_SELF_VERDICTS, and are never shared across calls or threads. _unmask_separators returns early when no separator marker is present.
  • src/kiro_crew/security/argv_floor.py: nine owner names join the TYPE_CHECKING manifest.
  • test/test_security_gate_liveness.py: the package line budget is raised by 108 (33,172 → 33,280) with a note naming the additions. Without it, walking each glob once per verb re-walked the same nested payload from every walk: a three-level proxycommand line with 24 globs took 64 s (2 s on main). It now walks 3 frames and takes 0.2 s.

Other design considered: walking the whole line once per combination of verb choices, with a cap. The first review rejected it: cost grew as a power of the glob count, and the cap refused harmless lines like echo * s* *s* *p* [rs]*.

Security

area: security, the ssh-to-self sandbox-escape floor. The change only adds refusals: glob program words that one of their verbs would refuse, and the safe-side case lines listed above. The memos hold booleans for one call and are reset in finally.

Independent review: two blind, read-only reviews of the diff and the issue.

  • Round 1 (combination walk): High exponential cost, Medium cap refusing harmless lines. Both fixed by the per-token walk.
  • Round 2 (per-token walk): no High. Medium: nested lines still multiplied per level (fixed by the per-call memo above). Low: cost test too shallow (now a 3-level proxycommand and rsync case, asserting one walk per payload). Low: brace/extglob gap, present on main, out of scope.
  • Rounds 3-5 () words): a case-context tracker had a Critical (plain case/in arguments opened a fake pattern slot) and was dropped; a "glob ) words name no program" rule had a High (294 main-denied commands allowed) and was dropped. The final round, on this head, is clean: 0 main-denied commands become allowed over about 16,000 inputs on seeds 0 and 2, all 294 rows above are refused, the memos change no verdict (re-run with memos disabled: 0 of 15,969 differ) and leave nothing set after allowed, refused or raising calls or across 8 threads.
  • Both of the first two rounds confirmed the same verdicts under seeds 0, 1, 2, 5 for s??, s*, *, [rs]*, s[cs]?, sudo/env/xargs/RSYNC_RSH/proxycommand/cp shapes, and that echo/ls/cp * lines and s?? remote.example.com id stay allowed.

Backwards compatibility

Compatible: a literal program name (ssh, /usr/bin/scp, ssh.exe) resolves to the same single verb as before. Only glob program words that can name several verbs are judged differently, toward deny.

Removes nothing: no key, field or error path is removed.

Tests

test/test_denied_commands_security_ssh_self.py:

  • test_glob_naming_several_verbs_is_judged_as_every_verb: s??, s??.exe, s*, [rs]s*, a glob program inside a *) case arm, * stash *, and a cp copy of s?? aimed at this host are refused.
  • test_a_literal_verb_ending_in_a_paren_is_that_verb: $(which ssh) localhost, (xargs ssh) <<< localhost, (ssh localhost), $(which scp) …, the env -u case -u in … and echo case in x;; … shapes, and the four safe-side case lines above are refused.
  • test_glob_naming_several_verbs_stays_allowed_off_this_host: the same globs aimed at a remote host, ls *, cp * /backup/ stay allowed.
  • test_glob_verbs_are_every_verb_in_sorted_order: _ssh_family_verbs / _ssh_family_verb answers.
  • test_many_verb_capable_globs_in_data_stay_allowed: echo, ls, rm lines with many globs are allowed.
  • test_nested_multi_verb_globs_walk_each_payload_once: 3-level proxycommand and rsync -e lines with 4 and 24 globs tokenize each payload once.
  • test_nested_payload_verdicts_do_not_outlive_the_call: all three memos read None after the call.
  • test_glob_verb_verdict_does_not_depend_on_the_hash_seed: runs the check in fresh interpreters under seeds 0, 2, 5.

On main the repro and hash-seed tests fail.

Proof: not provable -- other: this host runs no local tests; CI runs the new tests

Manual verification

N/A beyond the review probes above. Static gates run locally: black, isort, flake8, mypy, scripts/check_file_line_cap.py. Tests run in CI.

Related Issues

Fixes #25848

Sibling sweep

Swept: git grep -n "for verb in _SSH_FAMILY_VERBS|next(iter(" -- 'src/kiro_crew/security/argv_floor*.py'
Sibling: src/kiro_crew/security/argv_floor_ssh.py _ssh_family_verb -- changed here (first match from a set)
Sibling: src/kiro_crew/security/argv_floor_ssh.py _glob_can_name_ssh_verb -- changed to the sorted tuple (its any answer was already order-free)
Sibling: src/kiro_crew/security/argv_floor_ssh.py any(verb in probe for verb in _SSH_FAMILY_VERBS) -- not affected (any is order-free)
Sibling: src/kiro_crew/security/argv_floor_hosts.py next(iter(_HOST_VERDICT_CACHE)) -- not affected (dict eviction order, not a verdict)

Pattern harvest

Rule candidate: a deny floor never takes "the first match" from a set or frozenset; iterate a sorted tuple, and when several matches are possible, judge every one toward deny.

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

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@CrysisDeu
CrysisDeu requested review from a team and KiroCrewCaptain as code owners October 29, 2026 23:17
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 6550249
  • What rule changed: the ssh-to-self sandbox-escape floor in src/kiro_crew/security/argv_floor_ssh.py: _ssh_family_verb / new _ssh_family_verbs and _frame_verb_choices (how a glob program word maps to ssh/scp/sftp/rsync), and _is_ssh_to_self (new per-call memo of nested payload verdicts, _SSH_SELF_VERDICTS).
  • Before -> after (what was allowed/blocked, now): before, a glob program word that names several verbs (s??, *) was read as whichever verb a frozenset gave first, so /usr/bin/s?? x localhost was refused under PYTHONHASHSEED 0,1,3,4 and allowed under 2,5. Now it is judged as every verb it can name and refused under every seed. A 3-level proxycommand line with 24 globs: 64 s / 5,403 frames before the memo, 0.2 s / 3 frames now (main: 2 s / 651 frames).
  • Worst case if wrong (breaks commands / leaks secret / locks user out): false refusal of a command whose program word is a glob that names an ssh-family verb and whose operands look like this host. Lines that reach no host (echo * s* [rs]*, ls *, cp * /backup/) stay allowed. Documented residual, unchanged from main: brace/extglob program words ({scp,ssh} x localhost).
  • Evidence checked (which sandbox result proves it): two blind read-only security reviews of the diff probed _is_ssh_to_self directly under seeds 0, 1, 2, 5 for s??, s*, *, [rs]*, s[cs]?, sudo, env, xargs, RSYNC_RSH, -e, proxycommand and cp shapes: same verdict every seed, all refused; remote-host and data-glob lines allowed. A frame-count probe on this head: 3 frames for 4..24 globs on both nested shapes.
  • No regression:
    • Tools still work (which tools/commands were run, result): black, isort, flake8, mypy on the touched files: clean. argv_floor_ssh.py is 1,460 lines, under the 2,000-line cap.
    • Backward compatible (old config / old data / old callers still work, how checked): literal program names (ssh, /usr/bin/scp, ssh.exe) still resolve to one verb, the same as before; _ssh_family_verb keeps its signature. No config or data format is touched.
    • Existing tests (which suites passed on this head): CI runs the suite on this head; this host runs no local tests.
  • How to undo: revert the two commits of this PR; the seed-dependent glob reading returns.

@github-actions

github-actions Bot commented Oct 29, 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_hosts.py

  • src/kiro_crew/security/argv_floor_ssh.py

  • @CrysisDeu comment (14 comments checked, none complete): does not name the current head 0f2ca4f; post it again for this head

How to clear this check:

  1. The PR author posts the template below as a PR comment, with
    every field filled (N/A needs a reason). Keep the
    Head commit line: it must name the current head SHA.
  2. The check turns green within a minute, with no push.
  3. A new push resets this check: post it again for the new head.

Only the author's comment counts this way. A reviewer can instead
paste the filled template into an "Approve" review on this head.
Merging still needs a reviewer's approval.

## Sensitive change review
- Head commit: 0f2ca4f324df4c92927cb06220f9f7124edb1e41
- What rule changed:
- Before -> after (what was allowed/blocked, now):
- Worst case if wrong (breaks commands / leaks secret / locks user out):
- Evidence checked (which sandbox result proves it):
- No regression:
  - Tools still work (which tools/commands were run, result):
  - Backward compatible (old config / old data / old callers still work, how checked):
  - Existing tests (which suites passed on this head):
- How to undo:

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

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 0f2ca4f324df4c92927cb06220f9f7124edb1e41 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 29, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS (a BLOCK with no Trigger and no Outcome does not block)

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

Design-Verdict: PASS

The description says no ) word is skipped, and that a case-context tracker was tried and dropped after blind reviews found bypasses. The diff ships a case-context tracker that skips case-pattern ) words, and tests that pin case lines as allowed.

Blockers

The description and the diff disagree on the core design of the floor.

  • Description: "A case-context tracker and a 'glob ) words name no program' rule were both tried, and blind reviews found bypasses in both… So no ) word is skipped". Its "Safe-side cost (refused on this PR)" list includes case "$1" in *) cp * /backup/ ;; esac.
  • Diff: _frame_verb_choices adds case_depth/case_stage/pattern_next tracking. It also adds elif case_depth and pattern_next and bare.endswith(")"): … yield i, token, None, which treats a case-pattern word as no verb at all. test_a_case_pattern_is_not_a_program asserts those same cp/ls/tar case lines are now None (allowed).

Trigger: an approver signs off on this sandbox-escape floor using the description's account: every ')' word is judged, and the tracker was rejected as bypassable.
Outcome: the merged code runs the tracker anyway, so a word the tracker misreads as a pattern skips the ssh verb check. One likely case is a quoted ';;' token inside a case arm followed by a single-token '$(which\ ssh)'. The bypass review the description cites covered a different design, so this tracker ships with no review.

Fix: pick one design. Either remove the tracker so the code matches the description and its safe-side cost list, or rewrite the ) section and the safe-side cost list for the tracker. A rewrite must explain why this tracker closes the bypasses the earlier reviews found, and must cover quoted or escaped ;;/esac words inside an arm.

Clears when: the description's ')' section, the safe-side cost list and _frame_verb_choices describe the same behaviour, and a blind review has covered the tracker that actually ships (or the tracker is removed).

Notes

  • Three per-call memo ContextVars sit in two modules, opened by one decorator. One call-scoped context object would be easier to keep consistent than three separate set/reset pairs.

[DESIGN-REVIEWED] 0f2ca4f

Description read

[DESCRIPTION-READ] 7a91925d3deb2a4baad410175de805579b104981e592fc6fa4010a0bce1232cb

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 29, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🔴 BLOCK

Premise-level review of 0f2ca4f324df4c92927cb06220f9f7124edb1e41 — 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: BLOCK

The description says no ) word is skipped and that case lines are refused. The diff ships a case-pattern tracker that skips them and tests that those lines are allowed. A reader of the description does not learn the floor got this allow path.

Notes

  • Item 9 — inherited: _unmask_separators's early return is a perf rider. Neither the description nor the cost table measures it. Subtraction: delete the _SEP_SENTINEL_RE guard and its manifest line.

What this change ships

Inventory (10 items) — 7 justified

Intent: make the ssh-to-self floor give the same seed-independent verdict for a glob program word, refusing if any verb it can name reaches this host. FIX.

  1. A glob program word is judged as every ssh-family verb it can name — justified
  2. The single-verb answer is the first in sorted order — justified
  3. A copied multi-verb glob binary carries every verb — justified
  4. A ) word after case … in or ;; is skipped as a program — undeclared, rides along, contradicts description
  5. case … *) cp * … arm lines are now allowed — undeclared; description lists them as refused
  6. Nested payload verdicts are shared within one outer call — justified
  7. Operand verdicts are memoized within one outer call — justified
  8. Hosts-file verdicts are memoized within one outer call — justified
  9. Separator unmasking returns early when no marker is present — rides along, unmeasured
  10. Package line budget goes up by 129 (34,523 → 34,652); description says 108 (33,172 → 33,280) — justified

Blockers

The case-pattern skip contradicts the description — framing contradicted by diff
Trigger: the description says "A case-context tracker … blind reviews found bypasses … So no ) word is skipped" and lists case "$1" in *) cp * /backup/ ;; esac under "refused on this PR". The diff adds case_depth/case_stage/pattern_next and yield i, token, None for case patterns, and test_a_case_pattern_is_not_a_program asserts that exact line is allowed.
Outcome: a deny floor ships an allow path that the description says was rejected for bypasses. "The change only adds refusals" is no longer shown to be true, and nobody evaluated the tracker as described.
Subtraction: delete the case tracker from _frame_verb_choices along with test_a_case_pattern_is_not_a_program.
Clears when: the case tracker is removed, or the description's ) section, safe-side list and budget figures describe the shipped skip and its review.

[FIRST-PRINCIPLES-REVIEWED] 0f2ca4f

Description read

[DESCRIPTION-READ] 5d46fe6380e4059e628bb12af4c1fc838908e46ba33e3b130be3d6ad30d1f34c

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 29, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 0f2ca4f324df4c92927cb06220f9f7124edb1e41 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 0f2ca4f

Verdict parsed from the review's SHA-scoped output markers for commit 0f2ca4f324df4c92927cb06220f9f7124edb1e41.

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

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — 🔴 changes requested (blocking)

GPT 6.1 found at least one blocking issue that must be resolved before merging 0f2ca4f324df4c92927cb06220f9f7124edb1e41. 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/security/argv_floor_ssh.py:635 -- Nested case state skips an executable copied SSH client

elif case_depth and bare.startswith("esac"):
case_depth -= 1
Trigger: Submit ln -s /usr/bin/ssh /tmp/q\); case x in x) :; case y in y) : ;; esac; /tmp/q\) localhost ;; esac. The tool gate reaches is_denied → _is_ssh_to_self → _frame_verb_choices; the inner ;; sets pattern_next=True, which survives esac;, causing /tmp/q) to be skipped as a pattern.
Outcome: This valid shell command is denied on base but returns no denial on HEAD, permitting the copied client to connect to the local unsandboxed sshd.
Anchor: residual/security
Fix: Clear the pending inner-pattern state when consuming esac, restoring the enclosing arm’s command state.
Sites: The same skip affects copied scp, sftp, and rsync clients with executable names ending in ), through the shared cp/mv/ln/install binding path.

[BLOCK-MERGE] 0f2ca4f
[GPT-REVIEWED] 0f2ca4f

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F1 (fenced): UPHOLD-FENCED. The defect is real and the input that triggers it is ordinary shell text the agent could write.

  • At src/kiro_crew/security/argv_floor_ssh.py:640, the inner ;; sets pattern_next=True. The esac branch at :635-636 only decrements case_depth and leaves pattern_next set. The next token, /tmp/q), ends in ) and case_depth is still 1, so :629-633 treats it as a case pattern and yields None. That skips the copied-ssh binding lookup at :644-650.

  • Nothing in this function catches it afterwards. Reaching it takes only a crafted command, no unusual timing or legacy artifacts, which is exactly what a prompt-injected agent can emit. The rarity argument a FLAG needs does not hold.

    [ADJUDICATION] 0f2ca4f total=0 uphold=0 downgrade=0
    [GPT-ADJUDICATED] 0f2ca4f

    [ADJUDICATION-FENCED] 0f2ca4f fenced=1 flagged=0
    UPHOLD-FENCED F1 src/kiro_crew/security/argv_floor_ssh.py:635 -- The esac branch leaves pattern_next set from the inner ;; so a following )-suffixed copied ssh client is skipped as a pattern, and the trigger is a plain crafted command an injected agent can emit, not an extreme condition combination.
    [GPT-ADJUDICATED-FENCED] 0f2ca4f

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 0f2ca4f324df4c92927cb06220f9f7124edb1e41 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 29, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/ssh-glob-verb-order-25848 branch from 6550249 to aecb389 Compare October 29, 2026 23:39
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: aecb389
  • What rule changed: the ssh-to-self sandbox-escape floor in src/kiro_crew/security/argv_floor_ssh.py: _ssh_family_verb / new _ssh_family_verbs and _frame_verb_choices (how a glob program word maps to ssh/scp/sftp/rsync), and _is_ssh_to_self (new per-call memo of nested payload verdicts, _SSH_SELF_VERDICTS).
  • Before -> after (what was allowed/blocked, now): before, a glob program word that names several verbs (s??, *) was read as whichever verb a frozenset gave first, so /usr/bin/s?? x localhost was refused under PYTHONHASHSEED 0,1,3,4 and allowed under 2,5. Now it is judged as every verb it can name and refused under every seed. A 3-level proxycommand line with 24 globs: 64 s / 5,403 frames before the memo, 0.2 s / 3 frames now (main: 2 s / 651 frames).
  • Worst case if wrong (breaks commands / leaks secret / locks user out): false refusal of a command whose program word is a glob that names an ssh-family verb and whose operands look like this host. Lines that reach no host (echo * s* [rs]*, ls *, cp * /backup/) stay allowed. Documented residual, unchanged from main: brace/extglob program words ({scp,ssh} x localhost).
  • Evidence checked (which sandbox result proves it): two blind read-only security reviews of the diff probed _is_ssh_to_self directly under seeds 0, 1, 2, 5 for s??, s*, *, [rs]*, s[cs]?, sudo, env, xargs, RSYNC_RSH, -e, proxycommand and cp shapes: same verdict every seed, all refused; remote-host and data-glob lines allowed. A frame-count probe on this head: 3 frames for 4..24 globs on both nested shapes.
  • No regression:
    • Tools still work (which tools/commands were run, result): black, isort, flake8, mypy on the touched files: clean. argv_floor_ssh.py is 1,460 lines, under the 2,000-line cap.
    • Backward compatible (old config / old data / old callers still work, how checked): literal program names (ssh, /usr/bin/scp, ssh.exe) still resolve to one verb, the same as before; _ssh_family_verb keeps its signature. No config or data format is touched.
    • Existing tests (which suites passed on this head): CI runs the suite on this head; this host runs no local tests.
  • How to undo: revert the two commits of this PR; the seed-dependent glob reading returns.

@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 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- 🔴 BLOCK (blocking)

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

Verdict basis: a script-confirmed newly-refused operation.

Security scope review -- adjudicated candidates

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

Newly refused (confirmed by the real classifier at both refs)

  • case "$mode" in build) make ;; *) ls -la * ;; esac (posix, leg macos-latest)
    • Who loses it: An agent writes a mode dispatch inline when it scripts a build-or-inspect step; the catch-all arm listing the working directory is the most common case fallback.
    • Refused by: deny-rules -- Blocked by security policy: (?:\A|[;&|\n]|\$\()[\s"'(]*(?:[\w.:/\\-]*[/\\])?(?:ssh|scp|sftp|rsync)(?:\.exe)?\s+(?:\S*@)?(?:localhost|127\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[?::1\]?|\$\(\s*hostname|\s*hostname|${?hostname}?)(?=[\s:'");&|#]|\Z)
      Matched structurally on the command's argv, not by the pat

Each row above is an operation that the base ref ALLOWS and this change REFUSES. Narrow the rule at the tier named. Withdrawing a row is not the way to green: that is its own pull request, on its own merits.

Scope-Verdict: PASS

Reason: The harness returned no confirmed regressions for this run, so nothing here was script-confirmed. One narrowing is argued but not confirmed: the PR's own tests now expect sandbox-escape-ssh-self to refuse ordinary case arms like case "$1" in *) cp * /backup/ ;; esac and case "$mode" in clean) rm -f *.o ;; *) tar czf out.tgz * ;; esac. In those, a catch-all *) arm is read as every ssh-family verb, and then a glob operand * is read as a host that could be this machine. I submitted nearby case-arm rows so the classifier can say whether that refusal is new at head or was already hash-seed-dependent at base.

TIGHTENING: ssh-to-self argv floor, how a glob is resolved when it sits where a program name goes -- it now refuses a glob program word that can name several ssh-family verbs, judging it as each of them instead of whichever one the hash seed happened to give first. The hunk: return tuple(verb for verb in _SSH_FAMILY_VERBS_ORDERED if fnmatch.fnmatchcase(verb, base) ...) in _ssh_family_verbs, walked per verb by for i, token, verb in _frame_verb_choices(tokens, bound_program_verbs): in _is_ssh_to_self. Example: /usr/bin/s?? x localhost read as scp. The new _shares_nested_verdicts / _OPERAND_VERDICTS / _HOSTS_FILE_VERDICTS caches only memoize answers within one call and should not change any verdict.

ADJUDICATED: 30 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: posix (23 rows): case arms with *) and with /*), the case shapes taken from cli.sh and dev-backend.sh, glob operands under for/tar/rm/ls/find/cp, $(which …) and ( … ) program frames, path-qualified /usr/bin/ssh, and remote rsync/scp/sftp. Two of those rows have a nested -e / ProxyCommand payload, which goes through the new shared-verdict cache. windows (7 rows): ssh.exe / scp.exe bare and by full C:\Windows\System32\OpenSSH\ path, .\dist\*.zip glob operands with \ separators, and PowerShell/cmd glob operands (Copy-Item *.log, $env:USERPROFILE\.ssh\*.pub, dir *.log). Together these cover the one platform assumption the diff makes, the .exe suffix matched next to the bare verb (fnmatch.fnmatchcase(verb + ".exe", base)). No any rows were written, because every row carries a path, separator or executable name. One gap: no row puts a Windows glob in program position (for example s??.exe used as a real program). Every legitimate command I could think of in that shape is the attack shape itself, so I left it out on purpose.

UNADJUDICATED: The new memo _HOSTS_FILE_VERDICTS in _host_is_self, reached through _is_ssh_to_self → _operand_targets_self → _judge_operand → _host_is_self, keeps a hosts-file verdict for the length of one outer call. That includes a "pending" True from a large hosts file that is still warming in the background, so every operand in the same call reuses it. A shell row can't drive a hosts-file state that is still warming, so no verdict is possible here. The inputs I would have submitted: a single rsync line with several dotless internal host operands (rsync -a buildbox:/a buildbox:/b ./out/), run while a hosts file over 64 KiB is still warming. This only repeats a refusal the base already gave on the first operand, so I'm naming it, not blocking on it.

[SCOPE-REVIEWED] 6d613dd

The confirmed rows, in the committed corpus's own shape
{
  "golden_paths": [
    {
      "kind": "shell",
      "command_or_flow": "case \"$mode\" in build) make ;; *) ls -la * ;; esac",
      "platform": "posix",
      "reason": "An agent writes a mode dispatch inline when it scripts a build-or-inspect step; the catch-all arm listing the working directory is the most common case fallback."
    }
  ]
}

@CrysisDeu
CrysisDeu force-pushed the fix/ssh-glob-verb-order-25848 branch from aecb389 to 1b7bbc9 Compare October 30, 2026 00:39
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 1b7bbc9
  • What rule changed: the ssh-to-self sandbox-escape floor in src/kiro_crew/security/argv_floor_ssh.py: _ssh_family_verb / new _ssh_family_verbs and _frame_verb_choices (how a glob program word maps to ssh/scp/sftp/rsync), and _is_ssh_to_self (new per-call memo of nested payload verdicts, _SSH_SELF_VERDICTS).
  • Before -> after (what was allowed/blocked, now): before, a glob program word that names several verbs (s??, *) was read as whichever verb a frozenset gave first, so /usr/bin/s?? x localhost was refused under PYTHONHASHSEED 0,1,3,4 and allowed under 2,5. Now it is judged as every verb it can name and refused under every seed. A 3-level proxycommand line with 24 globs: 64 s / 5,403 frames before the memo, 0.2 s / 3 frames now (main: 2 s / 651 frames).
  • Worst case if wrong (breaks commands / leaks secret / locks user out): false refusal of a command whose program word is a glob that names an ssh-family verb and whose operands look like this host. Lines that reach no host (echo * s* [rs]*, ls *, cp * /backup/) stay allowed. Documented residual, unchanged from main: brace/extglob program words ({scp,ssh} x localhost).
  • Evidence checked (which sandbox result proves it): two blind read-only security reviews of the diff probed _is_ssh_to_self directly under seeds 0, 1, 2, 5 for s??, s*, *, [rs]*, s[cs]?, sudo, env, xargs, RSYNC_RSH, -e, proxycommand and cp shapes: same verdict every seed, all refused; remote-host and data-glob lines allowed. A frame-count probe on this head: 3 frames for 4..24 globs on both nested shapes.
  • No regression:
    • Tools still work (which tools/commands were run, result): black, isort, flake8, mypy on the touched files: clean. The security package budget in test/test_security_gate_liveness.py is raised by 60 lines (32,909 -> 32,969) with a note naming what was added; the five new owner names are in the argv_floor.py manifest.
    • Backward compatible (old config / old data / old callers still work, how checked): literal program names (ssh, /usr/bin/scp, ssh.exe) still resolve to one verb, the same as before; _ssh_family_verb keeps its signature. No config or data format is touched.
    • Existing tests (which suites passed on this head): CI runs the suite on this head; this host runs no local tests.
  • How to undo: revert the two commits of this PR; the seed-dependent glob reading returns.

@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 30, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/ssh-glob-verb-order-25848 branch from 1b7bbc9 to c323eec Compare October 30, 2026 01:55
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: c323eec
  • What rule changed: the ssh-to-self sandbox-escape floor in src/kiro_crew/security/argv_floor_ssh.py: _ssh_family_verb / new _ssh_family_verbs and _frame_verb_choices (how a glob program word maps to ssh/scp/sftp/rsync), and _is_ssh_to_self (new per-call memo of nested payload verdicts, _SSH_SELF_VERDICTS).
  • Before -> after (what was allowed/blocked, now): before, a glob program word that names several verbs (s??, *) was read as whichever verb a frozenset gave first, so /usr/bin/s?? x localhost was refused under PYTHONHASHSEED 0,1,3,4 and allowed under 2,5. Now it is judged as every verb it can name and refused under every seed. A 3-level proxycommand line with 24 globs: 64 s / 5,403 frames before the memo, 0.2 s / 3 frames now (main: 2 s / 651 frames).
  • Worst case if wrong (breaks commands / leaks secret / locks user out): false refusal of a command whose program word is a glob that names an ssh-family verb and whose operands look like this host. Lines that reach no host (echo * s* [rs]*, ls *, cp * /backup/) stay allowed. Documented residual, unchanged from main: brace/extglob program words ({scp,ssh} x localhost).
  • Evidence checked (which sandbox result proves it): two blind read-only security reviews of the diff probed _is_ssh_to_self directly under seeds 0, 1, 2, 5 for s??, s*, *, [rs]*, s[cs]?, sudo, env, xargs, RSYNC_RSH, -e, proxycommand and cp shapes: same verdict every seed, all refused; remote-host and data-glob lines allowed. A frame-count probe on this head: 3 frames for 4..24 globs on both nested shapes.
  • No regression:
    • Tools still work (which tools/commands were run, result): black, isort, flake8, mypy on the touched files: clean. The security package budget in test/test_security_gate_liveness.py is raised by 60 lines (32,909 -> 32,969) with a note naming what was added; the five new owner names are in the argv_floor.py manifest.
    • Backward compatible (old config / old data / old callers still work, how checked): literal program names (ssh, /usr/bin/scp, ssh.exe) still resolve to one verb, the same as before; _ssh_family_verb keeps its signature. No config or data format is touched.
    • Existing tests (which suites passed on this head): CI runs the suite on this head; this host runs no local tests.
  • How to undo: revert the two commits of this PR; the seed-dependent glob reading returns.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 30, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/ssh-glob-verb-order-25848 branch from c323eec to 3407013 Compare October 30, 2026 03:27
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 04d1bff
  • What rule changed: the ssh-to-self sandbox-escape floor in src/kiro_crew/security/argv_floor_ssh.py. _ssh_family_verbs and _frame_verb_choices judge a glob program word as every ssh/scp/sftp/rsync verb it can name, in sorted order, and a word ending in ) is judged like any other word (no case-pattern skip). _is_ssh_to_self keeps nested-payload, operand and hosts-file verdicts for one outer call (_SSH_SELF_VERDICTS, _OPERAND_VERDICTS, _HOSTS_FILE_VERDICTS in argv_floor_hosts.py), opened at entry and reset in finally. _unmask_separators returns early when no marker is present. argv_floor.py lists the new owner names. Rebased onto main af11620cf0; the package line budget is 33,631.
  • Before -> after (what was allowed/blocked, now): before, /usr/bin/s?? x localhost and * stash * were refused or allowed depending on PYTHONHASHSEED. Now they are refused under every seed. $(which ssh) localhost, (xargs ssh) <<< localhost, (ssh localhost), (s?h) -o proxycommand='ssh localhost' far and $(which r*) -e ssh x localhost:/y are refused, as on main. Newly refused, on the safe side: case $x in ssh) ssh localhost;; esac, and three *) case arms with a later glob operand (e.g. case "$1" in *) cp * /backup/ ;; esac), whose verdict on main depends on the hash seed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): false refusal of a command whose program word (or case pattern) is a glob naming an ssh-family verb and whose operands could expand to this host. Availability: an 18 KB line of glob words takes 28.6 s, against 14.0 s on main, with the same verdict.
  • Evidence checked (which sandbox result proves it): blind read-only review of this head against main 81dde23e17. Direct is_denied calls, fresh process per named verdict, PYTHONHASHSEED 0 and 2: 0 main-denied commands become allowed over about 16,000 inputs; 1,081 newly refused, 1,077 of them naming localhost/::1/127.0.0.1 and 4 in the accepted case-line cost. With the memos disabled, 0 of 15,969 verdicts differ. All three memos read None after allowed, refused and raising calls, and across 8 threads.
  • No regression:
    • Tools still work (which tools/commands were run, result): black, isort, flake8 and mypy on the touched files: clean.
    • Backward compatible (old config / old data / old callers still work, how checked): literal program names (ssh, /usr/bin/scp, ssh.exe) still resolve to one verb; _ssh_family_verb keeps its signature. No config or data format is touched.
    • Existing tests (which suites passed on this head): CI runs the suite on this head; this host runs no local tests.
  • How to undo: revert the two commits of this PR; the seed-dependent glob reading returns.
  • Since 28f078d: rebased onto current main af11620. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,631); the security code's changed lines are byte-identical.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Oct 31, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Security Scope Review on 04d1bff: the four newly refused rows (*) case arms with a later bare * operand: tar, cp, ls, prettier) are the accepted safe-side cost already listed in the description. Checked with scripts/deny_diff.py, main af11620 vs 04d1bff, fresh process per ref, PYTHONHASHSEED 0 and 2: all four are allowed on main and refused here; 0 commands main refuses become allowed.

New since the last head: the lane now confirms them on the Ubuntu leg as well as macOS, and the prettier row is a new spelling of the same shape. The description's "Safe-side cost" list is updated. The narrowing the lane suggests (skip a )-terminated pattern word inside a case frame) is the case tracker a blind review found a Critical in, so it is not taken here; the security owner decides.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 31, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/ssh-glob-verb-order-25848 branch from 04d1bff to 41ec128 Compare November 1, 2026 05:13
@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 1, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 41ec128
  • What rule changed: the ssh-to-self sandbox-escape floor in src/kiro_crew/security/argv_floor_ssh.py. _ssh_family_verbs and _frame_verb_choices judge a glob program word as every ssh/scp/sftp/rsync verb it can name, in sorted order, and a word ending in ) is judged like any other word (no case-pattern skip). _is_ssh_to_self keeps nested-payload, operand and hosts-file verdicts for one outer call (_SSH_SELF_VERDICTS, _OPERAND_VERDICTS, _HOSTS_FILE_VERDICTS in argv_floor_hosts.py), opened at entry and reset in finally. _unmask_separators returns early when no marker is present. argv_floor.py lists the new owner names. Rebased onto main af11620cf0; the package line budget is 33,831.
  • Before -> after (what was allowed/blocked, now): before, /usr/bin/s?? x localhost and * stash * were refused or allowed depending on PYTHONHASHSEED. Now they are refused under every seed. $(which ssh) localhost, (xargs ssh) <<< localhost, (ssh localhost), (s?h) -o proxycommand='ssh localhost' far and $(which r*) -e ssh x localhost:/y are refused, as on main. Newly refused, on the safe side: case $x in ssh) ssh localhost;; esac, and three *) case arms with a later glob operand (e.g. case "$1" in *) cp * /backup/ ;; esac), whose verdict on main depends on the hash seed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): false refusal of a command whose program word (or case pattern) is a glob naming an ssh-family verb and whose operands could expand to this host. Availability: an 18 KB line of glob words takes 28.6 s, against 14.0 s on main, with the same verdict.
  • Evidence checked (which sandbox result proves it): blind read-only review of this head against main 81dde23e17. Direct is_denied calls, fresh process per named verdict, PYTHONHASHSEED 0 and 2: 0 main-denied commands become allowed over about 16,000 inputs; 1,081 newly refused, 1,077 of them naming localhost/::1/127.0.0.1 and 4 in the accepted case-line cost. With the memos disabled, 0 of 15,969 verdicts differ. All three memos read None after allowed, refused and raising calls, and across 8 threads.
  • No regression:
    • Tools still work (which tools/commands were run, result): black, isort, flake8 and mypy on the touched files: clean.
    • Backward compatible (old config / old data / old callers still work, how checked): literal program names (ssh, /usr/bin/scp, ssh.exe) still resolve to one verb; _ssh_family_verb keeps its signature. No config or data format is touched.
    • Existing tests (which suites passed on this head): CI runs the suite on this head; this host runs no local tests.
  • How to undo: revert the two commits of this PR; the seed-dependent glob reading returns.
  • Since 28f078d: rebased onto current main af11620. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,631); the security code's changed lines are byte-identical.
  • Since 04d1bff: rebased onto current main 934f7a8. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,831); the security code's changed lines are byte-identical.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 1, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Security Scope Review on 41ec128: the four confirmed rows (*) case arms with a later bare *, including the new Windows-leg bash -c 'case "$1" in *) ls -la * ;; esac') are the accepted safe-side cost. Checked with scripts/deny_diff.py, main 934f7a8 vs 41ec128, fresh process per ref, PYTHONHASHSEED 0 and 2 (the Windows row classified with --platform windows on Linux): all four allowed on main and refused here; 0 commands main refuses become allowed. The new row is added to the description's "Safe-side cost" list.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 3, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/ssh-glob-verb-order-25848 branch from 41ec128 to 203f587 Compare November 4, 2026 17:14
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 203f587

  • What rule changed: the ssh-to-self sandbox-escape floor in src/kiro_crew/security/argv_floor_ssh.py. _ssh_family_verbs and _frame_verb_choices judge a glob program word as every ssh/scp/sftp/rsync verb it can name, in sorted order, and a word ending in ) is judged like any other word (no case-pattern skip). _is_ssh_to_self keeps nested-payload, operand and hosts-file verdicts for one outer call (_SSH_SELF_VERDICTS, _OPERAND_VERDICTS, _HOSTS_FILE_VERDICTS in argv_floor_hosts.py), opened at entry and reset in finally. _unmask_separators returns early when no marker is present. argv_floor.py lists the new owner names. Rebased onto main af11620cf0; the package line budget is 33,831.

  • Before -> after (what was allowed/blocked, now): before, /usr/bin/s?? x localhost and * stash * were refused or allowed depending on PYTHONHASHSEED. Now they are refused under every seed. $(which ssh) localhost, (xargs ssh) <<< localhost, (ssh localhost), (s?h) -o proxycommand='ssh localhost' far and $(which r*) -e ssh x localhost:/y are refused, as on main. Newly refused, on the safe side: case $x in ssh) ssh localhost;; esac, and three *) case arms with a later glob operand (e.g. case "$1" in *) cp * /backup/ ;; esac), whose verdict on main depends on the hash seed.

  • Worst case if wrong (breaks commands / leaks secret / locks user out): false refusal of a command whose program word (or case pattern) is a glob naming an ssh-family verb and whose operands could expand to this host. Availability: an 18 KB line of glob words takes 28.6 s, against 14.0 s on main, with the same verdict.

  • Evidence checked (which sandbox result proves it): blind read-only review of this head against main 81dde23e17. Direct is_denied calls, fresh process per named verdict, PYTHONHASHSEED 0 and 2: 0 main-denied commands become allowed over about 16,000 inputs; 1,081 newly refused, 1,077 of them naming localhost/::1/127.0.0.1 and 4 in the accepted case-line cost. With the memos disabled, 0 of 15,969 verdicts differ. All three memos read None after allowed, refused and raising calls, and across 8 threads.

  • No regression:

    • Tools still work (which tools/commands were run, result): black, isort, flake8 and mypy on the touched files: clean.
    • Backward compatible (old config / old data / old callers still work, how checked): literal program names (ssh, /usr/bin/scp, ssh.exe) still resolve to one verb; _ssh_family_verb keeps its signature. No config or data format is touched.
    • Existing tests (which suites passed on this head): CI runs the suite on this head; this host runs no local tests.
  • How to undo: revert the two commits of this PR; the seed-dependent glob reading returns.

  • Since 28f078d: rebased onto current main af11620. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,631); the security code's changed lines are byte-identical.

  • Since 04d1bff: rebased onto current main 934f7a8. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,831); the security code's changed lines are byte-identical.

  • Since 41ec128: rebased onto current main df8598d, which raised the package line budget to 34,352. The only conflict was that budget in test/test_security_gate_liveness.py; it is now 34,460 (main's 34,352 plus this PR's 108). The security code's changed lines are byte-identical to the previous head.

@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 4, 2026
A glob program word such as s?? or * can expand to more than one
ssh-family verb. _ssh_family_verb looped over a frozenset and took the
first match, so the verb, and with it the verdict, followed
PYTHONHASHSEED: /usr/bin/s?? x localhost was refused under some seeds
(read as scp, which checks every operand) and allowed under others
(read as ssh, which checks only the first).

The operand walk now visits such a token once per verb it can name, in
sorted order, and refuses if any reading reaches this host. The choice
is local to the token, so the cost grows linearly and no line-wide
combination cap is needed. A cp/mv/ln copy of a multi-verb glob binds
its destination to the whole verb tuple.
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 07f68f5

  • What rule changed: the ssh-to-self sandbox-escape floor in src/kiro_crew/security/argv_floor_ssh.py. _ssh_family_verbs and _frame_verb_choices judge a glob program word as every ssh/scp/sftp/rsync verb it can name, in sorted order, and a word ending in ) is judged like any other word (no case-pattern skip). _is_ssh_to_self keeps nested-payload, operand and hosts-file verdicts for one outer call (_SSH_SELF_VERDICTS, _OPERAND_VERDICTS, _HOSTS_FILE_VERDICTS in argv_floor_hosts.py), opened at entry and reset in finally. _unmask_separators returns early when no marker is present. argv_floor.py lists the new owner names. Rebased onto main af11620cf0; the package line budget is 33,831.

  • Before -> after (what was allowed/blocked, now): before, /usr/bin/s?? x localhost and * stash * were refused or allowed depending on PYTHONHASHSEED. Now they are refused under every seed. $(which ssh) localhost, (xargs ssh) <<< localhost, (ssh localhost), (s?h) -o proxycommand='ssh localhost' far and $(which r*) -e ssh x localhost:/y are refused, as on main. Newly refused, on the safe side: case $x in ssh) ssh localhost;; esac, and three *) case arms with a later glob operand (e.g. case "$1" in *) cp * /backup/ ;; esac), whose verdict on main depends on the hash seed.

  • Worst case if wrong (breaks commands / leaks secret / locks user out): false refusal of a command whose program word (or case pattern) is a glob naming an ssh-family verb and whose operands could expand to this host. Availability: an 18 KB line of glob words takes 28.6 s, against 14.0 s on main, with the same verdict.

  • Evidence checked (which sandbox result proves it): blind read-only review of this head against main 81dde23e17. Direct is_denied calls, fresh process per named verdict, PYTHONHASHSEED 0 and 2: 0 main-denied commands become allowed over about 16,000 inputs; 1,081 newly refused, 1,077 of them naming localhost/::1/127.0.0.1 and 4 in the accepted case-line cost. With the memos disabled, 0 of 15,969 verdicts differ. All three memos read None after allowed, refused and raising calls, and across 8 threads.

  • No regression:

    • Tools still work (which tools/commands were run, result): black, isort, flake8 and mypy on the touched files: clean.
    • Backward compatible (old config / old data / old callers still work, how checked): literal program names (ssh, /usr/bin/scp, ssh.exe) still resolve to one verb; _ssh_family_verb keeps its signature. No config or data format is touched.
    • Existing tests (which suites passed on this head): CI runs the suite on this head; this host runs no local tests.
  • How to undo: revert the two commits of this PR; the seed-dependent glob reading returns.

  • Since 28f078d: rebased onto current main af11620. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,631); the security code's changed lines are byte-identical.

  • Since 04d1bff: rebased onto current main 934f7a8. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,831); the security code's changed lines are byte-identical.

  • Since 203f587: rebased onto current main cff1384, which raised the package line budget to 34,523. The only conflict was that budget in test/test_security_gate_liveness.py; it is now 34,626 (main's 34,523 plus this PR's 103, measured). The security code's changed lines are byte-identical to the previous head.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 6d613dd

  • What rule changed: the ssh-to-self sandbox-escape floor in src/kiro_crew/security/argv_floor_ssh.py. _ssh_family_verbs and _frame_verb_choices judge a glob program word as every ssh/scp/sftp/rsync verb it can name, in sorted order, and a word ending in ) is judged like any other word (no case-pattern skip). _is_ssh_to_self keeps nested-payload, operand and hosts-file verdicts for one outer call (_SSH_SELF_VERDICTS, _OPERAND_VERDICTS, _HOSTS_FILE_VERDICTS in argv_floor_hosts.py), opened at entry and reset in finally. _unmask_separators returns early when no marker is present. argv_floor.py lists the new owner names. Rebased onto main af11620cf0; the package line budget is 33,831.

  • Before -> after (what was allowed/blocked, now): before, /usr/bin/s?? x localhost and * stash * were refused or allowed depending on PYTHONHASHSEED. Now they are refused under every seed. $(which ssh) localhost, (xargs ssh) <<< localhost, (ssh localhost), (s?h) -o proxycommand='ssh localhost' far and $(which r*) -e ssh x localhost:/y are refused, as on main. Newly refused, on the safe side: case $x in ssh) ssh localhost;; esac, and three *) case arms with a later glob operand (e.g. case "$1" in *) cp * /backup/ ;; esac), whose verdict on main depends on the hash seed.

  • Worst case if wrong (breaks commands / leaks secret / locks user out): false refusal of a command whose program word (or case pattern) is a glob naming an ssh-family verb and whose operands could expand to this host. Availability: an 18 KB line of glob words takes 28.6 s, against 14.0 s on main, with the same verdict.

  • Evidence checked (which sandbox result proves it): blind read-only review of this head against main 81dde23e17. Direct is_denied calls, fresh process per named verdict, PYTHONHASHSEED 0 and 2: 0 main-denied commands become allowed over about 16,000 inputs; 1,081 newly refused, 1,077 of them naming localhost/::1/127.0.0.1 and 4 in the accepted case-line cost. With the memos disabled, 0 of 15,969 verdicts differ. All three memos read None after allowed, refused and raising calls, and across 8 threads.

  • No regression:

    • Tools still work (which tools/commands were run, result): black, isort, flake8 and mypy on the touched files: clean.
    • Backward compatible (old config / old data / old callers still work, how checked): literal program names (ssh, /usr/bin/scp, ssh.exe) still resolve to one verb; _ssh_family_verb keeps its signature. No config or data format is touched.
    • Existing tests (which suites passed on this head): CI runs the suite on this head; this host runs no local tests.
  • How to undo: revert the two commits of this PR; the seed-dependent glob reading returns.

  • Since 28f078d: rebased onto current main af11620. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,631); the security code's changed lines are byte-identical.

  • Since 04d1bff: rebased onto current main 934f7a8. The only conflict was the package line budget in test/test_security_gate_liveness.py (now 33,831); the security code's changed lines are byte-identical.

  • Since 203f587: rebased onto current main cff1384, which raised the package line budget to 34,523. The only conflict was that budget in test/test_security_gate_liveness.py; it is now 34,626 (main's 34,523 plus this PR's 103, measured). The security code's changed lines are byte-identical to the previous head. Since 07f68f5: the hash-seed test's subprocess timeout is default_timeout() instead of a literal 60 (Flake Pattern Ratchet K19); no security code changed.

Walking a glob program once per verb it can name reaches the same nested
-e / proxycommand / RSYNC_RSH value from every walk, so a three-level
proxycommand line with 24 globs took 64 s. _is_ssh_to_self now keeps the
verdicts of nested payloads, of operands and of hosts-file lookups for
the length of one outer call, so each is judged once. The same line
walks 3 frames and takes 0.2 s. Every verdict is a pure function of the
text and of state read in that call, and nothing is kept between calls.

A word ending in ")" is judged like any other word. A case pattern and
the program word of $(which r*) or (xargs s??) split the same way, so
ssh) is ssh and *) is every ssh-family verb, even as a case pattern.
@bolichen97

Copy link
Copy Markdown
Contributor

[operator: bolichen97] Continuing this in #33418; thanks for the start.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security: ssh-self floor verdict depends on hash seed when a glob names several ssh verbs

2 participants