Skip to content

fix(security): treat backticks inside single quotes as plain text - #36903

Merged
buluoray merged 1 commit into
mainfrom
crew/slack/ssh-self-quoted-backtick
Nov 15, 2026
Merged

buluoray merged 1 commit into
mainfrom
crew/slack/ssh-self-quoted-backtick

Conversation

@buluoray

@buluoray buluoray commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A command whose only ssh text sits inside a single-quoted argument, such as a PR body or commit message that quotes an ssh example in backticks, is no longer refused by the ssh-to-self guard, because bash runs nothing there.

gh pr edit 1 --body 'Run ssh lvh.me id to check' is refused with rule=sandbox-escape-ssh-self component=argv-floor. The same text without the backticks is allowed. Inside single quotes a backtick is a plain character to bash, so nothing runs.

Why it matters

Agents quote commands in Markdown code spans all the time when they write PR bodies, issues and commit messages. Each time the example names an ssh host, the call is refused as a sandbox escape, the turn stops, and the agent is sent down the escape-recovery path for a harmless write.

Not a goal

What changed (motivation → approach → change)

The floor finds command substitutions with the shared payload walk. _substitution_bodies looked for `, $(, <( and >( byte by byte, without the quote state, so an opener inside '...' opened a nested command.

The walk now checks the existing quote reader (_iter_shell_chars), but only for a message flag on git or gh. When the caller's own line is one simple git commit|tag with -m/--message, or gh pr|issue create|edit|comment with --body/-b/--title/-t, and every `, $(, <( and >( sits inside a value of one of those flags that is one bare single-quoted word ('…' with nothing before or after it, so not $[…], $'…', x'…' or '…'y), and the line holds no $ anywhere, the line opens no nested frame. Any other text keeps main's quote-blind reading:

Text Reading
one simple `git commit tag/gh pr
any other command (echo, trap, bash -c, gh alias, git -c …, a path or wrapper before git/gh) main's
any live opener anywhere on the line, or a separator (;, &, ` `, a paren or brace)
a nested or decoded payload, or text holding $ anywhere, #, <<, a backslash or a control byte main's

_is_message_flag_command and _only_single_quoted_openers make the call, for the top frame only. The ssh floor judges the caller's line before it splices static $(...) output in.

Command main this PR
--body 'Run ssh lvh.me id to check', git commit -m 'docs: quote ssh -p 22 localhost id' refused allowed
echo "ssh localhost id", echo ssh localhost id``, sh -c, `eval`, `bash <<'EOF'` with ssh refused refused
trap '…', git -c alias.x='!…', gh alias set, echo '…' holding a backtick ssh refused refused
a live backtick ssh beside single quotes, or after a $(echo "x'y") refused refused

security.md records the rule. The security package's line budget gets one row, test/security_line_budget/ssh-self-quoted-message-flags.txt (+79, with its reason).

Backwards compatibility

Compatible: the only verdicts that change are refused to allowed, for one-line text bash keeps as plain characters inside single quotes.

Removes nothing: no deny pattern, rule id or catalog row changes, and every refusal for a live substitution still holds.

Tests

  • test/test_denied_commands_security_ssh_self.py::test_single_quoted_substitution_is_literal_text: single-quoted gh pr edit --body (also --body=), gh issue create -t/-b, git commit -m (also -m'…') and git tag --message forms are allowed (they use -p 22 or a non-catalog host, so only the floor is tested); the python3 -c and echo 'run $(…) later' rows stay allowed, as on main.
  • ...::test_single_quotes_outside_a_message_flag_get_the_quote_blind_reading: trap, bash -c 'eval "$1"', git -c alias.x='!…', git -c core.sshCommand=…, gh alias set, echo '…', echo $'…', git commit -F '…', a second positional, a chained && echo '…', /usr/bin/git, env git and gh api -f body='…' are all refused, as on main.
  • ...::test_floor_opens_no_substitution_inside_single_quotes: for the literal-localhost rows the floor does not fire; the catalog row may still refuse them.
  • ...::test_live_substitution_outside_single_quotes_still_denied: every row is refused on main too. It covers real ssh, bash <<'EOF', sh -c, eval, unquoted and double-quoted backticks, a backtick between two quoted spans, comments, heredocs, newlines, a decoded -c payload, ${ and a backslash.
  • ...::test_dollar_message_keeps_the_quote_blind_reading: a git commit -m line holding $[…], $((…)), $(…), ${…} or $'…', as the value or in another word, is refused, as on main.
  • ...::test_unsafe_text_gets_the_quote_blind_reading and ...::test_nested_payload_gets_the_quote_blind_reading: those texts, and an eval payload, give exactly main's bodies.
  • ...::test_one_line_single_quoted_backtick_is_literal, ...::test_heredoc_text_keeps_the_quote_blind_reading, ...::test_multi_line_text_keeps_the_quote_blind_reading: the rule on and off; a live opener beside a quoted one gives main's bodies.
  • test/test_argv_rules.py::test_real_permission_changes_are_refused: a double-quoted backtick chmod stays refused.

Proof: not provable -- other: red-first on main failed 4 single-quote rows, on 83d7c41 failed 13 rows (decoded payloads, ${, backslash, fall-back inputs), and on ce340b9 failed the spliced $(echo "x'y") row, and on eb5e7a4 failed 16 rows (the non-message-flag commands above), and on 1f1eb53 failed the $[…] and $'…'-neighbour rows; every refused row is refused on base 46707f8 too; prove.py was not run on this head.

Manual verification

N/A — unit coverage sufficient: the floor is a pure function of the command text, called through the public is_denied entry point. scripts/local-gate.py: backend related set, 7,542 passed. Its frontend step could not load vite.config.ts in this worktree (no node_modules); the diff touches no frontend file.

Related Issues

Closes #36887

Sibling sweep

Swept: git grep -n "_substitution_bodies(" -- src/kiro_crew/security/
Sibling: src/kiro_crew/security/shell_normalizer.py -- changed here
Sibling: src/kiro_crew/security/shell_normalizer_walk.py -- changed here
Sibling: src/kiro_crew/security/argv_floor_self.py:209 -- changed here: quoted assignment scripts are nested payloads, walked with main's reading
Sibling: src/kiro_crew/security/argv_floor_ssh.py -- changed here: only the caller's own line is judged by the rule, before static splices
Sibling: src/kiro_crew/security/argv_floor_self.py:918 -- not affected -- it passes a join of de-quoted tokens, where a literal quote must not hide a later opener, so it keeps the quote-blind read
Sibling: src/kiro_crew/security/shell_normalizer.py:1123 -- not affected -- same: a de-quoted join, read quote-blind as before

Pattern harvest

Not generalizable: one shared reader looked for substitution openers without the quote state its own sibling helper already tracks.

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

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 13, 2026 22:23
@buluoray
buluoray requested a review from CrysisDeu November 13, 2026 22:23
@buluoray
buluoray enabled auto-merge (squash) November 13, 2026 22:24
@github-actions

github-actions Bot commented Nov 13, 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/shell_normalizer.py

  • src/kiro_crew/security/shell_normalizer_walk.py

  • @buluoray comment (3 comments checked, none complete): does not name the current head 9ed8f10; 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: 9ed8f10e83381a9feaa74aa6d2b2afc45b64199b
- 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 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 9ed8f10e83381a9feaa74aa6d2b2afc45b64199b 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 13, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

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

The ssh-floor fix is aimed at the right cause, but its default also loosens the self-protection and argv-rule floors, which the Goal does not cover.

Notes

  • Item 2 — undeclared, oversized: the Goal says only "no longer refused by the ssh-to-self guard". The diff instead sets _shell_payload_walk(..., literal_single_quotes: bool = True) and _self_token_frames(..., literal_single_quotes: bool = True). As a result, 7 callers that pass nothing now get the literal reading too: argv_floor_self.py:261,379,855,899,1152,1237 and argv_rules.py:209. I found them by grepping _shell_payload_walk\(|_self_token_frames\(|_self_frames\(. Subtraction: change both defaults to False, and pass True only from _is_ssh_to_self(own_line=True). Clears when: the mechanism is removed, or a human amends the Goal.

What this change ships

Inventory (4 items) — 3 justified

Intent: let agents write PR bodies and commit messages that quote ssh examples in backticks without being refused as a sandbox escape. This is a FIX (#36887).

  1. A single-quoted backtick or $( in a git commit|tag -m or gh pr|issue … --body/--title value no longer trips the ssh-to-self floor — justified
  2. The same literal reading now also applies to the self-protection floor, the git-publish floor and argv_rules — undeclared, oversized: the shared walk's default is True
  3. A new line-budget row, ssh-self-quoted-message-flags.txt — justified
  4. The security.md walk section now records the rule — justified

[FIRST-PRINCIPLES-REVIEWED] 9ed8f10

Description read

[DESCRIPTION-READ] 861bc135edec9743e88d5eb2cf1765cd5c74a31a6de41f1d11a4eaf4d7f0d60b

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the change is a narrow allow-list (one simple git/gh message-flag command, bare single-quoted values, no $). Every other shape keeps main's quote-blind reading, and the only verdicts that change are refusals becoming allowed.

Notes

  • _shell_payload_walk/_self_frames now default to literal_single_quotes=True, so the self-protection and git-publish floors get the same literal reading, not only the ssh floor. The ssh floor protects its own line from the "spliced x'y" pairing hazard, but those other callers don't. Defaulting to False and opting in at each caller would keep that splice guard in one place.

[DESIGN-REVIEWED] 9ed8f10

Description read

[DESCRIPTION-READ] 114e97be17ec61589e9b1cbb9b3a7356b2eaa9e2504f382c53e2c3e922adcb70

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 9ed8f10

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

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

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does 9ed8f10e83381a9feaa74aa6d2b2afc45b64199b 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): 17 classified, 0 newly refused, 14 still allowed.
  • ubuntu-latest (platform posix): 17 classified, 0 newly refused, 14 still allowed.
  • windows-latest (platform windows): 4 classified, 0 newly refused, 3 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

Reason: The diff mostly loosens the shell-payload walk. Inside the caller's own one-line git commit|tag -m or gh pr|issue create|edit|comment --body|--title command, a substitution opener in single quotes is now read as literal text. Every other input keeps the quote-blind reading it had at base: _quoted_assignment_scripts walks with literal_single_quotes=False when text != text_lower, and with literal_single_quotes=True only for the caller's own line. I got no verdicts back from the classifier for these candidates, so no regression is confirmed.

TIGHTENING: Shell-payload walk (_shell_payload_walk / _substitution_bodies(raw_source=...)), used by the self floors, the ssh-to-self floor and argv_rules. It is a relaxation with fail-closed fallbacks rather than a new refusal. The threat it keeps refused is a live substitution hidden next to single quotes: "A live opener anywhere keeps the quote-blind reading for the whole text, so static substitution output spliced around the ssh (x'y) cannot pair into single quotes that hide it" (argv_floor_ssh.py, literal = own_line and _only_single_quoted_openers(text_lower)). The fallbacks are if raw_source and not any(m in text for m in ("#", "<<", "$", "\\")), the control-byte check, _only_single_quoted_openers and _is_message_flag_command. Any input that fails one of them gets the base reading.

ADJUDICATED: 21 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE:

  • posix: The diff assumes POSIX spelling: _is_message_flag_command keys on the first word being literally git or gh, and on bash single-quote semantics. The posix rows cover the edges of that test:
    • single-quoted commit, tag and gh messages, with and without backticks in them;
    • two -m flags on one line;
    • --body-file and --add-label neighbours;
    • a compound && commit-and-push;
    • a double-quoted live $(cat VERSION) subject;
    • ordinary remote ssh and rsync;
    • a quoted-assignment bash -c script;
    • a chmod next to the new argv_rules test case.
  • windows: These rows probe the git.exe / gh.exe / ssh.exe names and cmd.exe double quoting. The literal-first-word check never matches those names, so on Windows they should stay on the base reading. They test that this fallback refuses nothing new.
  • any: Not used, because every row names an executable.
  • Not covered: PowerShell quoting, where '...' is also literal but the tokenizer differs.

UNADJUDICATED: No guard outside the shell deny composite changed. One narrowing is argued but not confirmed. Message-flag commands written with a full program path (/usr/bin/git commit -m '...'), an env prefix or a .exe name keep the base quote-blind reading. On every platform, a commit message with backticks inside single quotes that names a self-reaching ssh still matches the catalog row on its raw text. The new test notes that in its comment (The catalog row still matches these literal spellings). Neither case is newly refused: both behave exactly as at base.

[SCOPE-REVIEWED] 9ed8f10

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 9ed8f10

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

@buluoray
buluoray disabled auto-merge November 13, 2026 22:38
@KiroCrewCaptain

KiroCrewCaptain commented Nov 13, 2026 •

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 20% chance that this change introduces a defect, above the 12% limit for approving on its own.

The fix is sound. Only a single simple git commit|tag or gh pr|issue create|edit|comment line gets the literal reading, and only when every backtick, $(, &lt;( or &gt;( sits inside a bare single-quoted message-flag value with no $, #, <<, backslash, control byte or unclosed quote. Bash runs nothing in that case. Every other text keeps main's quote-blind reading. The ssh floor decides the literal reading from the line as typed, before it splices in static $(echo ...) output, and it is the only place in the repo that does that splicing. The other checks pass the original text, so turning the setting on by default for them is still correct shell behaviour. The two caches include the new flag in their keys. Tests cover a broad set of fall-back and refused cases. Leftover items: a wider default than the stated goal, no tests showing the other checks change, and a missing Sensitive Change template.

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 9ed8f10e83 · 387 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@buluoray
buluoray force-pushed the crew/slack/ssh-self-quoted-backtick branch from 0229487 to 2a38ed6 Compare November 13, 2026 23:06
@buluoray

Copy link
Copy Markdown
Contributor Author

span=58f918e8fcd6
self-added: yes
mechanism: quote-aware opener scan read quotes in an unquoted heredoc body as shell quoting

  • Unquoted heredoc expansion bypasses the SSH-to-self guard

fixed in 2a38ed6: the single-quote rule now applies only to ordinary shell words; _substitution_bodies(raw_source=True) locates heredoc bodies with read_commands(..., heredocs=True) and reads unquoted bodies quote-blind, while a quoted-tag body opens no substitution.
The ssh floor reads payloads from the source before its argv mask, so <<-EOF and a double-quoted here-string are caught too.
Pinned refused: unquoted heredoc, <<-EOF, heredoc piped to sh, heredoc later in a chain, heredoc inside $(...), two heredocs on one line, here-string, bash <<'EOF'; red on 0229487 (12 failed).

@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 13, 2026
@buluoray
buluoray force-pushed the crew/slack/ssh-self-quoted-backtick branch from 2a38ed6 to 777d1dd Compare November 13, 2026 23:58
@buluoray

Copy link
Copy Markdown
Contributor Author

span=cd95ea57f636
self-added: yes
mechanism: raw-source walk closed a backtick body with the quote-aware closer, so a quote inside it hid the top-level command after it

  • a lone quote inside a backtick body hid a top-level ssh between two spans

fixed in 777d1dd: in raw-source mode _substitution_bodies ends a backtick body at its first unescaped backtick with _backtick_closer, as bash does, whatever quotes sit inside.
When such a body holds a ' or ", the walk also reads the line with those bodies cut out, so the ssh between the two spans reaches the floor.
echo `'` ; ssh -p 22 <self> id; echo `'` and the " spelling (allowed on main too) are refused, and a newline spelling as well; pinned in test_live_substitution_outside_single_quotes_still_denied.
Single-quoted literal rows give the same answer as before; the extra frame only exists for a live backtick body outside single quotes.

@buluoray

Copy link
Copy Markdown
Contributor Author

span=cd95ea57f636
self-added: yes
mechanism: single-quote skip read an apostrophe inside a # comment as an open quote
resolution: narrowed -- the single-quote rule now applies only to one-line text with no # and no <<

  • an apostrophe inside a # comment hid a backtick ssh on a later line

fixed in 83d7c41: _substitution_bodies(..., raw_source=True) applies the single-quote rule only when the text has no #, no << and no newline; any other text keeps main's quote-blind reading.
A comment can only start where one of those marks is present, so no comment can set the quote state the rule reads; the heredoc split this PR had added is removed.
Retrospective (round 3): the earlier rounds patched one reader shape each; narrowing the scope to the reported one-line --body '...' / -m '...' shapes ends that class instead of patching a fourth spelling.
echo ok # don't\necho ssh -p 22 id\n#', the $( form, a comment inside a substitution body, and single-quoted ssh text on a line with #, << or a newline are refused; pinned in test_live_substitution_outside_single_quotes_still_denied.

@buluoray

Copy link
Copy Markdown
Contributor Author

span=58f918e8fcd6
self-added: yes
mechanism: single-quote skip read an apostrophe inside a # comment as an open quote
resolution: narrowed -- the single-quote rule now applies only to one-line text with no # and no <<

  • Quotes in comments hide live SSH substitutions

fixed in 83d7c41: the single-quote rule in _substitution_bodies(..., raw_source=True) runs only on text with no #, no << and no newline; text with a comment keeps main's quote-blind reading.
echo ok # '\necho $(ssh -p 22 <self> id) is refused; comment rows (also inside a substitution body) are pinned in test_live_substitution_outside_single_quotes_still_denied.

@buluoray

Copy link
Copy Markdown
Contributor Author

span=58f918e8fcd6
self-added: yes
mechanism: recursive heredoc discovery inside the raw-source substitution walk
resolution: removed -- the heredoc split inside _substitution_bodies is gone

  • Heredoc discovery crashes on deeply nested substitutions

fixed in 83d7c41: the read_commands(..., heredocs=True) loop inside _substitution_bodies is removed; text holding << takes main's quote-blind path, as it did before this PR.
The 1,050-deep nested "$( input after a heredoc returns a normal verdict (allowed, as on main) with no RecursionError.

@buluoray

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 47bd2f9
  • What rule changed: the ssh-to-self floor's walk (shell_normalizer_walk._substitution_bodies, raw-source reading of the caller's own line) treats a backtick or $( inside single quotes as plain text, as bash does, but only when the line is ONE simple git commit|tag with -m/--message, or gh pr|issue create|edit|comment with --body/-b/--title/-t, every opener sits inside one bare single-quoted value of such a flag, and the text holds no $, #, <<, backslash, control byte or unclosed quote (_is_message_flag_command, _only_single_quoted_openers).
  • Before -> after (what was allowed/blocked, now): before, git commit -m 'docs: quote ssh -p 22 localhost id' and gh pr edit 1 --body 'Run ssh lvh.me id to check' were refused although bash runs no ssh there; now they are allowed. Every other shape keeps main's quote-blind reading and stays refused: live or double-quoted backticks, sh -c, eval, bash <<'EOF', trap '...', git -c alias.x='!...', gh alias set, echo '...', a path or wrapper before git/gh, any line with a $ ($[...], $((...)), $(...), ${...}, $'...'), a separator, a comment, a heredoc or a newline.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a command that really runs ssh-to-self is allowed. The allowed set is narrow: one simple git/gh message command whose only openers are inside a bare single-quoted message value, which git/gh store as text and bash never runs; any $, separator, wrapper or nested payload falls back to main's reading. Nothing that main allows is newly refused.
  • Evidence checked (which sandbox result proves it): is_denied probes on this change: git commit -m $[ -m 'ssh -p 22 id' ] refused on base and on this head (bash runs that backtick; checked with a harmless touch), git commit -m 'docs: quote ssh -p 22 id' refused on base, allowed here. Red-first rows for $[, $((, $(, ${, $' and the earlier rounds' shapes fail on the previous heads and pass here. GPT 6.1, Opus 5.5, Design, First Principles and Security Scope all pass on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): the ssh-self, argv-rules and security-liveness suites pass (548 locally on this head, with test_conductor_agent.py); python3 -c and echo 'run $(...) later' rows stay allowed as on main.
    • Backward compatible (old config / old data / old callers still work, how checked): no deny pattern, rule id, catalog row, config or data format changes; only refused-to-allowed verdicts change, for the shapes listed above.
    • Existing tests (which suites passed on this head): test_denied_commands_security_ssh_self.py, test_argv_rules.py, test_security_gate_liveness.py locally; CI backend shards (Linux and Windows) and CodeQL green on this head.
  • How to undo: revert the PR's commit; the walk returns to the quote-blind reading of every opener.

@buluoray
buluoray force-pushed the crew/slack/ssh-self-quoted-backtick branch from 47bd2f9 to 4e7e619 Compare November 14, 2026 18:53
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 14, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

/ai-review override scope 4e7e619 false-positive: agent: ssh -T git@github.com is refused only on the first call while host DNS classification is pending, identically on main 8298ea2 and this head; later calls are allowed on both (tracked in #37311). Not caused by this diff.

@buluoray

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 4e7e619
  • What rule changed: the ssh-to-self floor's walk (shell_normalizer_walk._substitution_bodies, raw-source reading of the caller's own line) treats a backtick or $( inside single quotes as plain text, as bash does, but only when the line is ONE simple git commit|tag with -m/--message, or gh pr|issue create|edit|comment with --body/-b/--title/-t, every opener sits inside one bare single-quoted value of such a flag, and the text holds no $, #, <<, backslash, control byte or unclosed quote (_is_message_flag_command, _only_single_quoted_openers).
  • Before -> after (what was allowed/blocked, now): before, git commit -m 'docs: quote ssh -p 22 localhost id' and gh pr edit 1 --body 'Run ssh lvh.me id to check' were refused although bash runs no ssh there; now they are allowed. Every other shape keeps main's quote-blind reading and stays refused: live or double-quoted backticks, sh -c, eval, bash <<'EOF', trap '...', git -c alias.x='!...', gh alias set, echo '...', a path or wrapper before git/gh, any line with a $ ($[...], $((...)), $(...), ${...}, $'...'), a separator, a comment, a heredoc or a newline.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a command that really runs ssh-to-self is allowed. The allowed set is narrow: one simple git/gh message command whose only openers are inside a bare single-quoted message value, which git/gh store as text and bash never runs; any $, separator, wrapper or nested payload falls back to main's reading. Nothing that main allows is newly refused.
  • Evidence checked (which sandbox result proves it): is_denied probes on this change: git commit -m $[ -m 'ssh -p 22 id' ] refused on base and on this head (bash runs that backtick; checked with a harmless touch), git commit -m 'docs: quote ssh -p 22 id' refused on base, allowed here. Red-first rows for $[, $((, $(, ${, $' and the earlier rounds' shapes fail on the previous heads and pass here. GPT 6.1, Opus 5.5, Design, First Principles and Security Scope all pass on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): the ssh-self, argv-rules and security-liveness suites pass (548 locally on this head, with test_conductor_agent.py); python3 -c and echo 'run $(...) later' rows stay allowed as on main.
    • Backward compatible (old config / old data / old callers still work, how checked): no deny pattern, rule id, catalog row, config or data format changes; only refused-to-allowed verdicts change, for the shapes listed above.
    • Existing tests (which suites passed on this head): test_denied_commands_security_ssh_self.py, test_argv_rules.py, test_security_gate_liveness.py locally; CI backend shards (Linux and Windows) and CodeQL green on this head.
  • How to undo: revert the PR's commit; the walk returns to the quote-blind reading of every opener.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@buluoray recorded a false-positive release (class false-positive) for the scope AI finding on 4e7e61921483f1972eae9c3ded901431f5c3c294.

agent: ssh -T git@github.com is refused only on the first call while host DNS classification is pending, identically on main 8298ea2 and this head; later calls are allowed on both (tracked in #37311). Not caused by this diff.

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

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 14, 2026
The ssh-to-self floor read a backtick or $( inside a single-quoted
argument as a live command substitution. Bash keeps that text as
plain characters, so a PR body or commit message that quotes an ssh
example in Markdown code spans was refused although nothing runs.

The shared payload walk now reads substitution openers with the
quote state the shell uses: one inside '...' or $'...' opens no
nested frame. Double quotes, unquoted text, sh -c and eval scripts,
and heredocs a shell runs still open one, so every real refusal
stays. The catalog pattern row is unchanged.

Closes #36887
@buluoray
buluoray force-pushed the crew/slack/ssh-self-quoted-backtick branch from 4e7e619 to 9ed8f10 Compare November 14, 2026 21:22
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision 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 14, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

No blocking finding on this head. This PR changes what the denied-command gate allows (refused on main, allowed here), and docs/system-specs/modules/security.md now records that allowance. The security reviewers and maintainers decide a change that widens a security gate. This review does not. So the PR waits for a person.

What the review verified on 9ed8f10: it ran is_denied on main and head trees for the goal rows and for about 60 fallback shapes ($(printf "'") splices, ''-adjacent backticks, git -c alias, $[..], heredocs, comments, nested -c payloads). Each shape that main refuses is still refused. Reverting the fix makes 23 tests fail. One thing done well: the exemption is an allow-list of positive conditions, so any doubt falls back to the reading main uses, and a parse error can only over-refuse.

For the security review:

  1. Four functions now default to literal_single_quotes=True: _shell_payload_walk, _shell_payload_walk_uncached, _self_frames and _self_token_frames (shell_normalizer.py:1588, argv_floor_self.py:228 and :254). That default also changes floors the Goal does not name. On head these commands are allowed, and main refuses each one at the argv floor: git commit -m 'see `chmod 600 /etc/shadow`', gh pr edit 1 --body 'see `chmod 777 /etc/passwd`' and git commit -m 'note `kirocrew gateway restart`'. Bash runs none of them, but no test pins these verdicts. One smallest fix: set the four defaults to False and pass True only from the ssh floor (argv_floor_ssh.py:1078). That keeps the goal row allowed and restores main's verdicts everywhere else. Only the test at test_denied_commands_security_ssh_self.py:1266 then has to pass the flag. The other fix: keep the default, declare the change, and add verdict rows for the argv_rules, self-protection and git-publish floors.
  2. The Sensitive Change Review check is red. The latest template names head 4e7e619, not 9ed8f10, and it describes only the ssh floor.
  3. Open fix(security): read a multi-line script a shell runs in the ssh-to-self floor #35359 adds a second single-quote reading at the same _substitution_bodies seam, and the two PRs conflict in a merge. Name the merge order in both bodies. The second PR should reuse _only_single_quoted_openers and not add a second scanner.

Optional:

  • Most of the new guard lines survive deletion. The rows that name them start with echo, and _is_message_flag_command rejects echo first. Message-flag spellings such as git commit -m 'a\x04b `id`' would pin the control-byte and unclosed-quote checks.
  • Main already allows the gh issue create -t 'x' -b 'Run $(ssh -p 22 localhost id)' row, so that row does not test the fix.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed 9ed8f10e83. Approving.

The change is narrow. Single quotes read as literal only on the caller's own line, only for one simple git commit|tag -m or gh pr|issue … --body|--title command, and only when every substitution opener sits inside one bare single-quoted value. Nested and decoded payloads stay quote-blind, and the memo keys now include the flag, so the two readings never share a cache entry.

I ran 14 hand-written shapes through is_denied on this head and on current main. The only verdict that changed is git commit -m 'see `ssh -p 22 localhost id`', which is literal text in bash. These stay denied on both: a trailing ; ssh …, && ssh …, | sh, a newline, &, > >(sh), a second positional quoted word, '\'' splicing, double quotes, --cleanup=verbatim -m, and --body … --repo x. The last two fall back to the quote-blind reading, which is conservative.

Not from this PR, worth an issue of their own: git -c core.pager='sh -c "ssh localhost"' commit … and GIT_SSH_COMMAND='ssh localhost' git commit … pass on main as well as here.

Locally: test_denied_commands_security_ssh_self.py, test_argv_rules.py and test_security_gate_liveness.py pass on this head (482 passed). The filled template is below, so Sensitive Change Review can clear on this head. Auto merge is on.

Sensitive change review

  • Head commit: 9ed8f10
  • What rule changed: sandbox-escape-ssh-self, through the payload walk (_shell_payload_walk, _self_frames, _is_ssh_to_self).
  • Before -> after (what was allowed/blocked, now): before, a backtick or $( inside a single-quoted commit message or PR body was read as a live substitution, so a commit message quoting an ssh command was denied. Now that one shape passes; every other shape keeps the quote-blind reading.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a command that really runs ssh to this host passes the floor.
  • Evidence checked (which sandbox result proves it): is_denied on 14 shapes on this head and on main, listed above; the only difference is the literal message case.
  • No regression:
    • Tools still work (which tools/commands were run, result): plain ssh localhost id and every wrapped form above still deny.
    • Backward compatible (old config / old data / old callers still work, how checked): the new keyword arguments default to the old reading; existing callers are unchanged.
    • Existing tests (which suites passed on this head): the three suites above, 482 passed locally.
  • How to undo: revert this PR's commit.

@buluoray
buluoray merged commit 3397952 into main Nov 15, 2026
156 of 159 checks passed
@buluoray
buluoray deleted the crew/slack/ssh-self-quoted-backtick branch November 15, 2026 00:38
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 15, 2026
buluoray added a commit that referenced this pull request Nov 15, 2026
…6903)

The ssh-to-self floor read a backtick or $( inside a single-quoted
argument as a live command substitution. Bash keeps that text as
plain characters, so a PR body or commit message that quotes an ssh
example in Markdown code spans was refused although nothing runs.

The shared payload walk now reads substitution openers with the
quote state the shell uses: one inside '...' or $'...' opens no
nested frame. Double quotes, unquoted text, sh -c and eval scripts,
and heredocs a shell runs still open one, so every real refusal
stays. The catalog pattern row is unchanged.

Closes #36887

(cherry picked from commit 3397952)
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.

sandbox-escape-ssh-self reads backticks inside a single-quoted argument as a command substitution

3 participants