Skip to content

fix(security): stop the ssh-self and -d @ gates refusing inert lines - #34755

Closed
Marsjohn-11 wants to merge 2 commits into
kirodotdev:mainfrom
Marsjohn-11:fix/deny-heredoc-date-fp
Closed

Marsjohn-11 wants to merge 2 commits into
kirodotdev:mainfrom
Marsjohn-11:fix/deny-heredoc-date-fp

Conversation

@Marsjohn-11

@Marsjohn-11 Marsjohn-11 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An agent's Python edit script fed on a here-document, and a date -d @<epoch> conversion chained or piped with programs that run nothing, are no longer refused as an ssh-to-self escape or a curl upload, and every exfil-gate refusal names the rule and the span it matched.

Reported in #34754. Two gates refuse commands that run no ssh and send nothing:

  • sandbox-escape-ssh-self refuses python3 - <<'EOF'\nn = a * localhost\nEOF: the floor reads the heredoc body as argv, so a bare * (multiplication) followed by a self-host word reads as a glob verb naming ssh and its target. The same happens when cat writes the script to a file the line then runs.
  • data-exfil-curl-file-body (-d @) refuses date -u -d @N && echo ok, TZ=UTC date -d @N, date -d @N | cat, echo "$(date -u -d @N)" and date --help | grep -- '-d @'. fix(security): let inert date/grep pass the curl file-body exfil deny #18392 carved out only a lone date command.
  • The exfil-gate refusal is one line naming a substring, with no rule id and no position, so a false match cannot be reported precisely.

Why it matters

A refusal stops the agent's turn and sends it down the exfiltration or sandbox-escape recovery path, which is the wrong guidance for a local file edit or a time conversion. A heredoc-fed edit script is a very common agent shape, so the ssh-self false refusal recurs on ordinary work, and the only escape today is turning the whole rule off.

Not a goal

What changed (motivation → approach → change)

Symptom → cause → change.

  • ssh-self. Cause: _self_token_frames puts every heredoc body into the frame's flat tokens, and _is_ssh_to_self walks them as argv. Change: argv_floor_ssh._heredoc_bodies_as_data runs first and cuts the bodies out (rm_floor._without_bodies, read through read_commands(..., heredocs=True)) only when no program on the line can run one. Every program must be a directly named cat, tee, cd, or Python reading its program from stdin (python3 -) or a file, with no -c/-m; a wrapper (env, flock, sudo), an assignment prefix or an unresolved program keeps the bodies. The text outside the bodies must hold no arithmetic or compound syntax (a paren, brace, backtick, [[ or $[, or a command starting with let or a shell keyword), because there << can be a shift, as in ((cat<<z)). A backslash-newline anywhere in the text keeps the bodies too, because it can change a heredoc's delimiter. Every heredoc tag must be a plain word (letters, digits or underscores, bare or wholly in one pair of quotes); a $'...' or partly quoted tag keeps the bodies. The line must hold exactly one heredoc, and its tag must appear nowhere else in the text in any letter case, since the floor reads lowered text and bash matches the delimiter case-sensitively. No heredoc command may be piped, and no unquoted body may hold a $ or backtick, which bash expands even for cat. Any other line keeps the current reading, so bash <<EOF, cat <<EOF | bash, source /dev/stdin, perl -e 'system(<STDIN>)', python3 -c '...os.system(sys.stdin.read())', a script file a shell then runs and an unquoted $(ssh localhost) body all stay refused. This is the same "a body is data unless a shell reads it" rule argv_rules._commands and rm_floor already apply, made stricter.
  • -d @. Cause: the carve-out requires denied_rules._exception_eligible, which refuses any separator. Change: exfil_bash._inert_line_allows is tried when that fails. It reads the shared reader's commands (a double-quoted $(…)'s commands included) and allows the line only when every command starts with a carve-out verb or echo/cat, after an optional TZ/LANG/LC_* prefix (never PATH or LD_PRELOAD). There must be no redirection, no live $ or backtick left in any word (variables, unquoted substitutions, ${ …; } funsubs), and only ; & && || | or newline separators. printf is not inert, because printf -v assigns a variable. With no other program on the line, no HTTP client can run. _data_at_carveout_allows is unchanged, so its parity test still holds.
  • Diagnostics. exfil_bash._exfil_denial appends the existing diagnostics line (component exfil-gate, rule id, span, shape, never the matched bytes) to every exfil refusal. When lowercasing changes the text's length (İ), the span is the whole command. Line one is unchanged, so deny_guidance and every reader of it see what they saw before. security.md records why this one pattern tier passes a diagnostic.

Backwards compatibility

Compatible: the only verdicts that change are refused → allowed for the shapes above; every refusal keeps its first line byte-for-byte and gains a last line, which readers that stop at line one never see.

Removes nothing: no deny pattern, rule id, catalog row or operator toggle is removed or renamed, and every previously pinned denial still holds.

Tests

  • test/test_denied_commands_security_ssh_self.py::test_heredoc_body_read_as_data_is_not_argv: the four false refusals (stdin program, cd && python3 -u -, cat to a script then python3 runs it, tee with a redirect) are allowed.
  • ...::test_heredoc_body_that_can_run_stays_argv: 13 shapes where a shell, source, an interpreter running stdin, a pipe, a script a shell runs, an unquoted substitution body, or a real ssh outside the body is involved stay refused.
  • test/test_exfil_carveouts.py::TestCompoundInertLine: the six date lines are allowed, and 11 lines carrying a program that can send (| python3, && curl, PATH=, LD_PRELOAD=, substitution in a prefix, quoted curl substitution, a redirect, $X, a funsub, a quoted 'date', a heredoc) stay refused.
  • ...::TestDenialNamesItsRule: the file-body refusal names rule=data-exfil-curl-file-body component=exfil-gate span=<a>..<b> with no file name or host in the line, and each other branch names its own row.
  • test/test_security_gate_liveness.py: the package line budget is re-pinned to the re-measured total, with its justification entry.

Proof: PROVEN test/test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_heredoc_body_read_as_data_is_not_argv[python3 - <<'EOF'\nn = a * localhost\nEOF], test/test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_heredoc_body_read_as_data_is_not_argv[cd /work && python3 -u - <<'PY'\nfor p in paths: p.write_text(t * 127.0.0.1)\nPY], test/test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_heredoc_body_read_as_data_is_not_argv[cat > /tmp/edit.py <<'EOF'\nn = a * localhost\nEOF\npython3 /tmp/edit.py], test/test_denied_commands_security_ssh_self.py::TestSandboxEscapeSshSelf::test_heredoc_body_read_as_data_is_not_argv[tee /tmp/edit.py <<'EOF' >/dev/null\nn = a * localhost\nEOF], test/test_exfil_carveouts.py::TestCompoundInertLine::test_inert_compound_line_allowed[date -u -d @1700000000 && echo ok] (head 5c0a379)

Also run on this head: the 37 security test files (test_denied_commands_security*, test_exfil*, test_deny_*, test_mcp_cron_security*, test_argv*, test_shell_commands_reader, test_security_gate_liveness), 3443 passed, plus test_flake_pattern_ratchet.py. black, isort, flake8 and mypy are clean on the changed files, and scripts/docs-lint.sh passes.

Manual verification

N/A — unit coverage sufficient: both gates are pure functions of the command text, called directly by the tests above through the public is_denied / audit_bash_exfiltration entry points.

Related Issues

Closes #34754

Sibling sweep

Swept: git grep -n "_self_token_frames|_shell_payload_walk|heredocs=True" -- src/kiro_crew/security/
Sibling: src/kiro_crew/security/argv_floor_ssh.py -- changed here
Sibling: src/kiro_crew/security/argv_floor_self.py -- tracked in #34754 (the self-kill and mint floors read the same frames; left out of scope)
Sibling: src/kiro_crew/security/argv_rules.py -- not affected -- it already reads a body as commands only when a shell is the program
Sibling: src/kiro_crew/security/rm_floor.py -- not affected -- it already reads only shell-run bodies and unquoted body substitutions
Swept: git grep -n "_data_at_carveout_allows|_exception_eligible" -- src/kiro_crew/security/
Sibling: src/kiro_crew/security/exfil_bash.py -- changed here
Sibling: src/kiro_crew/security/denied_rules.py -- not affected -- its exception gate is left as it is, so the rm deny-exception does not widen

Pattern harvest

Rule candidate: review-prompt
Pattern: a shell-grammar floor that walks a here-document body as argv without asking which program on the line consumes it

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

Sensitive change review

This is a fork PR on a sensitive path, which the gate refuses whatever the record says, so this filled template is here for whoever takes it over.

  • What rule changed: the ssh-self floor no longer walks a here-document body as argv when no program on the line can run it, and the -d @ date carve-out also holds for a line of inert commands. Exfil refusals gain a diagnostic line.
  • Before -> after (what was allowed/blocked, now): before, python3 - <<'EOF' edit scripts and date -d @N in a chain, pipe, quoted substitution or locale prefix were refused. Now they are allowed, and every shape where a shell or interpreter can run the body, or another program can send, is still refused.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a line the readers misjudge as inert could run ssh to this host or a curl upload. The allow sets are closed, any unread construct keeps the deny, and the OS sandbox and network fence still apply.
  • Evidence checked (which sandbox result proves it): gate-level only, no sandbox change. The 13 runnable-body shapes and 11 sending lines are pinned as refused on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): is_denied and audit_bash_exfiltration were run on the reported commands and on every pinned denial in the security suites, with the expected results.
    • Backward compatible (old config / old data / old callers still work, how checked): no rule, pattern or toggle changed, and line one of every refusal is unchanged; test_deny_guidance.py passed.
    • Existing tests (which suites passed on this head): the 37 security test files listed above (3443 passed), plus the flake-pattern ratchet.
  • How to undo: revert this single commit. No data, config or format migrates.

Contribution License Agreement

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

@Marsjohn-11
Marsjohn-11 requested review from a team and KiroCrewCaptain as code owners November 10, 2026 19:45
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) 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 10, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Hi @Marsjohn-11, a heads-up on overlap. We replayed 132 recorded refusals from 2026-10-28 to 2026-11-12. Six were the date -d @<epoch> case inside a loop or chain, which this PR also covers.

We have a structural version of the date fix ready, not opened as a PR. It reads the shared reader's commands (read_commands), blanks each date command's own words, and allows only when no -d @-family text is left. It refuses when:

  • any unquoted paren appears (function definition, subshell, $(...));
  • any command is alias/function/eval/source/./export/hash/env/exec/command/declare and similar;
  • any word holds PATH=;
  • a date word holds a substitution, quote or escape.

The existing test_exfil_carveouts.py bypass cases (alias date=curl; date -d @f URL, eval 'date(){...}', date -d @0 "$(curl -d @f ...)") stay refused. On the recorded set it frees 5 of 6. The sixth is date -d @$(gh api ...), which it refuses on purpose.

This PR is yours. Are you still working on it? It currently conflicts with main. You are welcome to take any of the above. If it stays quiet past 2026-11-18, we will open the date part on a branch of this repository, crediting this PR. A branch here also lets Sensitive Change Review run, which a fork cannot.

The ssh-self floor read every here-document body as argv, so a Python
edit script fed on stdin (python3 - <<'EOF' ... a * localhost ...)
read as a glob verb naming ssh and its target, and was refused. A body
is now cut out only when no program on the line can run it: cat, tee,
cd, or Python reading its program from stdin or a file, no heredoc
command piped, and no unquoted body holding $ or a backtick. Any other
line keeps every body as argv.

The -d @ date carve-out only held for a single plain command, so
date -d @n && echo, date -d @n | cat, echo "$(date -d @n)", a TZ=
prefix and date --help | grep -- '-d @' were refused as curl uploads.
A whole line is now carved out when every command in it starts with
date/grep or echo/printf/cat, with no redirection, no live $ or
backtick left in a word, and only list or pipe separators.

Each exfil-gate refusal now ends with the refusal diagnostic line:
the catalog rule id and the matched span, never the matched text.
@buluoray
buluoray force-pushed the fix/deny-heredoc-date-fp branch from 5c0a379 to cf66a40 Compare November 13, 2026 22:47
@buluoray

Copy link
Copy Markdown
Contributor

Thanks @Marsjohn-11 for this fix. We took the PR over to get it green, since it had conflicts with main and sat idle:

  • Rebased your commit onto current main. It is unchanged in substance and still authored by you; the three conflicts (argv_floor_ssh.py, security.md, the package line budget) were resolved by keeping both sides.
  • Added one small commit on top that drops an issue number from a docstring, which the comment-history gate refuses.

Your credit stays on the commit. We will drive CI and review from here.

@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 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed c026d65b5545b1f09516396d46e76daf44fdf0f2 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] c026d65

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 13, 2026
@buluoray
buluoray force-pushed the fix/deny-heredoc-date-fp branch from cf66a40 to 1f67326 Compare November 14, 2026 00:10
@buluoray

Copy link
Copy Markdown
Contributor

span=4fda723f6f7e
self-added: yes
mechanism: heredoc-body exemption classified the reader through the best-effort wrapper stripper and skipped an unresolved chain

  • Wrapper stripping removes executable heredocs from the SSH-self check

fixed in 1f67326: _heredoc_bodies_as_data no longer calls _argv_rules._program_args; only a directly named cat, tee, cd or Python reader qualifies.
Any wrapper (env --split-string=..., flock --command=..., sudo), assignment prefix or empty/unresolved argv returns the text whole, so the body stays argv and is judged.
env --split-string='bash -s' cat <<'EOF' and flock --command=bash /dev/null <<'EOF' with an ssh body are refused; pinned in test_denied_commands_security_ssh_self.py. The plain cat <<'EOF' row stays allowed.

@buluoray

Copy link
Copy Markdown
Contributor

span=e1ef3b066cec
self-added: yes
mechanism: exfil diagnostic took match offsets from the lowercased text and applied them to the original

  • Lowercased offsets point diagnostics at the wrong text

fixed in 1f67326: when command.lower() changes the length (e.g. İ), _exfil_denial reports the whole command as its span instead of shifted offsets.
The refusal verdict and line one are unchanged; test_expanding_lowercase_diagnostic_covers_file_body_flag pins that the span covers -d @ and that no header or host text appears in the line.

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision d695c157f261240fbfaaf1a1c2e77fbfc079b7ab 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 14, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 50ad22b1aedc6828d3231ba4bfcbb8a796d9d583 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design-level blocker: both relaxations are closed allowlists that keep the deny on anything they cannot read, and the added diagnostic line leaves line one byte-identical for every reader.

Notes

  • _heredoc_bodies_as_data checks one fail-closed condition after another (compound marks, continuations, tag shapes, unquoted $), which is what you get when each review round finds a bypass and patches it. If another bypass turns up, narrow the allowlist (for example, quoted tags only, no cd/tee) instead of adding a sixth condition.
  • The cat > f.py <<EOF … python3 f.py allow relies on the stated non-goal that interpreter indirection is the network fence's job (Sandbox network fence: block loopback sshd from inside the sandbox (netns or connect-filter on self:22) #9806). That is consistent with how python3 -c is treated, so keep the two policies aligned.

[DESIGN-REVIEWED] 50ad22b

Description read

[DESCRIPTION-READ] be2f32df3c64de9f4d4802de167232c72ee94805539604ee12dad2f551540c51

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of d695c157f261240fbfaaf1a1c2e77fbfc079b7ab via the fork AI-review pipeline — 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

Both false refusals come from issue #34754 and have tests. The heredoc cut is applied to one of the four consumers of the shared frame walk. The other three are excluded by the Not-a-goal, so that is a note.

Notes

  • Item 1 — symptom-level: the description names the cause: "_self_token_frames puts every heredoc body into the frame's flat tokens". But the cut only goes in at _is_ssh_to_self. A grep for _self_token_frames( finds 4 consumers, and the other 3 (argv_floor_self.py:371, :1144, :1229) still read bodies as argv. This is deferred under the Not-a-goal ("self-kill and credential-mint floors"). There is no subtraction until the cut moves into the producer.
  • Item 3 — rides along: the diff rewrites the recorded rule "the pattern tiers do not, and a plain catalog refusal stays exactly one line" to "The one pattern tier that passes one is the exfil gate". The false refusals in ssh-self and -d @ exfil gates refuse inert commands: heredoc bodies read as argv, date outside a lone command #34754 are fixed without it. Subtraction: delete _exfil_denial and keep the one-line returns.

What this change ships

Inventory (5 items) — 3 justified

Intent: stop an agent's heredoc edit scripts and chained date -d @ conversions from being refused as ssh-to-self or a curl upload. This is a FIX.

  1. A Python, cat or tee line fed by a heredoc is no longer refused as ssh-to-self — symptom-level: 3 of 4 frame consumers left
  2. date -d @N chained, piped, locale-prefixed or inside a quoted $(…) with echo/cat is no longer refused — justified
  3. Every exfil-gate refusal gains a last line naming the rule id and span — rides along; reverses a recorded spec rule
  4. Command-lookup changers (hash, enable, declare, export…) before date -d @ stay refused, and new tests pin that — justified
  5. The package line budget goes from 36,000 to 36,160 — justified

[FIRST-PRINCIPLES-REVIEWED] d695c15

Description read

[DESCRIPTION-READ] f5eec05d7581b91146def512eea1e77fb6ab62157a9640510a29c4525deda49b

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

Copy link
Copy Markdown
Contributor

Security Scope Review (fork) — ✅ PASS

Which legitimate operations does c026d65b5545b1f09516396d46e76daf44fdf0f2 newly refuse? Model proposes, scripts/deny_diff.py decides — updated in place on each push. A script-confirmed regression blocks PR readiness.

adjudicated, zero confirmed regressions

Scope-Verdict: PASS

Reason: This change mostly loosens the deny composite. It adds two carve-outs (_heredoc_bodies_as_data on the ssh-self floor and _inert_line_allows on the -d @ exfil rule) and a diagnostic line on exfil refusals. No pattern is broadened, and the harness gave me no confirmed newly-refused row. New refusals could only come from the new helpers failing closed, or from the spliced body-free text matching the ssh walk where the full text did not. The 15 candidates probe that boundary.

TIGHTENING: None in the refusal set. The only change on a refusal path is the exfil gate's refusal text, which now carries a rule id and span line (return _exfil_denial(reason, rule_id, command, (start, start + len(pat)))). The nearest thing to a new guard is the fail-closed admission inside the new heredoc carve-out (if ("\\\n" in text_lower ... or len(tags) != 1 ... ): return text_lower). That only decides whether text is removed before _is_ssh_to_self reads it, so it can keep a refusal but not add one, unless removing the bodies makes adjacent text match.

ADJUDICATED: 15 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: posix (11 rows): heredoc shapes with cat/tee/python3 -/cd && (quoted and unquoted tags, a heredoc followed by a command on the next line), date -d @ epoch conversions chained by ; and fed by xargs, a grep for the literal flag, curl GET and inline -d posts, and a remote ssh one token off the self-target threat. These cover the POSIX shell syntax the diff reads: <<, separators, locale prefixes and $/backtick liveness. windows (3 rows): curl.exe, a PowerShell Get-Content | Select-String read, and %TEMP%\ with --body-file. These cover the .exe name, the \ separators and %VAR% on the exfil and ssh-floor tiers. The diff assumes a POSIX shell's heredoc and TZ=/LANG= prefix grammar, and Windows has no heredoc, so no Windows heredoc row is possible. No any rows were written, because every candidate names an executable or a path.

UNADJUDICATED: The refusal-text change (exfil_bash._exfil_denial appends a Refusal diagnostic: line) is not a deny decision, so no shell classification can measure it. It changes the string that RecoveryCard.tsx (per-line regex /Blocked by security policy:\s*(.+?)\s*$/gm), chat_runner display and the _denied_by test helper consume. Path: audit_bash_exfiltration → the deny composite's exfil tier → refusal string → the chat recovery card. Inputs I would have submitted: any exfil refusal, such as a curl file-body upload, checked to confirm the card still extracts exactly one pattern and does not read the diagnostic line as a second one. The spec says the line shares no prefix with DENY_REASON_PREFIX, and nothing here could check that.

[SCOPE-REVIEWED] c026d65

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 12 classified, 0 newly refused, 9 still allowed.
  • ubuntu-latest (platform posix): 12 classified, 0 newly refused, 9 still allowed.
  • windows-latest (platform windows): 3 classified, 0 newly refused, 3 still allowed.

No candidate flipped from allowed to refused.

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed c026d65b5545b1f09516396d46e76daf44fdf0f2 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] c026d65

@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 14, 2026
@buluoray
buluoray force-pushed the fix/deny-heredoc-date-fp branch from 1f67326 to 4928263 Compare November 14, 2026 00:47
@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 14, 2026
iamwhatever pushed a commit that referenced this pull request Nov 14, 2026
The -d @ date carve-out only held for a single plain command, so
date -d @n && echo, date -d @n | cat, echo "$(date -d @n)", a TZ=
prefix and date --help | grep -- '-d @' were refused as curl uploads.
A whole line is now carved out when every command in it starts with
date/grep, echo or cat, with no redirection, no live $ or backtick
left in a word, and only list or pipe separators. printf is never
inert: printf -v 'BASH_CMDS[date]' rebinds the date verb.

Each exfil-gate refusal now ends with the refusal diagnostic line:
the catalog rule id and the matched span in the command as
submitted, never the matched text.

The ssh-self heredoc reader from #34755 is left out: review found
it misreads arithmetic, substitutions and copied shells, so the
ssh-self floor keeps its current reading until a real shell AST.

Supersedes #34755.

Co-authored-by: John Marshall <74795701+Marsjohn-11@users.noreply.github.com>
@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
iamwhatever pushed a commit that referenced this pull request Nov 14, 2026
The -d @ date carve-out only held for a single plain command, so
date -d @n && echo, date -d @n | cat, echo "$(date -d @n)", a TZ=
prefix and date --help | grep -- '-d @' were refused as curl uploads.
A whole line is now carved out when every command in it starts with
date/grep, echo or cat, with no redirection, no live $ or backtick
left in a word, and only list or pipe separators. printf is never
inert: printf -v 'BASH_CMDS[date]' rebinds the date verb.

Each exfil-gate refusal now ends with the refusal diagnostic line:
the catalog rule id and the matched span in the command as
submitted, never the matched text.

The ssh-self heredoc reader from #34755 is left out: review found
it misreads arithmetic, substitutions and copied shells, so the
ssh-self floor keeps its current reading until a real shell AST.

Supersedes #34755.

Co-authored-by: John Marshall <74795701+Marsjohn-11@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Nov 14, 2026
The -d @ date carve-out only held for a single plain command, so
date -d @n && echo, date -d @n | cat, echo "$(date -d @n)", a TZ=
prefix and date --help | grep -- '-d @' were refused as curl uploads.
A whole line is now carved out when every command in it starts with
date/grep, echo or cat, with no redirection, no live $ or backtick
left in a word, and only list or pipe separators. printf is never
inert: printf -v 'BASH_CMDS[date]' rebinds the date verb.

Each exfil-gate refusal now ends with the refusal diagnostic line:
the catalog rule id and the matched span in the command as
submitted, never the matched text.

The ssh-self heredoc reader from #34755 is left out: review found
it misreads arithmetic, substitutions and copied shells, so the
ssh-self floor keeps its current reading until a real shell AST.

Supersedes #34755.

Co-authored-by: John Marshall <74795701+Marsjohn-11@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Nov 14, 2026
The -d @ date carve-out only held for a single plain command, so
date -d @n && echo, date -d @n | cat, echo "$(date -d @n)", a TZ=
prefix and date --help | grep -- '-d @' were refused as curl uploads.
A whole line is now carved out when every command in it starts with
date/grep, echo or cat, with no redirection, no live $ or backtick
left in a word, and only list or pipe separators. printf is never
inert: printf -v 'BASH_CMDS[date]' rebinds the date verb.

Each exfil-gate refusal now ends with the refusal diagnostic line:
the catalog rule id and the matched span in the command as
submitted, never the matched text.

The ssh-self heredoc reader from #34755 is left out: review found
it misreads arithmetic, substitutions and copied shells, so the
ssh-self floor keeps its current reading until a real shell AST.

Supersedes #34755.

Co-authored-by: John Marshall <74795701+Marsjohn-11@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Nov 14, 2026
The -d @ date carve-out only held for a single plain command, so
date -d @n && echo, date -d @n | cat, echo "$(date -d @n)", a TZ=
prefix and date --help | grep -- '-d @' were refused as curl uploads.
A whole line is now carved out when every command in it starts with
date/grep, echo or cat, with no redirection, no live $ or backtick
left in a word, and only list or pipe separators. printf is never
inert: printf -v 'BASH_CMDS[date]' rebinds the date verb.

Each exfil-gate refusal now ends with the refusal diagnostic line:
the catalog rule id and the matched span in the command as
submitted, never the matched text.

The ssh-self heredoc reader from #34755 is left out: review found
it misreads arithmetic, substitutions and copied shells, so the
ssh-self floor keeps its current reading until a real shell AST.

Supersedes #34755.

Co-authored-by: John Marshall <74795701+Marsjohn-11@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Nov 14, 2026
The -d @ date carve-out only held for a single plain command, so
date -d @n && echo, date -d @n | cat, echo "$(date -d @n)", a TZ=
prefix and date --help | grep -- '-d @' were refused as curl uploads.
A whole line is now carved out when every command in it starts with
date/grep, echo or cat, with no redirection, no live $ or backtick
left in a word, and only list or pipe separators. printf is never
inert: printf -v 'BASH_CMDS[date]' rebinds the date verb.

Each exfil-gate refusal now ends with the refusal diagnostic line:
the catalog rule id and the matched span in the command as
submitted, never the matched text.

The ssh-self heredoc reader from #34755 is left out: review found
it misreads arithmetic, substitutions and copied shells, so the
ssh-self floor keeps its current reading until a real shell AST.

Supersedes #34755.

Co-authored-by: John Marshall <74795701+Marsjohn-11@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Nov 14, 2026
The -d @ date carve-out only held for a single plain command, so
date -d @n && echo, date -d @n | cat, echo "$(date -d @n)", a TZ=
prefix and date --help | grep -- '-d @' were refused as curl uploads.
A whole line is now carved out when every command in it starts with
date/grep, echo or cat, with no redirection, no live $ or backtick
left in a word, and only list or pipe separators. printf is never
inert: printf -v 'BASH_CMDS[date]' rebinds the date verb.

Each exfil-gate refusal now ends with the refusal diagnostic line:
the catalog rule id and the matched span in the command as
submitted, never the matched text.

The ssh-self heredoc reader from #34755 is left out: review found
it misreads arithmetic, substitutions and copied shells, so the
ssh-self floor keeps its current reading until a real shell AST.

Supersedes #34755.

Co-authored-by: John Marshall <74795701+Marsjohn-11@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Nov 14, 2026
The -d @ date carve-out only held for a single plain command, so
date -d @n && echo, date -d @n | cat, echo "$(date -d @n)", a TZ=
prefix and date --help | grep -- '-d @' were refused as curl uploads.
A whole line is now carved out when every command in it starts with
date/grep, echo or cat, with no redirection, no live $ or backtick
left in a word, and only list or pipe separators. printf is never
inert: printf -v 'BASH_CMDS[date]' rebinds the date verb.

Each exfil-gate refusal now ends with the refusal diagnostic line:
the catalog rule id and the matched span in the command as
submitted, never the matched text.

The ssh-self heredoc reader from #34755 is left out: review found
it misreads arithmetic, substitutions and copied shells, so the
ssh-self floor keeps its current reading until a real shell AST.

Supersedes #34755.

Co-authored-by: John Marshall <74795701+Marsjohn-11@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Nov 14, 2026
The -d @ date carve-out only held for a single plain command, so
date -d @n && echo, date -d @n | cat, echo "$(date -d @n)", a TZ=
prefix and date --help | grep -- '-d @' were refused as curl uploads.
A whole line is now carved out when every command in it starts with
date/grep, echo or cat, with no redirection, no live $ or backtick
left in a word, and only list or pipe separators. printf is never
inert: printf -v 'BASH_CMDS[date]' rebinds the date verb.

Each exfil-gate refusal now ends with the refusal diagnostic line:
the catalog rule id and the matched span in the command as
submitted, never the matched text.

The ssh-self heredoc reader from #34755 is left out: review found
it misreads arithmetic, substitutions and copied shells, so the
ssh-self floor keeps its current reading until a real shell AST.

Supersedes #34755.

Co-authored-by: John Marshall <74795701+Marsjohn-11@users.noreply.github.com>
KiroCrewCaptain pushed a commit that referenced this pull request Nov 14, 2026
#36992)

The -d @ date carve-out only held for a single plain command, so
date -d @n && echo, date -d @n | cat, echo "$(date -d @n)", a TZ=
prefix and date --help | grep -- '-d @' were refused as curl uploads.
A whole line is now carved out when every command in it starts with
date/grep, echo or cat, with no redirection, no live $ or backtick
left in a word, and only list or pipe separators. printf is never
inert: printf -v 'BASH_CMDS[date]' rebinds the date verb.

Each exfil-gate refusal now ends with the refusal diagnostic line:
the catalog rule id and the matched span in the command as
submitted, never the matched text.

The ssh-self heredoc reader from #34755 is left out: review found
it misreads arithmetic, substitutions and copied shells, so the
ssh-self floor keeps its current reading until a real shell AST.

Supersedes #34755.

Co-authored-by: John Marshall <74795701+Marsjohn-11@users.noreply.github.com>
@buluoray

Copy link
Copy Markdown
Contributor

Thanks @Marsjohn-11 for this fix and the careful review rounds. Here is where each part stands on main today (ba065b84ca0):

Part of this PR On main
-d @ carve-out for inert date lines (chained, TZ=, piped, "$( )", --help | grep) already there, through #36992
Rule id and span on every exfil refusal already there, through #36992
ssh-self reading a heredoc body as argv (python3 - <<'EOF' with n = a * localhost) still refused on main

To get the last part in, we ported your ssh-self rules into a new PR, #39056 (issue #38979). It keeps your fail-closed rules, adds a fallback so no line main allows becomes refused, and credits you as co-author.

Since main or #39056 now covers each part, could you close this PR when you have a moment? Thanks again.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 18, 2026
buluoray added a commit that referenced this pull request Nov 19, 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 new module argv_floor_ssh_heredoc.py cuts the 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. Anything else
keeps the bodies: a wrapper, an assignment prefix, a pipe, a second
heredoc, a non-plain tag, compound syntax, a backslash-newline, or an
unquoted body with a live substitution. The floor allows the line when
the cut reading reaches no self host; otherwise it reads the whole line
as before, so no line main allows becomes refused.

Ported from #34755 by Marsjohn-11.

Closes #38979

Co-authored-by: Marsjohn-11 <74795701+Marsjohn-11@users.noreply.github.com>
buluoray added a commit that referenced this pull request Nov 20, 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 new module argv_floor_ssh_heredoc.py cuts the 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. Anything else
keeps the bodies: a wrapper, an assignment prefix, a pipe, a second
heredoc, a non-plain tag, compound syntax, a backslash-newline, or an
unquoted body with a live substitution. The floor allows the line when
the cut reading reaches no self host; otherwise it reads the whole line
as before, so no line main allows becomes refused.

Ported from #34755 by Marsjohn-11.

Closes #38979

Co-authored-by: Marsjohn-11 <74795701+Marsjohn-11@users.noreply.github.com>
buluoray added a commit that referenced this pull request 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 new module argv_floor_ssh_heredoc.py cuts the 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. Anything else
keeps the bodies: a wrapper, an assignment prefix, a pipe, a second
heredoc, a non-plain tag, compound syntax, a backslash-newline, or an
unquoted body with a live substitution. The floor allows the line when
the cut reading reaches no self host; otherwise it reads the whole line
as before, so no line main allows becomes refused.

Ported from #34755 by Marsjohn-11.

Closes #38979

Co-authored-by: Marsjohn-11 <74795701+Marsjohn-11@users.noreply.github.com>
buluoray added a commit that referenced this pull request 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 same heredoc view the
self-subcommand floor already uses, `_heredoc_data_view`. It allows
the line when the view blanked a body and the blanked line reaches no
self host; otherwise it reads the whole line as before.

The view moves to its own module, argv_floor_heredoc_data.py, and
widens by three line shapes: one leading `cd <plain path> &&`, Python
reading stdin with -u, -b, -e or -s, and a cat or tee that stores a
body followed only by `python <file>`, where each stored body must
pass the same data-only Python check. It also turns stricter: a tag
must be a plain word used exactly twice, and a backslash-newline
outside a quoted-tag body keeps every body. The facade and its
manifest list the new owner; argv_floor_self re-exports the names.

Ported from #34755 by Marsjohn-11.

Closes #38979

Co-authored-by: Marsjohn-11 <74795701+Marsjohn-11@users.noreply.github.com>
buluoray added a commit that referenced this pull request 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 same heredoc view the
self-subcommand floor already uses, `_heredoc_data_view`. It allows
the line when the view blanked a body and the blanked line reaches no
self host; otherwise it reads the whole line as before.

The view moves to its own module, argv_floor_heredoc_data.py, and
widens by three line shapes: one leading `cd <plain path> &&`, Python
reading stdin with -u, -b, -e or -s, and a cat or tee that stores a
body followed only by `python <file>`, where each stored body must
pass the same data-only Python check. It keeps every body when bash
and the lowered reader could close a body on different lines: a
backslash-newline inside an unquoted-tag body or at the end of a
heredoc opener's line, or a tag whose closing lines outnumber its
bodies. The facade and its manifest list the new owner;
argv_floor_self re-exports the names.

Ported from #34755 by Marsjohn-11.

Closes #38979

Co-authored-by: Marsjohn-11 <74795701+Marsjohn-11@users.noreply.github.com>
buluoray added a commit that referenced this pull request 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 same heredoc view the
self-subcommand floor already uses, `_heredoc_data_view`. It allows
the line when the view blanked a body and the blanked line reaches no
self host; otherwise it reads the whole line as before.

The view moves to its own module, argv_floor_heredoc_data.py, and
widens by three line shapes: one leading `cd <plain path> &&`, Python
reading stdin with -u, -b, -e or -s, and a cat or tee that stores a
body followed only by `python <file>`, where each stored body must
pass the same data-only Python check. Like bash, it joins a
backslash-newline that ends a line after its `<<` before it finds
the bodies. It keeps every body when bash and the lowered reader
could close a body on different lines: a backslash-newline inside an
unquoted-tag body, or a tag whose closing lines outnumber its bodies. The facade and its manifest list the new owner;
argv_floor_self re-exports the names.

Ported from #34755 by Marsjohn-11.

Closes #38979

Co-authored-by: Marsjohn-11 <74795701+Marsjohn-11@users.noreply.github.com>
buluoray added a commit that referenced this pull request 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 same heredoc view the
self-subcommand floor already uses, `_heredoc_data_view`. It allows
the line when the view blanked a body and the blanked line reaches no
self host; otherwise it reads the whole line as before.

The view moves to its own module, argv_floor_heredoc_data.py, and
widens by three line shapes: one leading `cd <plain path> &&`, Python
reading stdin with -u, -b, -e or -s, and a cat or tee that stores a
body followed only by `python <file>`, where each stored body must
pass the same data-only Python check. It reads the text as typed and
keeps every body when a backslash-newline sits inside an
unquoted-tag body. The ssh floor reads the whole line, as before,
when a line holding `<<` ends in a backslash. The facade and its manifest list the new owner;
argv_floor_self re-exports the names.

Ported from #34755 by Marsjohn-11.

Closes #38979

Co-authored-by: Marsjohn-11 <74795701+Marsjohn-11@users.noreply.github.com>
buluoray added a commit that referenced this pull request 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. It 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 added a commit that referenced this pull request 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ssh-self and -d @ exfil gates refuse inert commands: heredoc bodies read as argv, date outside a lone command

4 participants