Hybrid shell interpreter, AST evasion detection, and prefilter delegation #36
Merged
chen-zichen merged 4 commits intomainfrom Feb 28, 2026
Merged
Hybrid shell interpreter, AST evasion detection, and prefilter delegation #36chen-zichen merged 4 commits intomainfrom
chen-zichen merged 4 commits intomainfrom
Conversation
…esting - Add internal/shellutil package that builds shell commands via the shell parser's AST (syntax.Quote → parse → CallExpr → Printer) instead of manual string concatenation - Replace hand-rolled shellQuote + string concat in acpwrap/convert.go and proxy/sse_buffer.go with shellutil.Command() - Add jsonDepth check in extractor.Extract() — arguments with nesting depth > 2 are flagged as evasive (hard block), preventing attackers from hiding security-relevant fields inside deeply nested objects - Add tests for deep nesting evasion detection
Replace all-or-nothing interpreter fallback with per-statement hybrid approach: safe statements run through the interpreter for full variable expansion, unsafe ones (ProcSubst, coproc, background, fd-dup redirects) use AST extraction with recursive interpretation of inner commands. Key changes: - Refactor astHasUnsafe → nodeHasUnsafe (accept syntax.Node) - Add collectInnerStmts, defuseStmt, extractFromAST skipInner param - Extract runShellFileInterp, rewrite runShellFile with hybrid loop - Add ls/exa/eza/lsd to command DB - Fix [ builtin false-positive in glob detection - Add false_positive, hybrid, and shell_fuzz test suites (230+ cases)
223c81b to
8933a10
Compare
… parser - Rewrite all EvasiveReason strings for non-technical users - Include offending command/value in every evasive message - Unparseable shell commands no longer flagged as evasive - Move eval to AST-level recursive parsing (like sh -c) - Move fork bomb detection to AST-level astForkBomb (FuncDecl self-call) - Remove network/IFS/indirect-expansion patterns from prefilter - Prefilter now only has base64 + hex encoding detection - Add TestForkBombDetection, TestEvalRecursiveParsing, TestUnparseableCommandNotEvasive
8933a10 to
489937e
Compare
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.
Summary
AST. DIR=/tmp; diff <(ls $DIR) now expands $DIR.
remain)
Test plan
go build ./...passesgo test -race ./...passesSecurity checklist