Skip to content

fix: tighten a self-protection check on shell scripts - #32885

Merged
bolichen97 merged 1 commit into
mainfrom
fix/8544-quoted-script-frame
Nov 11, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/8544-quoted-script-frame

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A command the self-protection floor refuses when it is typed directly is refused the same way when a quoted shell script handed to a shell carries it.

Part of #8544. Builds on #13261 by @CrysisDeu.

The self-protection floor refuses an agent's attempt to run the commands that would disable its own controls. Some shell scripts that run one of those commands, which the shell runs exactly like the plain form, were allowed while the plain form was refused.

Why it matters

An agent could run a protected command the operator never approved, by putting it inside a shell script the floor did not read the way the shell does.

Not a goal

What changed (motivation → approach → change)

An agent that wraps a protected command in a shell script now gets the same refusal it gets when it types the command directly, so the wrapper no longer slips past the self-protection floor. The self-protection floor in src/kiro_crew/security reads each quoted script that opens with an assignment as a whole command of its own, its ssh self-target check included, and keeps every frame it read before, so nothing it refused before is allowed. The shared shell reader returns what it returned before, so the git-publish check and the other command rules read exactly what they read before. The security spec under docs/ describes the reading, regression rows under test/ cover it, and the package line budget in test/ is raised to the measured size.

Backwards compatibility

Compatible: a command is newly refused only when a shell script it carries, read whole, is a command the self-protection floor already refuses when typed directly; ordinary scripts stay allowed. A script that is only printed reads the way one already does: echo bash -c 'kirocrew token' is refused today, and echo bash -c 'X=kirocrew; $X token' is refused the same way.

Removes nothing: no rule, row or allowed ordinary command is removed, and every command refused on main is still refused.

Tests

Regression rows pair the newly refused scripts (bash -c, zsh -Cc, a long variable name, a pkill through a variable, an ssh to this host through a variable) with the self-protection rule that refuses their plain form; nearby ordinary scripts (one that assigns a file name, one that connects to another host) stay allowed. With the production change reversed, the five refused rows fail and the allowed rows still pass.

Proof: PROVEN 5 regression rows fail with the bug reintroduced: 4 credential-mint and kill rows and 1 ssh self-target row (head af0f35ef5df9)

Manual verification

N/A — unit coverage sufficient: the gate is a pure function of the command text, and the tests call it directly. A side-by-side run of the gate with and without the whole-script reading over 45 command shapes found no command that is refused without it and allowed with it; of the 11 it newly refuses, 10 run a protected command inside a shell script and 1 prints one, which is read as main already reads a printed script.

Related Issues

Part of #8544

Sibling sweep

Siblings: none -- both self-protection readers of a carrier's frames (the argv predicates and the ssh self-target check) are changed here; how the other command-text checks, git-publish included, read a carrier is outside this PR's goal and stays with #21682

Pattern harvest

Not generalizable: the maintainer decision on #21682 keeps this shell reader and stops adding rules for one spelling at a time, so there is no lint or review rule to add.

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

@github-actions

github-actions Bot commented Nov 8, 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_self.py

  • src/kiro_crew/security/argv_floor_ssh.py

  • src/kiro_crew/security/deny_gate.py

  • src/kiro_crew/security/shell_normalizer.py

  • @buluoray: missing the ## Sensitive change review heading

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: d42c2804201ffd125907b9002a11b20946e55c54
- 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 Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision d42c2804201ffd125907b9002a11b20946e55c54 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 8, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of d42c2804201ffd125907b9002a11b20946e55c54 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing to check.

What this change ships

Inventory (5 items) — 5 justified

Intent: a protected command wrapped in a quoted shell script that starts with an assignment is refused the same way as when it is typed directly. This is a FIX.

  1. A bash -c/zsh -c script that assigns the kirocrew name and then mints a token or kills it by name is now refused — justified
  2. A quoted script that assigns ssh and then connects to this host is now refused — justified
  3. Ordinary assignment scripts and ssh to other hosts stay allowed (pinned rows) — justified
  4. _self_tokens gains a resolve=False mode; the shared reader's default output is unchanged — justified
  5. The package line budget pin is raised by 62 lines, with the measured figure in a comment — justified

[FIRST-PRINCIPLES-REVIEWED] d42c280

Description read

[DESCRIPTION-READ] 537aaa5c2ad66728643d9f57356bee6e722f32ffe041431e5ca5c7ded4785352

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks. This reads a quoted script as a whole command line using the parser that already exists, and it refuses only commands that are already refused when typed directly. It adds no new matcher for a single spelling.

Notes

[DESIGN-REVIEWED] d42c280

Description read

[DESCRIPTION-READ] 27036e1fa5832b0c04de83040228b892c58804270418bf31bfeec93de4767bce

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 added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] d42c280

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

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

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] d42c280

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

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

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

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

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

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

Reason: No regression has been confirmed by the script; the harness gave this review no verdicts. The change widens the walk of three floors: credential mint, self-kill and ssh self-target. They now also see a carrier's quoted script that opens with an assignment, read whole. I wrote 22 rows at that edge, but none has a verdict yet.

TIGHTENING: _self_frames / _quoted_assignment_scripts in argv_floor_self.py, plus _reaches_self_over_ssh replacing _is_ssh_to_self in deny_gate.py. Before this change, the assignment resolver split a bash -c/sh -c/zsh -c/eval payload at its inner operator, so only the first statement was walked. Now the whole quoted script is walked as its own command line. The one threat it refuses is a variable-held program name invoked inside a carrier: bash -c 'X=<name>; $X <verb>' (test hunk: (f"bash -c 'X={_NAME}; $X {_TOK}'", _RULE_MINT), "bash -c 'x=ssh; $x localhost'").

ADJUDICATED: 22 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: posix (18 rows). These cover the three carriers the diff names (bash -c, sh -c, zsh -c) and eval. Each probes a case one token off an attack:

  • a variable-held CLI name running a verb other than token;
  • pkill/kill on a target that isn't the product;
  • ssh/scp/rsync to a remote host held in a variable;
  • localhost assigned but used only by curl or ping;
  • a loopback that is only the remote side of a -L forward;
  • product-named worktree paths as data.

windows (4 rows). Three cover Git Bash spelled as bash.exe, both bare and as the fully qualified C:\Program Files\Git\bin\bash.exe, with a drive-letter path. One is a cmd /c "set H=...&& ssh %H% ..." row, because the diff assumes POSIX NAME=value; assignment syntax and a bash/sh/zsh carrier. PowerShell $env:X=...; scripts under powershell -Command are not probed. The diff's _LOCAL_ASSIGN_RE/carrier detection is unlikely to read them, so they are an open question, not a covered one.

UNADJUDICATED: The adjudicated shell-command path is the whole tightening. One gap is on the threat side, not the allow side: the new walk is skipped when a payload goes through _decode_printf_escapes and the decoded script is not shorter than its source (len(script) < len(source)). Nothing here could classify that, and it is noted only for the other review lanes.

[SCOPE-REVIEWED] d42c280

@bolichen97
bolichen97 enabled auto-merge (squash) November 8, 2026 03:43
@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 8, 2026
@bolichen97
bolichen97 force-pushed the fix/8544-quoted-script-frame branch from 6476f2c to 16f79f6 Compare November 8, 2026 09:37
@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 8, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • Printed shell examples become executable frames span=5e784cc06287

fixed in 16f79f6: the extra whole-script frames are skipped when the agent's own top-level command is ONE pure printer (echo, printf, print), read quote-aware and past every heredoc; any second command, heredoc, other consumer (awk, grep) or nested frame keeps the frame, so the change stays deny-only against main.
Red/green: test_printed_quoted_script_assignment_allowed (echo bash -c 'X=<cli>; $X <verb>', printf, a quoted ;, a leading assignment) fails on 6476f2c and passes here; refused rows cover a same-command printer redefinition, a heredoc before the script, gawk @f(), and a nested printer piped to a shell.

[operator: bolichen97]

AI-assisted, posted on behalf of bolichen97

@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 8, 2026
@bolichen97

bolichen97 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Whole-script frames interpret shell comments as protected invocations span=5e784cc06287

Rebutted (maintainer ruling): not a defect against this PR's goal. Main d7a4537 already refuses the same text typed directly, X=<cli>; # $X <verb> and bash -c '# <cli> <verb>', because the shared reader keeps comment words in argv. This head refuses bash -c 'X=<cli>; # $X <verb>' the same way, which is the goal: refused the same way when a quoted script carries it.
Failing closed is the right direction for a self-protection check: the result is a visible refusal of an assignment-plus-comment script, never an allow. Dropping comment spans only in the new frames would make the quoted script read differently from the typed form; dropping them everywhere changes main's reading for every rule (parser evaluation tracked in #21682).
No override is posted; this lane's clearance stays with a maintainer.

[operator: bolichen97] Maintainer ruling: accept the comment refusal.

AI-assisted, posted on behalf of bolichen97

@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 8, 2026
@bolichen97
bolichen97 force-pushed the fix/8544-quoted-script-frame branch from 16f79f6 to 269ddc5 Compare November 10, 2026 03:50
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/security.md, src/kiro_crew/security/shell_normalizer.py, test/test_security_gate_liveness.py since this head went green (6d07df1 -> 3467dd6); CI re-running.

[operator: bolichen97]

@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: a printer exemption (one echo/printf/print command adds no whole-script frame), added in 16f79f6 for this span
resolution: removed -- the exemption read a printed assignment script differently from the same printed script without the assignment

  • Printed shell examples become executable frames span=5e784cc06287

Rebutted: not a defect against this PR's goal. Main already refuses the printed plain form, echo bash -c '<cli> token' and echo bash -c 'pkill -f <cli>', because a carrier's first-word payload is read whatever program holds it (checked on fd5d9ef).
So echo bash -c 'X=<cli>; $X token' is now refused the same way, which is the goal: refused the same way when a quoted script carries it. The printer exemption (_only_prints, top=) and its rows are removed: it allowed the assignment spelling while main refuses the plain one.
Failing closed is the direction for a self-protection check: the result is a visible refusal with a rule id, never an allow. Exempting printed scripts for every rule changes main's reading for every floor (parser evaluation tracked in #21682).

[operator: bolichen97]

@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
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge 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 10, 2026
A command the self-protection floor refuses when it is typed directly is
refused the same way when a quoted shell script passed to a shell carries
it. Commands that do not reach a protected command are unaffected.

Builds on #13261 by @CrysisDeu.
Refs #8544
@bolichen97
bolichen97 force-pushed the fix/8544-quoted-script-frame branch from 269ddc5 to d42c280 Compare November 11, 2026 07:36
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/security.md, src/kiro_crew/security/argv_floor.py, src/kiro_crew/security/argv_floor_self.py, src/kiro_crew/security/deny_gate.py, test/test_security_gate_liveness.py since this head went green (3467dd6 -> 756346d); CI re-running.

[operator: bolichen97]

@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: a two-phase shared walk (whole-script frames walked last, a plain flag per frame, a whole_scripts filter for the git-publish reader), added in 269ddc5 when rebasing onto the memoized walk
resolution: narrowed -- the whole-script reading moved out of the shared walk into the self-protection floor's own frames, so the shared walk is main's again

removed in d42c280: the two-phase walk, its plain flag and the whole_scripts filter are gone; _shell_payload_walk and _shell_payload_sources are main's again, byte for byte.
Only the self-protection floor reads a quoted script that opens with an assignment whole (_self_frames, once per gate call like the walk), and its ssh self-target check reads the same scripts as command lines of their own (_reaches_self_over_ssh).
The git-publish reader and the other command rules read exactly what they read on main, by construction instead of through a filter on a shared walk; the goal and every refusal main makes are unchanged.

[operator: bolichen97]

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

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider thinks the change is probably fine but estimates a 14% chance that this change introduces a defect, above the 12% limit for approving on its own.

The self-protection floor now reads a quoted carrier script that starts with an assignment as a whole command line, using new frames added on top of the existing ones. That closes a bypass for the mint, self-kill and ssh-self-target checks (e.g. bash -c 'X=kirocrew; $X token'). The cached shell walk gives each caller a fresh copy, so appending the extra frames cannot change what git-publish or the other checks read. The only dispatch path (deny_gate) and the ssh check's frame walk both use the new reading. The loop terminates because each added script is strictly shorter than its source and not already found. Exceptions in tokenizing are still caught. Refused and allowed regression rows are added; the PR says the five refused rows fail with the fix reverted, which I could not run. The spec and the line budget are updated. Nothing blocks.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit d42c280420 · 106 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve on d42c280. Deny-only. The self-protection floor now also reads a quoted -c script that opens with an assignment as a command line of its own, so bash -c 'X=kirocrew; $X token' gets the plain form's refusal. The shared shell walk is unchanged, so git-publish and argv rules read exactly what they read before. No new rule or regex. The branch merges cleanly with main. Decisive lines: src/kiro_crew/security/argv_floor_self.py:192 (_quoted_assignment_scripts), src/kiro_crew/security/argv_floor_self.py:218 (_self_frames, plus its use at :838 and :882), src/kiro_crew/security/argv_floor_ssh.py:935 (_reaches_self_over_ssh) wired at src/kiro_crew/security/deny_gate.py:783, src/kiro_crew/security/shell_normalizer.py:974 (_self_tokens(resolve=False)), test/test_denied_commands_security_kill.py:275, test/test_denied_commands_security_ssh_self.py:418

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 11, 2026
@bolichen97
bolichen97 merged commit f016c64 into main Nov 11, 2026
102 of 104 checks passed
@bolichen97
bolichen97 deleted the fix/8544-quoted-script-frame branch November 11, 2026 08:37
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 11, 2026
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