Skip to content

fix(security): 0.13 backport, read a double-quoted $( ) as a command in ssh floor (#37443) - #37551

Merged
bolichen97 merged 1 commit into
release/0.13.0from
crew/slack/backport-0.13.0-37443
Nov 16, 2026
Merged

bolichen97 merged 1 commit into
release/0.13.0from
crew/slack/backport-0.13.0-37443

Conversation

@buluoray

@buluoray buluoray commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Ship in 0.13 the ssh-floor fix that lets a KAS custom agent's auto-approved commands through when a double-quoted $( ) appears, part of the custom-agent auto-approve work users reported.

Backport onto release/0.13.0 (head b45ee13fbcf). One commit, made with git cherry-pick -x. It applied with no conflict; nothing was hand-resolved.

Pick Main commit What 0.13 users get
#37443 87b11b5ef245 The ssh floor reads a double-quoted $( ) as a command, as the shell does, so the floor judges the command that really runs. Brings its own line-budget row (ssh-self-dquote-subst.txt, +69), equal to its net growth of the security package.

No prerequisite is needed: #36903, the ssh-floor change it builds on, is already on release/0.13.0.

Why it matters

Users reported KAS custom agents whose auto-approved commands were refused or judged wrong. This is one of the main fixes for that work, so 0.13 should carry it.

Not a goal

  • Other security picks: they come in their own PRs.

What changed (motivation → approach → change)

Cherry-pick only. No hunk was hand-resolved and no line is new.

Backwards compatibility

Compatible. The pick behaves as it does on main, where it was reviewed. Nothing is removed.

Tests

Test changes come from the pick.

Release PRs get no backend test lanes on this branch yet, so the backend tests also ran locally on this head, one pytest process per batch of 20 files, no xdist: the 17 test files the pick touches or that import a module it changes, 2,149 passed, 0 failed. test_security_gate_liveness.py passes with the cap equal to the measured package size. flake8 and black on every Python file in the diff: clean.

Manual verification

N/A. Unit coverage above; the same change is on main.

Screenshots / video

N/A: no frontend change.

Related Issues

Backport of #37443.

Sibling sweep

Siblings: none -- the backport touches the same sites #37443 changed on main

Pattern harvest

Not generalizable: backport of an already-reviewed fix (#37443)

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

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

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 15, 2026 07:27
@buluoray
buluoray requested review from bolichen97 and removed request for a team November 15, 2026 07:28
@github-actions

github-actions Bot commented Nov 15, 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

  • No reasoning template for d9ab644 yet.

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: d9ab644d584b5e2f83535a491dce45381698511e
- 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 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision d9ab644d584b5e2f83535a491dce45381698511e 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 15, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

No blocker: this is a conflict-free cherry-pick of a fix main already reviewed. It changes how the floor judges commands and removes no surface anyone reads.

Notes

  • The Goal: line misstates what the pick does. It says the fix "lets a KAS custom agent's auto-approved commands through", but the diff mainly refuses more commands: a double-quoted $(ssh … <this host>) used to be masked as data and is now denied. The pick's own cat <<'EOF' carve-out only keeps gh pr create --body "$(cat <<'EOF' …)" allowed, as it already was. The goal is frozen, so state the tightening in a PR comment so release readers expect the new refusals.

[DESIGN-REVIEWED] d9ab644

Description read

[DESCRIPTION-READ] c21fac371063775a53bd884c92ac35d3189345ea5be7e85812a5001eb7f5d13a

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

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

This is a straight backport of reviewed #37443. It tightens the ssh-to-self floor for a sandbox-escape spelling, and the added denied-row tests are the defect's provenance.

Notes

  • Item 1 — framing: the Goal says the fix "lets a KAS custom agent's auto-approved commands through when a double-quoted $( ) appears", but the diff only adds refusals (echo "$(ssh -p 22 <this host> id)" now denied). The rows under test_double_quoted_substitution_rows_that_stay_allowed are rows that were already allowed and stay allowed, not new allows.
  • Item 2 — possible duplicate: _double_quoted_substitution_bodies is a second body-finder beside shell_normalizer_walk._substitution_bodies (1 sibling found grepping def _.*substitution_bodies). It is quote-aware where that one is quote-blind, so the two do different jobs. It stays because a quote-blind reading would refuse echo '$(ssh … )'.
Inventory (4 items) — 4 justified

Intent: give 0.13 users the main-branch ssh-floor fix for a command run from inside a double-quoted $( ). This is a FIX.

  1. A $( ) inside double quotes that reaches ssh to this host is now refused, as the unquoted and backtick spellings already are — justified
  2. A body's quoted-tag heredoc text that a bare cat only prints is not judged, so gh pr create --body "$(cat <<'EOF' …)" stays allowed — justified
  3. Security line-budget row ssh-self-dquote-subst.txt (+69) — justified
  4. Security spec paragraph describing the new reading — justified

[FIRST-PRINCIPLES-REVIEWED] d9ab644

Description read

[DESCRIPTION-READ] 4538f21d0d33a8c59e3f92791fc3e1ae168b33b0935837e360a7004b89d61fa6

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] d9ab644

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

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

@github-actions

github-actions Bot commented Nov 15, 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 d9ab644d584b5e2f83535a491dce45381698511e. 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:1109 -- Nested substitutions crash the permission scan

if any(map(_is_ssh_to_self, _double_quoted_substitution_bodies(unmasked))):
Trigger: With default deny rules, a shell request containing 'echo "$(' * 1000 + 'true; echo ssh' + ')"' * 1000 (valid Bash, 10,014 characters, below the scan ceiling) reaches this recursion through _resolve_permission → _title_denial → is_denied → _reaches_self_over_ssh.
Outcome: The base returns an allowed verdict; this head raises RecursionError. It escapes the off-loop scan and aborts the turn before answering the permission request.
Anchor: residual/crash-data-loss-corruption
Fix: Traverse the double-quoted substitution bodies with an iterative worklist rather than one Python stack frame per nesting level.

[BLOCK-MERGE] d9ab644
[GPT-REVIEWED] d9ab644

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

F1 (fenced): The harm is not unbounded. The crash happens before anything is approved, so it fails closed: the command never runs and no credential or ceiling is exposed. What I confirmed in the code:

  • The crash only happens if a command nests double-quoted $( about 1000 levels deep. No ordinary or model-written command looks like that. Each level is handed back through _is_ssh_to_self from src/kiro_crew/security/argv_floor_ssh.py:1109, and _double_quoted_substitution_bodies (:181) walks them with no depth bound.
  • The floor runs unguarded at security/deny_gate.py:779-806, unlike the rm floor at :892, which catches RecursionError. Nothing in llm_helpers_parts/tool_approval.py:602-610 catches it either, so the RecursionError propagates. reject_tool (:621) is never reached, and neither is any approval.
  • Result: that one turn aborts loudly and the user can retry. A real fix (an iterative worklist, or a depth cap that fails closed) is cheap. But since the outcome is a fail-closed crash and not a bypass, a human could reasonably accept the residual risk.
[ADJUDICATION] d9ab644d584b5e2f83535a491dce45381698511e total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] d9ab644d584b5e2f83535a491dce45381698511e

[ADJUDICATION-FENCED] d9ab644d584b5e2f83535a491dce45381698511e fenced=1 flagged=1
FLAG F1 src/kiro_crew/security/argv_floor_ssh.py:1109 -- Only a deliberately built command nested about 1000 levels deep reaches this, and the RecursionError fails closed (it propagates through deny_gate.py:806 and tool_approval.py:610 before any approval, so the command never runs); the outcome is one visible aborted turn with no bypass, credential exposure, or data loss.
[GPT-ADJUDICATED-FENCED] d9ab644d584b5e2f83535a491dce45381698511e

🏷️ Fenced finding(s) machine-flagged as likely edge case

The security fence keeps these findings blocking regardless of adjudication; the only clearance path is a human override. The annotate-only pass judged the condition combination each one requires extreme, and pre-drafted the override rationale below. A repository writer must independently verify a rationale before posting it — it is machine-authored, and a wrong override on a security-class finding ships exactly the class the fence exists to stop.

  • F1 src/kiro_crew/security/argv_floor_ssh.py:1109 — Only a deliberately built command nested about 1000 levels deep reaches this, and the RecursionError fails closed (it propagates through deny_gate.py:806 and tool_approval.py:610 before any approval, so the command never runs); the outcome is one visible aborted turn with no bypass, credential exposure, or data loss.

    /ai-review override gpt d9ab644d584b5e2f83535a491dce45381698511e <class>: Only a deliberately built command nested about 1000 levels deep reaches this, and the RecursionError fails closed (it propagates through deny_gate.py:806 and tool_approval.py:610 before any approval, so the command never runs); the outcome is one visible aborted turn with no bypass, credential exposure, or data loss.
    

Replace <class> with the class that records what you did. These findings are real, so for an accepted risk use owner-decision (link the decision comment in the reason) or deferred #<N> (a tracked follow-up issue); false-positive only if you verified the finding is wrong. Not not-applicable: that class files the override as a rule mismatch in the audit.

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

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- 🔴 BLOCK (blocking)

Which legitimate operations does d9ab644d584b5e2f83535a491dce45381698511e 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): 21 classified, 2 newly refused, 19 still allowed.
  • ubuntu-latest (platform posix): 21 classified, 2 newly refused, 19 still allowed.
  • windows-latest (platform windows): 6 classified, 0 newly refused, 6 still allowed.

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

  • `git commit -m "$(cat <<EOF
    docs: ssh floor

ssh -p 22 localhost id is now refused in double quotes
EOF
)" (posix, leg macos-latest) - Who loses it: A maintainer's commit about this very floor, with an UNQUOTED heredoc tag: cat only prints the text, but the new cut keeps unquoted-tag text and reads it at the top level - 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]?|$(\shostname|`\shostname|${?hostname}?)(?=[\s:'");&|#]|\Z)
Matched structurally on the command's argv, not by the pat

  • git commit -m "$(cat <<'EOF' 2>/dev/null fix: ssh -p 22 localhost id refused EOF )" (posix, leg macos-latest)
    • Who loses it: A quoted-tag commit message whose cat also carries a stderr redirect; the new cut requires every redirect to be a heredoc and so keeps this text
    • 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
  • `git commit -m "$(cat <<EOF
    docs: ssh floor

ssh -p 22 localhost id is now refused in double quotes
EOF
)" (posix, leg ubuntu-latest) - Who loses it: A maintainer's commit about this very floor, with an UNQUOTED heredoc tag: cat only prints the text, but the new cut keeps unquoted-tag text and reads it at the top level - 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]?|$(\shostname|`\shostname|${?hostname}?)(?=[\s:'");&|#]|\Z)
Matched structurally on the command's argv, not by the pat

  • git commit -m "$(cat <<'EOF' 2>/dev/null fix: ssh -p 22 localhost id refused EOF )" (posix, leg ubuntu-latest)
    • Who loses it: A quoted-tag commit message whose cat also carries a stderr redirect; the new cut requires every redirect to be a heredoc and so keeps this text
    • 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 new rule judges the body of a $(...) inside double quotes as its own command line, and it lives inside is_denied (deny-rules tier), so the classifier covers it. The harness gave me no script-confirmed newly-refused row. Two narrowing questions I can argue but not confirm (an arithmetic $((…<<…)) opening a body that runs to the end of the text, and a case pattern ) ending a body too early) are named below and do not block.

TIGHTENING: ssh-to-self argv floor (argv_floor_ssh._is_ssh_to_self) now recurses into double-quoted command-substitution bodies -- it refuses an ssh-to-this-host hidden in a double-quoted $(...), from the hunk + # The mask above keeps double-quoted text as data, but bash runs a ``$(...)``` / + if any(map(_is_ssh_to_self, _double_quoted_substitution_bodies(unmasked))):/+ return True(e.g.echo "$(ssh -p 22 id)"`).

ADJUDICATED: 27 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: posix (21 rows) and windows (6 rows). I wrote no any rows, because every candidate names an executable. The posix rows probe the bash rules the diff builds in:

  • quote state from _iter_shell_chars, and $$ / \$ parity;
  • where _matching_close_paren ends a body, including an unbalanced case pattern ) and $(( arithmetic, which this scanner also opens as a body;
  • a << inside arithmetic that reaches read_commands(heredocs=True);
  • each quoted-tag heredoc spelling the new bare-cat cut depends on (<<'EOF' with a space, <<-'EOF', <<"EOF", <<\EOF), plus an unquoted tag and a cat with a non-heredoc redirect, which by design keep their text;
  • far-host, variable-host, no-host, -L loopback-forward and ssh-family (ssh-add, ssh-keygen) neighbours inside a body.

The windows rows cover PowerShell's double-quoted $(...) subexpression, which also runs:

  • ssh.exe / scp.exe executable names;
  • backslash path segments inside a body;
  • a path ending in \ before its closing quote, which a posix reader takes as an escaped quote, so the next $( is read in a shifted quote context.

One assumed spelling has no row. PowerShell escapes with a backtick, not a backslash, and the scanner reads every input with bash quoting. A command whose meaning depends on PowerShell escaping can only be classified under bash rules, so no row can test PowerShell's own reading. cmd.exe does not expand $(, so it is outside this change.

UNADJUDICATED: Two narrowing questions the rows probe but that no verdict confirms, and that prose can only argue:

  1. Arithmetic in double quotes. "$((1<<4))" opens a body at $((, and rest begins (1<<4))…. If read_commands(rest, heredocs=True) takes <<4 as a heredoc tag, the blanked text leaves _matching_close_paren unproven, and the body becomes text[at + 2 :], everything to the end of the line. The rest of the line is then judged with its quote context shifted, so prose inside a later double-quoted commit message after a ; could be read as a command. Probed by the row echo "mask $((1<<4))"; git commit -m "docs: shift fixed; ssh -p 22 localhost id stays refused". If it confirms, the narrow fix is in the scanner: skip $(( as arithmetic, the way read_commands already does, instead of opening a body.
  2. case patterns. A case pattern ) inside a captured body (kind="$(case "$OSTYPE" in darwin*) …; esac)") may end the body early and resume the scan in the wrong quote state. Probed by the case row. The fix is the same kind: _matching_close_paren should skip case pattern parens.

[SCOPE-REVIEWED] d9ab644

The confirmed rows, in the committed corpus's own shape
{
  "golden_paths": [
    {
      "kind": "shell",
      "command_or_flow": "git commit -m \"$(cat <<EOF\ndocs: ssh floor\n\nssh -p 22 localhost id is now refused in double quotes\nEOF\n)\"",
      "platform": "posix",
      "reason": "A maintainer's commit about this very floor, with an UNQUOTED heredoc tag: cat only prints the text, but the new cut keeps unquoted-tag text and reads it at the top level"
    },
    {
      "kind": "shell",
      "command_or_flow": "git commit -m \"$(cat <<'EOF' 2>/dev/null\nfix: ssh -p 22 localhost id refused\nEOF\n)\"",
      "platform": "posix",
      "reason": "A quoted-tag commit message whose cat also carries a stderr redirect; the new cut requires every redirect to be a heredoc and so keeps this text"
    }
  ]
}

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

Copy link
Copy Markdown
Contributor

MacFlackyGuard: Security scope adjudication (macos-latest) is red because of this PR's change, not a flaky macOS test.

  • Run: https://github.com/kirodotdev/KiroCrew/actions/runs/43690064110/job/132739691353
  • deny_diff found 5 newly-refused candidates on macOS (the same 5 on ubuntu-latest, plus 1 on windows-latest). All are refused by the new deny-rules ssh floor in src/kiro_crew/security/argv_floor.py / argv_floor_ssh.py. They are legitimate rows: ssh -G config debugging inside "$( )", capturing a remote command's output into a variable over ssh/sftp, two gh pr create --body "$(cat <<EOF ...)" bodies that only mention an ssh command as text, and on Windows a PowerShell capture of ssh.exe to a remote host. The exact commands are in report-*.json in the run artifacts.
  • Please narrow the rule (or adjudicate these in the scope review). I am not changing this PR.

…37443)

The ssh-to-self floor masks quoted separators and parens before it
walks a command line, so it never saw a `$(` inside double quotes:
`echo "$(ssh -p 22 <this host> id)"` and `x="$(...)"` slipped past
the floor, although bash runs that substitution.

The mask stays as it was, so the parent command's walk still reads
the quoted word as one argument. The floor now also takes each
double-quoted `$( )` body from the unmasked text, opened only by an
unpaired `$` and ended at its own matching `)`, and judges it as a
command line of its own. A quoted-tag heredoc that a bare `cat` only
prints is cut from the body first, so a PR body passed through
`"$(cat <<'EOF' ...)"` stays allowed.

Closes #36904

(cherry picked from commit 87b11b5)
@buluoray
buluoray force-pushed the crew/slack/backport-0.13.0-37443 branch from ce60e9c to d9ab644 Compare November 16, 2026 03:41
@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 16, 2026
@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 16, 2026
@bolichen97
bolichen97 merged commit 2837764 into release/0.13.0 Nov 16, 2026
92 of 103 checks passed
@bolichen97
bolichen97 deleted the crew/slack/backport-0.13.0-37443 branch November 16, 2026 07:21
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 16, 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.

2 participants