Skip to content

fix(security): read a heredoc body no program runs as data in ssh-self - #39056

Open
buluoray wants to merge 1 commit into
mainfrom
crew/slack/ssh-self-heredoc-data
Open

buluoray wants to merge 1 commit into
mainfrom
crew/slack/ssh-self-heredoc-data

Conversation

@buluoray

@buluoray buluoray commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An agent's Python edit script fed on a here-document (python3 - <<'EOF' with n = a * localhost in the body) is no longer refused as an ssh-to-self escape, while every heredoc a shell or another program could run stays refused.

sandbox-escape-ssh-self refuses python3 - <<'EOF'\nn = a * localhost\nEOF and the same script written with cat > s.py <<'EOF' and then run. Nothing on either line runs ssh. The floor reads the heredoc body as command words, so a bare * (multiplication) reads as a glob verb that could name ssh, and localhost as its target. Reported in #34754; #34755 by @Marsjohn-11 fixed it together with two parts main already has through #36992, and is now conflicting.

Why it matters

A heredoc-fed edit script is a common agent shape, so this false refusal recurs on ordinary work. The refusal sends the agent down the sandbox-escape recovery path, which is the wrong guidance for a local file edit, and the only way past it today is turning the whole rule off.

Not a goal

What changed (motivation → approach → change)

Symptom → cause → change. The ssh floor walked heredoc bodies as argv. Main's self-subcommand floor already has a reader that blanks bodies no program runs, _heredoc_data_view (argv_floor_self.py). The ssh floor now uses that same reader, unchanged, instead of a second one.

  • _judge_ssh_to_self (argv_floor_ssh.py, +18 lines) reads the line through _heredoc_data_view, run on the words as written and only then lowered, because bash matches a closing line case-sensitively (without the words as written, the view is not taken). It allows when the view blanked a body and the blanked line reaches no self host. Otherwise it reads the whole line as before, so the ssh floor only gains allows.
  • It skips the view, and reads the whole line as main does, in two shapes the view reads differently from bash:
Shape Why the view is skipped
the text holds a \r the view drops it from a tag but not from the closing line, where bash keeps it
a line holding << ends in a backslash bash joins it to the next line; the view does not
  • security.md describes the ssh floor's use of the view. The reader, the self floor and the facade are unchanged.

cat > s.py <<'EOF' … python3 s.py, a leading cd <path> &&, and Python options such as -u stay refused, as on main. #40368 tracks them, with the review findings from this PR as design notes.

Backwards compatibility

Compatible: the only verdicts that change are refused → allowed on the ssh-to-self floor, for a line whose heredoc bodies the self floor's view already reads as data and whose blanked line reaches no self host. Every other line keeps main's verdict, because the whole line is still read when the view refuses or is skipped.

Removes nothing: no deny pattern, rule id, catalog row, reader rule or operator toggle is removed or renamed.

scripts/deny_diff.py against origin/main, on every row the Security Scope Review found over this PR's rounds plus the GPT and Opus repros: 0 newly refused (32 posix rows classified).

Tests

  • test/test_denied_commands_security_ssh_self_heredoc.py: 16 allow rows (the python3 - repro, tee, quoted bodies holding an ssh line, a quoted body with a backslash-newline, tag spellings such as <<'MD' and EOF in a sentence), 12 rows where a program can run the body, 64 rows where the reader could misread the line (a body line that is the tag in another case, CRLF heredocs, << lines ending in \, x\\ or # \, case-mismatched tags, a second heredoc, wrappers, stored scripts, cd, Python options), the common-form matrix (38 rows), and test_argv_floor_imports_in_a_fresh_interpreter.
  • Related set (every test file naming _heredoc_data_view, argv_floor_self, argv_floor or denied_commands_security, plus facade mirror, listing budget and gate liveness): 5,827 passed, 19 skipped. mypy, black, isort, flake8, subprocess encoding, line cap, comment history, brand and the flake ratchet pass.
  • Determinism: the rows judge strings only: no clock, process, file or network. The fresh-interpreter import test runs one bounded child with FALLBACK_TIMEOUT_SECS.

Proof: PROVEN test/test_denied_commands_security_ssh_self_heredoc.py::test_body_no_program_can_run_is_data[python3 - <<'EOF'\nn = a * localhost\nEOF], test/test_denied_commands_security_ssh_self_heredoc.py::test_body_no_program_can_run_is_data[tee f <<'EOF' >/dev/null\nn = a * localhost\nEOF], test/test_denied_commands_security_ssh_self_heredoc.py::test_body_no_program_can_run_is_data[cat <<'EOF'\ninert\\ntext\nssh -p 22 localhost id\nEOF], test/test_denied_commands_security_ssh_self_heredoc.py::test_body_no_program_can_run_is_data[cat > release.md <<'MD'\nssh -p 22 localhost id\nMD], test/test_denied_commands_security_ssh_self_heredoc.py::test_body_no_program_can_run_is_data[cat > note.md <<'EOF'\nThe file ends at EOF.\nssh -p 22 localhost id\nEOF] (head fa59e37)

Manual verification

N/A — the floors are pure functions of the command text, and the unit rows call them directly.

Real-machine verification

N/A — the diff changes only how the argv floors read command text; it runs nothing on a machine.

Related Issues

Closes #38979

Ports the ssh-self part of #34755 by @Marsjohn-11 (credited as co-author). Reported in #34754.

Merge order: this PR merges first; #34156, which also edits argv_floor_ssh.py, then rebases onto it.

Sibling sweep

Swept: git grep -n "heredocs=True" -- src/kiro_crew/security/
Sibling: src/kiro_crew/security/argv_floor_self.py -- not affected -- its _heredoc_data_view is reused unchanged by the ssh floor
Sibling: src/kiro_crew/security/rm_floor.py -- not affected -- it already cuts bodies a shell does not read (_without_bodies)
Sibling: src/kiro_crew/security/s3_direction.py -- not affected -- it reads bodies only to tell an upload from a download
Sibling: src/kiro_crew/security/argv_rules.py -- not affected -- its command reader already keeps a body out of argv unless a shell reads it

Pattern harvest

Not generalizable: the ssh floor now reuses the self floor's heredoc reader, and the other floors already read heredoc bodies as data unless a shell runs them.

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; see the Licensing section of CONTRIBUTING.md.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision fa59e3789721bc71633f7ce60c737408bc1526d5 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 18, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/argv_floor_ssh.py

  • @buluoray comment: does not name the current head fa59e37; 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: fa59e3789721bc71633f7ce60c737408bc1526d5
- 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 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the change reuses the existing _heredoc_data_view reader rather than adding a second one, and its guards can only turn the new allow off.

Notes

  • The ssh floor's new allows are now only as safe as _heredoc_data_view's idea of "no program runs this body". That reader is now shared by two floors, so any future loosening of it widens both, and it needs a test that pins the ssh floor too.

[DESIGN-REVIEWED] fa59e37

Description read

[DESCRIPTION-READ] c880712901e12bef9af737a7d4ac20a126f109ed11a13af4481ca46c6ecc3a0a

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of fa59e3789721bc71633f7ce60c737408bc1526d5 — 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 blocks. The fix reuses the existing heredoc reader. Its two guards, for \r and for a << line ending in a backslash, cover misreads inside that reader, and the reader's other caller, the self floor, still runs without them.

Notes

  • Item 2 — symptom-level: the PR says the view "drops [\r] from a tag but not from the closing line" and "does not [join a << line ending in a backslash]". Those are defects in _heredoc_data_view (argv_floor_self.py:1349). That reader has 2 consumers (grep _heredoc_data_view(). The guard covers only argv_floor_ssh.py:1090, so 1 sibling is unfixed: _matches_self_subcommand at argv_floor_self.py:1442, which also passes lowered text, the case gap behind the cased re-read. Subtraction: move the \r and backslash early returns into _heredoc_data_view and delete the per-caller condition in _judge_ssh_to_self. That changes the self floor, which ## Not a goal excludes, so this is a deferral to security: read stored-script, cd && and Python-flag heredocs as data in the self and ssh floors #40368.

What this change ships

Inventory (4 items) — 3 justified

Intent: let an agent feed a Python or text edit script on a heredoc without a false ssh-to-self refusal (FIX).

  1. A heredoc body that no program on the line runs (python3 -, cat, tee) is no longer refused as ssh-to-self — justified
  2. Lines holding \r, or a << line ending in a backslash, keep main's whole-line reading — symptom-level: guards a shared-reader misread at one of its two callers
  3. The view is read on the cased text, so a case-mismatched closing line can't end a body early — justified
  4. The security spec and the line-budget entry describe the ssh floor's use of the view — justified

[FIRST-PRINCIPLES-REVIEWED] fa59e37

Description read

[DESCRIPTION-READ] c6e175516fe1b2fa7977cb9e46820436e87bf7638b5e6ebc2507a21b7613359f

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] fa59e37

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

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

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] fa59e37

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

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does fa59e3789721bc71633f7ce60c737408bc1526d5 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): 14 classified, 0 newly refused, 10 still allowed.
  • ubuntu-latest (platform posix): 14 classified, 0 newly refused, 10 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 change only adds an early return False (allow) to _judge_ssh_to_self. It fires only when the heredoc data view blanked a body and the blanked line reaches no ssh to this host. When its guards (a \r, a << line ending in a backslash, no cased text) apply, the line goes back to the base read, so by construction it cannot newly refuse anything. No candidate verdicts were handed to me, so no confirmed regression is claimed.

TIGHTENING: None. This is a loosening of the sandbox-escape-ssh-self argv floor in the deny-rules tier. Its threat model is unchanged: a heredoc body that a shell or program could run still counts as argv. The hunk: if (view != text_lower and "\r" not in text_lower and not any("<<" in ln and ln.endswith("\\") for ln in text_lower.split("\n")) and not _is_ssh_to_self(view, own_line=own_line)): return False. The only new refusal risk is an exception raised by _heredoc_data_view / read_commands on a << line that reaches this floor, which would fail closed. The rows below probe that path.

ADJUDICATED: 17 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE:

  • posix: heredoc commit messages, a gh pr create body inside a substitution, cat/tee/python3 - data bodies, and remote ssh/scp with heredocs. It also covers each guard the diff adds: a CRLF line, a backslash-continued << opener, and a mixed-case line that takes the cased-view path.
  • windows: Git Bash heredocs with CRLF endings, a drive-letter target path, and an ssh.exe program name. These cover the diff's one platform-sensitive assumption, the \r guard, on the host where CRLF is normal.
  • any: one control row with no heredoc.
  • Not probed: PowerShell here-strings (@'…'@). The diff assumes bash heredoc syntax only and does not read them, so they keep the base behaviour.

UNADJUDICATED: The documentation hunk describes the git add plain-line carve-out (argv_rules.is_one_plain_git_add_line). That carve-out already exists in BASE at argv_floor_ssh.py:1178 and this diff does not change it. One row probes it anyway (git add s* README.md && git commit -F - <<'EOF'…).

[SCOPE-REVIEWED] fa59e37

@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Nov 18, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 19, 2026
@buluoray
buluoray force-pushed the crew/slack/ssh-self-heredoc-data branch from b12f078 to 39f7aec Compare November 19, 2026 11:29
@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 19, 2026
@buluoray
buluoray force-pushed the crew/slack/ssh-self-heredoc-data branch from 39f7aec to 29c4c1f Compare November 20, 2026 08:00
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 20, 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 20, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 29c4c1f
  • What rule changed: the sandbox-escape-ssh-self argv floor. A new module, src/kiro_crew/security/argv_floor_ssh_heredoc.py, cuts a line's here-document bodies out when no program on the line can run one: every program is a direct cat, tee or cd, or Python reading its program from stdin or a file with no -c/-m. _judge_ssh_to_self allows the line when that cut reading reaches no self host, and otherwise reads the whole line exactly as main does. Ported from fix(security): stop the ssh-self and -d @ gates refusing inert lines #34755 by Marsjohn-11. argv_floor.py only lists the new owner and names.
  • Before -> after (what was allowed/blocked, now): before, python3 - <<'EOF' with n = a * localhost in the body, and the same body written with cat > s.py <<'EOF' and then run, were refused (the body's * read as a glob verb naming ssh). Now they are allowed, as are python3 -u -, tee f <<'EOF' >/dev/null and cd /w && python3 - <<'EOF' forms. Still refused: bash <<'EOF', sudo sh <<, cat <<'EOF' | bash, source /dev/stdin <<, python3 -c '…' <<, perl -e '…' <<, python3 runner.py <<, a body written to a script a shell then runs, an unquoted body holding $(…) or a backtick, a real ssh outside the body, and every line with a wrapper, an assignment prefix, a pipe, two heredocs, a reused or non-plain tag, compound syntax or a backslash-newline.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): an ssh to this host hidden inside a heredoc body that some program on the line runs as a shell script would be allowed. The cut happens only when every program on the line is one of the listed non-shells, so a shell, interpreter -c, wrapper or pipe keeps main's reading. Python running a program that itself opens ssh stays the OS network fence's residual (Sandbox network fence: block loopback sshd from inside the sandbox (netns or connect-filter on self:22) #9806), as python3 -c is today. No line main allows becomes refused: the whole line is still read when the cut reading refuses.
  • Evidence checked (which sandbox result proves it): read-only is_denied rows only; no ssh was run. The 5 allow rows were refused on main; prove.py reverted the production hunks and they went red (PROVEN on b12f078, the head before a rebase onto main that changed only the module ceilings in test_mcp_listing_import_budget.py). Removing the call turns the 5 allow rows red; dropping each fail-closed rule turns its own refuse row red, except the keyword-first-word and one-tag rules, which other checks already cover.
  • No regression:
    • Tools still work (which tools/commands were run, result): the existing allow row test_a_quote_inside_a_substitution_rows_that_stay_allowed (a heredoc followed by a # comment naming ssh) stays allowed, as on main.
    • Backward compatible (old config / old data / old callers still work, how checked): no config, data or API change. The only caller, deny_gate.py, reaches the floor through the argv_floor facade, which still serves every name main serves (facade mirror tests pass).
    • Existing tests (which suites passed on this head): locally on 29c4c1f, test_denied_commands_security_ssh_self.py, test_denied_commands_security_ssh_self_heredoc.py, test_security_gate_liveness.py and test_mcp_listing_import_budget.py (704 passed together, with main's added modules and this PR's module counted). The CI Backend Tests shards and AI lanes rerun on this head.
  • How to undo: revert the squash commit of fix(security): read a heredoc body no program runs as data in ssh-self #39056; the floor goes back to reading heredoc bodies as argv, with no data to migrate.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 21, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, but it is held at tier pending: being reviewed.

The PR adds a pre-check to the ssh-to-self floor. It cuts out heredoc bodies only when every command on the line is a plain cat, tee or cd, or Python reading stdin or a file. The line must also have exactly one plain-word tag that appears exactly twice ignoring case, no backslash-newline, no compound or arithmetic marks outside the body, no $ or backtick in an unquoted body, and no piped heredoc command. The cut reading can only allow; anything else falls back to main's whole-line reading. The shared reader (read_commands) lists every command bash would run, comments included, so an ssh command anywhere keeps the whole line refused. Python running ssh from a body matches how main already treats python3 -c, which a test pins, and fits AGENTS.md's rule that the OS sandbox is the real control. Recursion depth and caching fail closed. Allow and refuse rows are tested, CI is green, and I found no line bash runs as ssh-to-self that the change newly allows.

Tier: pending: being reviewed.

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

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This PR needs one change before it can merge. The head is correct on its own base, but merging it onto current main breaks the security package import.

  1. src/kiro_crew/security/argv_floor_ssh_heredoc.py:27: after #39757 merged, main defines _HEREDOC_DATA_PROGRAMS = frozenset({"cat", "tee"}) in argv_floor_self.py:1144. That module is also an argv_floor facade owner, and argv_floor.py already lists the name in its manifest. This PR binds the same name to a different set ({"cat", "tee", "cd"}) in a second owner. The merge has no text conflict. But in the merged tree, import kiro_crew.security.argv_floor raises RuntimeError: ... names bound to different objects across the family are ['_HEREDOC_DATA_PROGRAMS'], but the facade declares [] from _facade_mirror.install. So kiro_crew.security fails to import, the gateway cannot start, and every backend test fails at collection. CI passed only because this head's merge-base predates #39757. Smallest fix: rebase onto main, then rename this module's set (for example _SSH_HEREDOC_DATA_PROGRAMS) in the module and in the TYPE_CHECKING manifest line in argv_floor.py. The two sets differ, so they cannot share one object. In a scratch copy of the merged tree, that rename alone made the import work, and the related test files passed. Then let CI run again on the rebased head.

Optional:

  • #39757 added a second heredoc-as-data reader for the self floors (_heredoc_data_view in argv_floor_self.py). It accepts a python - body only when the body parses as inert. This floor accepts any python - body, because Python running ssh is already this floor's documented residual. Could the security.md paragraph state that difference? Also, the body's Sibling sweep and Pattern harvest were written before #39757 landed. Could they be updated to match current main?
  • Several fail-closed guards stay green when they are deleted one at a time. These are the paren, backtick, [[ and $[ marks, the backslash-CRLF check, not docs, and the body-backtick check. _runs_no_body catches every case, so I found no bypass. The comment on the ((cat<<z)) row says it pins the left-shift reading, but it actually pins _runs_no_body. The mutation sentence in the Tests section could list these guards.

Good: the pre-pass can only turn a refusal into an allow. It also cuts the << and its tag together with the body, so lines after the closing tag are still read as commands.

@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 21, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for moving both floors onto one heredoc reader. Two problems in the new code need fixing before this can merge.

  1. src/kiro_crew/security/argv_floor_heredoc_data.py:349 (_join_opener_continuations, which uses _backslash_newlines at line 413): the join treats every backslash before a newline on a << line as a line continuation. It does not check for an escaped backslash or a # comment. Take cat <<'EOF' x\\ or cat <<'EOF' # note \, then EOF, then ssh -p 22 localhost id or kirocrew restart, then EOF. The join glues the real closing EOF onto the opener, and the reader blanks the next line as body. Bash closes the heredoc at the first EOF and runs that line. Through is_denied, main refuses all of these (sandbox-escape-ssh-self, self-protection-restart) and this head allows them. That breaks the goal's rule that every heredoc a shell could run stays refused. Smallest fix: join only the plain <<[-]TAG + blanks + single \ opener form that your continuation rows need. For any other backslash-newline on an opener line, return text_lower so every body is kept. Add refuse rows for the escaped and comment forms on both floors.
  2. src/kiro_crew/security/argv_floor_heredoc_data.py:274-281: the tag-count check runs .lstrip("\t") on every tag and every line, even when the heredoc is not <<-. Example: a cat > scripts/upgrade.sh <<'EOF' body that holds its own tab-indented cat <<-EOF ... \tEOF, plus a kirocrew restart line. The check counts two eof lines for one tag, keeps the body as argv, and refuses the store. Main allows it, so this is a new false refusal that the Backwards compatibility list does not mention. Removing the lstrip from both lines leaves all 220 rows in the two test files green, so no test pins this behaviour. Smallest fix: strip leading tabs only on lines inside or closing a <<- body. Add allow rows for the nested case and one refuse row where a tabbed tag really closes a <<- body.

Earlier review item: the duplicate _HEREDOC_DATA_PROGRAMS binding is fixed on this head. The set now has one definition in argv_floor_heredoc_data.py, and argv_floor_self re-exports that same object.

Optional:

  • The Sensitive Change Review comment and the "0 newly refused" deny_diff claim describe head 29c4c1f and a module that no longer exists. Could you re-post both for the fixed head?
  • argv_floor_self.py:33-55 re-exports 21 names, but only _heredoc_data_view and _python_body_is_data have a reader through that path. The other 19 lines could go.
  • Changing the CRLF join width at line 355 to 2 turns no row red. A CRLF refuse row (cat <<'EOF' \ CRLF | bash ...) would pin it.

@buluoray
buluoray force-pushed the crew/slack/ssh-self-heredoc-data branch from 3d43360 to c948699 Compare November 21, 2026 07:33
@buluoray

Copy link
Copy Markdown
Contributor Author

resolution: removed _join_opener_continuations; no line joining

  • span=f926264d2d58 _join_opener_continuations joins after an escaped \\ or a \ in a comment

fixed in c948699: the reader no longer joins any line (_join_opener_continuations and _MAX_OPENER_JOINS are deleted). It reads the text as typed, as main's reader does. The ssh floor skips the heredoc view and reads the whole line when a line holding << ends in a backslash (_opener_line_ends_in_backslash).

All three of your commands (cat <<'EOF' x\\, cat <<'EOF' # \, and the kirocrew restart variant) are refused on both floors at c948699, as on main. They are rows in test_opener_line_backslash_not_joined_keeps_hidden_command and test_line_the_reader_may_misread_keeps_bodies_as_argv, and each was allowed on 3d43360.

@buluoray

Copy link
Copy Markdown
Contributor Author

resolution: removed _join_opener_continuations; no line joining

  • span=9e6c68896eda Join only actual shell continuations

fixed in c948699: the reader joins no lines at all now; _join_opener_continuations is deleted. It reads the text as typed, as main's reader does, and the ssh floor reads the whole line when a line holding << ends in a backslash. An escaped \\ or a commented \ at the end of an opener line is refused on both floors, as on main.

@buluoray

Copy link
Copy Markdown
Contributor Author

resolution: narrowed; the ssh floor skips the heredoc view on any \r

  • span=4fda723f6f7e CRLF heredocs hide an executable SSH-to-self command

fixed in bb96a10: _judge_ssh_to_self takes the heredoc view only when the text holds no \r and no line holding << ends in a backslash; otherwise it reads the whole line, as main does. The shared reader is back to main's, unchanged, and the stored-script, cd && and Python-option widening is removed (tracked in #40368).

Your rows (quoted and unquoted cat, cat <<-EOF, tee, and a leading cd . && cat, each with EOF\r before ssh -p 22 localhost id) are refused at bb96a10, as on main. They are rows in test_line_the_reader_may_misread_keeps_bodies_as_argv, and each was allowed on c948699.

@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 21, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

The second "Not a goal" bullet is edited, with the Lead's OK: from round 4 on, this PR no longer changes the self-subcommand floor. The ssh floor reuses _heredoc_data_view unchanged. The old bullet pointed at self-floor changes under Backwards compatibility that are gone. The deferred cases (stored scripts, a leading cd <path> &&, Python options) now point at #40368. Goal and "Why it matters" are unchanged.

@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 21, 2026
The ssh-to-self floor read every here-document body as command words,
so a Python edit script fed on a heredoc (`n = a * localhost`) read as
a glob verb naming ssh and its target, and was refused.

The ssh floor now reads the line through the heredoc view the
self-subcommand floor already uses, `_heredoc_data_view`, unchanged.
It allows the line when the view blanked a body and the blanked line
reaches no self host. The view reads the words as written, because
bash matches a closing line case-sensitively. The floor skips the
view and reads the whole line as before when the text holds a
carriage return or a line holding `<<` ends in a backslash, two
shapes the view reads differently from bash.

Ported from #34755 by Marsjohn-11.

Closes #38979

Co-authored-by: Marsjohn-11 <74795701+Marsjohn-11@users.noreply.github.com>
@buluoray
buluoray force-pushed the crew/slack/ssh-self-heredoc-data branch from bb96a10 to fa59e37 Compare November 21, 2026 09:35
@buluoray

Copy link
Copy Markdown
Contributor Author

resolution: narrowed; the ssh floor finds bodies on the words as written

  • span=4fda723f6f7e Lowercased heredoc delimiters hide executable SSH-to-self

fixed in fa59e37: _judge_ssh_to_self runs _heredoc_data_view on the words as written (raw_text, used only when its lowered form equals the floor's text) and lowers the view afterwards, so a body closes only on the tag as written, as in bash. Without the words as written the view is not taken. The \r and opener-backslash guards stay.

Your rows (cat and tee, single-quoted, double-quoted and unquoted tags, <<-, and >, <, 2> tails, each with a lowercase eof body line before EOF and the ssh line) are refused at fa59e37, as on main. They were allowed on bb96a10. They are rows in test_line_the_reader_may_misread_keeps_bodies_as_argv. The self floor's own use of the lowered reader is unchanged by this PR and is outside its goal.

@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 21, 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 21, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

This review found no blocking problem on fa59e37. It cannot approve yet, because PR Readiness is red. The Sensitive Change Review check says the template comment names old head 29c4c1f. That comment also describes argv_floor_ssh_heredoc.py, which this head no longer has, and a wider allow set than this head ships. Please post the template again for this head. Say that the only change is the early allow in _judge_ssh_to_self through the unchanged _heredoc_data_view, guarded on \r and on a << line that ends in a backslash, and that it turns refusals into allows only. A maintainer approval on this head then replaces the earlier change requests.

Earlier review items:

  • Duplicate _HEREDOC_DATA_PROGRAMS binding: fixed. There is one definition, in argv_floor_self.py:1144, and the second module is gone.
  • _join_opener_continuations joining after an escaped or commented backslash: fixed. The joiner is deleted, and a << line ending in a backslash keeps main's whole-line reading.
  • Unconditional lstrip("\t") in the tag count: fixed. That module is deleted, and the shared reader is the same as on main.

What the review checked: reverting the 18-line hunk turns 54 of 131 rows red, including every allow row. Removing the \r guard, the backslash guard, or the cased-text reading each turns its own rows red. A differential fuzz run against real bash found no allow that is new on this head where bash then runs ssh. The Security Scope lane reports 0 newly refused. Done well: the PR reuses the one existing heredoc reader, and the allow re-runs the full ssh judge on the blanked line, so a wrong view can only fall back to main's reading.

Optional:

  • argv_floor_ssh.py:1093: a NUL byte on a closing line (EOF\x00) makes the view blank the next line, but bash fed from a file or stdin drops the NUL and runs it. Adding "\x00" not in text_lower next to the \r check keeps main's reading for that line. No shipped path hands a NUL to bash, so this does not block.
  • docs/system-specs/modules/security.md: the view blanks a python - body only when _python_body_is_data proves it inert, so a read-modify-write edit script (p.read_text() / p.write_text(t)) is still refused. One clause saying so would match the code.
  • argv_floor_ssh.py:1090: the "no cased text, so no view" branch has no pin. Loosening it turns 0 of 131 rows red. A row reached through a nested read with a case-mismatched tag pair would pin it. A rebase onto current main would also drop the two unrelated security.md hunks from the diff view.

@KiroCrewCaptain
KiroCrewCaptain dismissed their stale review November 21, 2026 10:44

Withdrawn: every item in this review is fixed or answered on the current head (see the follow-up comment). Other holds on this PR are listed there.

@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: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 21, 2026

This branch has not been deployed

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

Labels

readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ssh-self floor refuses a Python edit script fed on a heredoc

2 participants