Repository navigation
fix(security): judge the nc redirect row per pipeline, not per line - #38787
Conversation
Sensitive change reviewHead: 3a6152e
|
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ✅ PASSUX-level review of 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 |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing to check. What this change shipsInventory (6 items) — 6 justifiedIntent: let an agent run a line where
[FIRST-PRINCIPLES-REVIEWED] 52a83da Description read[DESCRIPTION-READ] 5a103cf6ccbb4b12f787ffae9679a5e4079c7d648b18a5d9aa5686059c856e6a That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
3a6152e to
99512d5
Compare
Sensitive change reviewHead: 99512d5
|
|
GPT 6.1 finding on 3a6152e ( The finding was right. The class is an empty command after a |
Security Scope Review -- ✅ PASSWhich legitimate operations does Verdict basis: adjudicated, zero confirmed regressions. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: PASS Reason: This diff narrows a rule instead of tightening one. It adds a carve-out ( TIGHTENING: None. The only rule touched is the ADJUDICATED: 17 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: Candidates cover posix, windows and any.
No platform the diff assumes is left without a candidate. [SCOPE-REVIEWED] 52a83da |
99512d5 to
fc21d22
Compare
Sensitive change reviewHead: fc21d22
|
|
GPT 6.1 finding on 99512d5 ( The finding was right. Its class is output from a command that holds an nc word reaching another command through a pipe ( One shape stays allowed because the issue's acceptance criterion 1 requires it: |
|
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
fc21d22 to
880757a
Compare
Sensitive change reviewHead: 880757a
|
|
Review disposition for 880757a (rebase of fc21d22 onto main 0c5d8bd, conflict-only):
|
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.
Sensitive change reviewHead: bbc22e0
|
|
Opus 5.5 finding on 880757a ( |
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.
Sensitive change reviewHead: ce3de70
|
|
Opus 5.5 finding on bbc22e0 ( |
Semgrep D11: an autouse fixture on the shared monkeypatch is lifted by any monkeypatch.undo().
Sensitive change reviewHead: 52a83da
|
Code change approver recommendation: A person should decideWhy: 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 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 |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
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_firstcheck (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 asnc -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 #38524with a follow-up issue, would tell the reporter that nothing changes on their platform. - The body has no
## Real-machine verificationsection. 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.
Problem / Motivation
Goal: A shell line where
ncorncatappears 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-redirectrefused any line withnc/ncatfollowed anywhere by<, even when the<belongs to a different command.nc -z host 22; sort < in.txt,echo nc done; wc -l < fand 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 -zand 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 realnc host port < fileblock the row exists for.Not a goal
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 decoyncword, and this PR does not change that.nc -e/ncat -ereverse-shell rows.What changed (motivation → approach → change)
(?:^|\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|.exfil_bash._nc_redirect_line_allows, reads the line with the sharedshell_commands.read_commands/pipelinesand lets a match through only when:$, backtick, paren, brace, glob,<<, non-ASCII or control character (other than tab and newline), and is at most 2000 characters;|&), since the pipe runs on into the next command;;,&,&&,||,|or a newline, has noexecword, 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,.);ncornetcat(/bin/nc,nc.openbsd,sort=nc) stands only first in its command, or afterechoin a command with no redirect;<), so an echoednccannot be piped into a script (echo nc h 1 | tee run).deny_gate._nc_redirect_narrows, beside_s3_download_narrows): it writes adeny_exceptionSEL 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.[^;&|\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.mddocuments the reader.test/security_line_budget/nc-redirect-scope.txtrecords 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_deniedand 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 withtee), 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.pyand related files passed (1646 tests), as didlocal-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 calledaudit_bash_exfiltrationandis_deniedon the five lines: both refused all five. On this branch both allow all five, and both still refusenc h 1 < f,nc h 1 <f,ncat h 1 < fandnc 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-Fand wget--post-filerows the keyed flag is itself the upload shapePattern 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
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.