Stop misclassifying innocuous shell redirections (1.4.0)#6
Merged
Merged
Conversation
…sifying innocuous redirections (1.4.0) Innocuous shell redirections were misclassified. The bash tokenizer only knew `2>`/`2>>`, so `cmd 2>&1` produced a target-less `2>` redirection, a spurious "Redirection without a target" diagnostic, and a phantom command named `1` — whose `errorOutput` node falsely added a writeFilesystem capability. `1>&2` and `&>/dev/null` broke the same way, and even well-formed `>/dev/null` reported a file write. - AST: add RedirectionType.mergeStreams, combinedOutput, combinedAppendOutput. - Parsers (bash/posix, windows cmd, powershell): recognize fd-duplication (N>&M, >&-) and combined redirects (&>, &>>). Merges are self-contained: no consumed word, no phantom command, no diagnostic. - Capability detector: fd-merges add nothing; null-sink targets (/dev/null, NUL, $null) no longer add writeFilesystem/readFilesystem. Genuine targets (> out.txt, &> out.log) still do. - New BenignRedirectionDetector (default suite): records merges and null-sink discards as safe-level audit findings; decision-neutral. - DangerousOperatorDetector: recognize >& / &> as redirection sequences. - Bump to 1.4.0 + CHANGELOG; +24 tests across all parsers. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Agents routinely append innocuous redirections to commands, and the analyzer mishandled the whole family —
2>&1,1>&2,2>/dev/null,>/dev/null,&>/dev/null,>/dev/null 2>&1.Two concrete defects:
2>&1was mis-parsed. The bash tokenizer only knew2>/2>>, socmd 2>&1produced a target-less2>redirection, a spurious"Redirection without a target"diagnostic, and a phantomCommandInvocationwith executable1.1>&2and&>/dev/nullbroke the same way.writeFilesystem. The phantomerrorOutputnode (and even well-formed>/dev/null) added awriteFilesystemcapability →modifyFileseffect, pushing read-only commands toward REVIEW.Changes
command_node.dart): newRedirectionType.mergeStreams,combinedOutput,combinedAppendOutput.shell_parser,windows_cmd_parser,powershell_parser): recognize fd-duplication (N>&M,>&-) and combined redirects (&>,&>>). Merges are self-contained — no consumed word, no phantom command, no diagnostic. Leading-digit fds only trigger when immediately followed by>(so2foostays a word)./dev/null,NUL,$null) no longer addwriteFilesystem/readFilesystem. Genuine targets (> out.txt,&> out.log) still do.BenignRedirectionDetector(new, in the default suite): records merges and null-sink discards assafe-levelbenign-redirectionfindings for audit visibility. Decision-neutral sincesafe < mediumRisk.DangerousOperatorDetector: recognizes>&/&>as redirection sequences so fd-dups aren't mislabeled as output redirection.Verification
dart analyzeclean;dart formatapplied; 428 tests pass (+24 new across parser, capability, security, and end-to-end suites).ls -la 2>&1,grep x f >/dev/null,foo &>/dev/null,cmd >/dev/null 2>&1→ allow, nomodifyFiles, benign marker present;rm -rf / >/dev/null 2>&1→ deny (command risk not masked);echo hi > out.txt→ stillmodifyFiles.Limits (documented in code)
/dev/null,NUL/NUL:,$null.12>&3is not treated as a merge).🤖 Generated with Claude Code