Repository navigation
fix(security): treat backticks inside single quotes as plain text - #36903
Conversation
Sensitive Change ReviewSensitive files changed:
How to clear this check:
Only the author's comment counts this way. A reviewer can instead |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of 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
What this change shipsInventory (4 items) — 3 justifiedIntent: 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).
[FIRST-PRINCIPLES-REVIEWED] 9ed8f10 Description read[DESCRIPTION-READ] 861bc135edec9743e88d5eb2cf1765cd5c74a31a6de41f1d11a4eaf4d7f0d60b That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change is a narrow allow-list (one simple Notes
[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 |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
Security Scope Review -- ✅ PASSWhich legitimate operations does Verdict basis: adjudicated, zero confirmed regressions. Security scope review -- adjudicated candidates
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 TIGHTENING: Shell-payload walk ( ADJUDICATED: 21 candidates, 0 confirmed newly-refused PLATFORM COVERAGE:
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 ( [SCOPE-REVIEWED] 9ed8f10 |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Code change approver recommendation: A person should decideWhy: 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, 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 |
0229487 to
2a38ed6
Compare
|
span=58f918e8fcd6
|
2a38ed6 to
777d1dd
Compare
|
span=cd95ea57f636
|
777d1dd to
83d7c41
Compare
|
span=cd95ea57f636
|
|
span=58f918e8fcd6
|
|
span=58f918e8fcd6
|
83d7c41 to
ce340b9
Compare
Sensitive change review
|
47bd2f9 to
4e7e619
Compare
|
/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. |
Sensitive change review
|
Human judgment recorded@buluoray recorded a false-positive release (class
This decision applies only to this commit. A new push requires a new judgment. |
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
4e7e619 to
9ed8f10
Compare
|
No blocking finding on this head. This PR changes what the denied-command gate allows (refused on main, allowed here), and What the review verified on 9ed8f10: it ran For the security review:
Optional:
|
bolichen97
left a comment
There was a problem hiding this comment.
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
sshto this host passes the floor. - Evidence checked (which sandbox result proves it):
is_deniedon 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 idand 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.
- Tools still work (which tools/commands were run, result): plain
- How to undo: revert this PR's commit.
…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)
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 'Runssh lvh.me idto check'is refused withrule=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
localhost/127.0.0.1ssh line wherever it sits. Loosening it is a separate decision.python3 -orcat(ssh-self and -d @ exfil gates refuse inert commands: heredoc bodies read as argv, date outside a lone command #34754 / fix(security): stop the ssh-self and -d @ gates refusing inert lines #34755).python3 -c 'import os; os.system(...)', which main allows and leaves to the OS network fence (Sandbox network fence: block loopback sshd from inside the sandbox (netns or connect-filter on self:22) #9806).$(ssh ...)that main already lets through: tracked on its own.What changed (motivation → approach → change)
The floor finds command substitutions with the shared payload walk.
_substitution_bodieslooked 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 ongitorgh. When the caller's own line is one simplegit commit|tagwith-m/--message, orgh pr|issue create|edit|commentwith--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:/gh precho,trap,bash -c,gh alias,git -c …, a path or wrapper beforegit/gh);,&, `$anywhere,#,<<, a backslash or a control byte_is_message_flag_commandand_only_single_quoted_openersmake the call, for the top frame only. The ssh floor judges the caller's line before it splices static$(...)output in.--body 'Runssh lvh.me idto check',git commit -m 'docs: quotessh -p 22 localhost id'echo "ssh localhost id",echossh localhost id``,sh -c, `eval`, `bash <<'EOF'` with sshtrap '…',git -c alias.x='!…',gh alias set,echo '…'holding a backtick ssh$(echo "x'y")security.mdrecords 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-quotedgh pr edit --body(also--body=),gh issue create -t/-b,git commit -m(also-m'…') andgit tag --messageforms are allowed (they use-p 22or a non-catalog host, so only the floor is tested); thepython3 -candecho '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 gitandgh api -f body='…'are all refused, as on main....::test_floor_opens_no_substitution_inside_single_quotes: for the literal-localhostrows 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-cpayload,${and a backslash....::test_dollar_message_keeps_the_quote_blind_reading: agit commit -mline holding$[…],$((…)),$(…),${…}or$'…', as the value or in another word, is refused, as on main....::test_unsafe_text_gets_the_quote_blind_readingand...::test_nested_payload_gets_the_quote_blind_reading: those texts, and anevalpayload, 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 backtickchmodstays 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_deniedentry point.scripts/local-gate.py: backend related set, 7,542 passed. Its frontend step could not loadvite.config.tsin this worktree (nonode_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
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)