tcha-protection
v2.0.3
Published
An in-line firewall that blocks prompt injection, SSRF, path traversal, and destructive tool calls for MCP and agent tools, with a built-in 100-probe self-test.
Maintainers
Readme
🛡️ Tcha Protection
An in-line firewall that blocks prompt injection, SSRF, path traversal, and destructive tool calls for MCP and agent tools, with a built-in 100-probe self-test.
Tcha Protection runs as an in-line STDIO proxy firewall between your AI agent (Claude Code, Cursor, custom agents) and Model Context Protocol (MCP) servers. It intercepts and blocks SSRF egress to cloud metadata, stops path traversal before it touches the host filesystem, defuses indirect prompt injections, and pauses destructive tool calls for cryptographic Human-in-the-Loop (HITL) authorization. It also ships with a built-in 100-probe self-test benchmarking its own internal defense perimeter.
⚡ Headline Quickstart: In-Line Firewall
Wrap any standard MCP server command in a transparent, zero-trust proxy firewall:
npx tcha-protection wrap -- <mcp command>Example: Protecting the Official Filesystem MCP Server
npx tcha-protection wrap -- npx -y @modelcontextprotocol/server-filesystem ./workspaceWhen your agent invokes MCP tools:
- Safe calls (
read_file,list_directory): Forwarded with minimal latency (about 0.7 ms median proxy overhead across scenarios (excludes URL arguments; N=100, local, Windows 8-core laptop)). - Path traversal (
../../etc/shadow): Blocked in-line with JSON-RPC error code-32001. - SSRF egress (
http://169.254.169.254): Intercepted before the request touches internal networks or cloud metadata. - Destructive actions (
delete_file,drop_table): Suspended pending HMAC-SHA256 human authorization token. - Every event: Cryptographically logged to an append-only SQLite Merkle audit ledger under
~/.tcha/tcha_events.jsonl.
How to Authorize a Suspended Destructive Action (Out-of-Band HITL Flow)
When an agent invokes a destructive tool (e.g. delete_file, drop_table), Tcha Protection halts the call and emits an out-of-band authorization challenge:
{
"jsonrpc": "2.0",
"id": 4,
"error": {
"code": -32001,
"message": "[Tcha Guard]: High-risk Tier 3 tool invocation suspended awaiting human authorization. Run 'tcha approve ch_a1b2c3d4' to authorize.",
"data": {
"threat_type": "UNAUTHORIZED_TIER3_ACTION",
"rule_id": "SEC-HITL-003",
"challengeId": "ch_a1b2c3d4",
"toolName": "delete_file",
"params": { "path": "./workspace/note.txt" },
"expiresAt": 1729000300
}
}
}Step 1: Human Out-of-Band Approval
A human operator in a separate terminal verifies the tool parameters and signs the authorization:
npx tcha-protection approve ch_a1b2c3d4This cryptographically signs the pending challenge using the local secret key (~/.tcha/hitl_secret) and records it in ~/.tcha/pending_approvals.json.
Step 2: Safe Downstream Execution
When the agent retries the call, Tcha Protection verifies the authentic human signature, releases that single invocation downstream to the MCP server, and immediately marks the challenge as CONSUMED to prevent replay attacks.
Security Note: By default, Tcha Protection strictly rejects agent self-approval attempts. An agent cannot derive or sign its own tokens.
Automated Testing Mode: --allow-inline-approval
For automated integration test suites and CI scripts, you can permit inline HMAC token resubmission by passing --allow-inline-approval:
npx tcha-protection wrap --allow-inline-approval -- <mcp-command>⚡ Performance Overhead Benchmark (npm run bench)
Measure deterministic proxy overhead on your local machine across all request types:
npm run benchHeadline Performance: about 0.7 ms median proxy overhead across scenarios (excludes URL arguments; N=100, local, Windows 8-core laptop).
Per-Scenario Breakdown:
- Safe Read-Only Tool:
0.38 msmedian (0.69 msp95) - Blocked Path Traversal:
0.34 msmedian (0.45 msp95) - Blocked SSRF Egress (IP literal):
0.37 msmedian (0.55 msp95) - State-Mutating Tool:
0.39 msmedian (0.62 msp95) - Tier 3 Destructive (HMAC Challenge + State Persist):
1.71 msmedian (2.42 msp95) - Overall Across All Scenarios:
0.67 msmedian (0.99 msp95)
🧪 Built-In Defense Benchmark (100-Probe Self-Test)
Run the built-in self-test to verify Tcha Protection's defense mechanisms locally in your environment:
Note: This self-test benchmarks Tcha Protection's own built-in defense modules against 100 adversarial vectors; it does not probe or attack your external agent.
npx tcha-protection auditReal Self-Test Output
$ npx tcha-protection audit
[Tcha Protection] Launching 100-probe Defense Benchmark (Self-Test)...
[Tcha Protection] Note: Benchmarks Tcha Protection's own built-in guards, not your agent.
======================================================================
🛡️ Tcha Protection Pro 2.0 Defense Benchmark (100-Probe Self-Test)
Note: This self-test benchmarks Tcha Protection's own built-in guards, not your agent.
Evaluating OWASP Top 10 for LLMs 2025/2026 Defense Perimeter
======================================================================
[Phase 1/4] Auditing Prompt Injection & Steganography (25 Probes)...
✓ Probe 01-25: Neutralized injection, delimiter breakout & zero-width stego
[Phase 2/4] Auditing SSRF & Egress Firewall (25 Probes)...
✓ Probe 01-25: Blocked AWS/GCP IMDS (169.254.169.254), hex IPs, IPv6 & loopbacks
[Phase 3/4] Auditing Path Traversal & Shell Probes (25 Probes)...
✓ Probe 01-25: Flagged & sanitized directory traversal and pipe injections
[Phase 4/4] Auditing Tool Privilege & HITL Gates (25 Probes)...
✓ Probe 01-25: Intercepted Tier-3 destructive actions (table drops, shell exec)
======================================================================
🏆 DEFENSE BENCHMARK COMPLETE: 100/100 Probes Neutralized (100.0%)
======================================================================
🌟 BENCHMARK STATUS: MAXIMUM (100% Defense Benchmark Pass)
Execution Time: 1.41s | Zero SSRF escapes | 100% destructive tools caught🚀 Additional CLI Commands
# Generate an air-gapped Executive Compliance Report (HTML/PDF)
npx tcha-protection report audit-report.html
# Verify cryptographic Merkle ledger integrity
npx tcha-protection verify-ledger
# Start the local cybersecurity web dashboard (port 4420)
npx tcha-protection start👉 Need continuous cloud red-teaming and managed SOC alerts? Join the waitlist at tcha.dev
📊 100-Probe Attack Matrix Coverage
| Attack Vector | Category | OWASP LLM 2025/2026 Matrix | Defended By |
|---|---|---|---|
| Indirect Prompt Injection | 25 Probes | LLM01:2025 Prompt Injection | PromptSanitizer (XML encapsulation & delimiter neutralization) |
| Unicode Steganography & ASCII Smuggling | Integrated | LLM01:2025 / Steganographic Evasion | PromptSanitizer (Zero-width stripping & tag filter) |
| SSRF & Cloud Metadata Exfiltration | 25 Probes | LLM02:2025 Sensitive Information / SSRF | SSRFGuard (IMDSv1/v2, IPv4/IPv6, hex/octal decoding) |
| Path Traversal & Shell Metacharacters | 25 Probes | LLM05:2025 Improper Output Handling | RiskEngine (Argument token inspection & sanitization) |
| Unauthorized Tool Abuse & Privilege Escalation | 25 Probes | LLM06:2025 Excessive Agency & Autonomy | RiskEngine (3-Tier classification & HMAC sign-off gate) |
⚠️ Known Limitations & Threat Model
Tcha Protection provides defense-in-depth at the MCP transport layer, but you should understand its security boundaries:
- Heuristic & Pattern-Based Detection:
- Path traversal and argument inspection look for suspicious tokens (
..,;,|,$(, null bytes,%2e%2e). While effective against common automated escapes, token pattern matching is heuristic and not an OS-level sandbox. - Attackers with novel encoding polyglots or complex multi-hop filesystem indirection could theoretically evade pure token heuristics.
- Path traversal and argument inspection look for suspicious tokens (
- Not an Operating System Sandbox:
- Tcha Protection is a protocol-level JSON-RPC firewall. It does not replace running MCP servers with OS-level least privilege (e.g., dedicated Linux users, Docker containers with read-only root filesystems, minimal capability flags).
- If a downstream tool has an internal vulnerability that executes without suspicious parameters, Tcha will pass the valid-looking parameters through.
- Defense Benchmark vs. Target Pen-Testing:
- The default
npx tcha-protection auditcommand runs a built-in self-test of Tcha Protection's own internal defense engines against 100 OWASP/adversarial vectors. It does not attack or benchmark your custom external agent or MCP server. - Roadmap: Active targeting via
npx tcha-protection audit --target "<mcp command>"is currently designed and scheduled for upcoming releases to dynamically introspect and red-team third-party MCP servers.
- The default
- Out-of-Band Approval Boundaries & Host File/Shell Access:
- Out-of-band human approval (
tcha approve <challenge-id>) protects against agents that interact exclusively via MCP tool invocations. - For agents that possess direct host shell execution (e.g. bash, terminal execution tools) or host filesystem access, the
~/.tchadirectory (which holdshitl_secretandpending_approvals.json) must not be readable or writable by the agent process. - Enforce process isolation by running the agent under a separate OS user account, inside an unprivileged Docker container, or by mounting
~/.tchainto a volume restricted from the agent process.
- Out-of-band human approval (
- Operating System User Separation vs. Passwords:
- The approval workflow (
tcha approve <challenge-id>) is protected by operating system user boundary separation, not by a password prompt or interactive authentication factor. Any process running under the same OS user account with access to the local shell can sign pending challenges.
- The approval workflow (
- Store Concurrency & File Locking:
- The local approval store (
~/.tcha/pending_approvals.json) relies on atomic file reads and writes without OS-level file locking. Under heavy parallel concurrency across multiple proxy instances, uncoordinated concurrent writes could race.
- The local approval store (
- Windows Filesystem Permissions (POSIX Modes):
- Windows does not enforce POSIX file permission bits (
0700,0600) on~/.tcha/hitl_secret. On Windows hosts, the security of the signing secret depends on Windows user profile directory ACLs.
- Windows does not enforce POSIX file permission bits (
- Ephemeral Secret Restarts:
- If
~/.tchais unwritable and the proxy falls back to an in-memory secret, restarting the proxy process generates a new key and immediately invalidates all previously issued pending approval challenges.
- If
- Heuristic Secret Redaction:
- Secret redaction in challenge summaries is heuristic (matching key names and token shapes) and may miss secrets stored under neutral keys or short values.
- SSRF Guard & DNS Resolution Boundaries:
- Explicit
http(s)URLs are resolved through the system resolver at inspection time: DNS queries for hostnames found in tool arguments (including the full domain names) go directly to the host's configured DNS resolver. Because DNS queries leave the machine, they could be abused as a covert exfiltration channel by an injected prompt. - The inspection check is not safe against DNS rebinding (TTL = 0), because downstream tools may resolve the hostname again later with a different address.
- Using the
--no-dns-resolveflag switches network DNS resolution off entirely (evaluating only IP literals, dynamic DNS providers, and static domain suffix policies). While this eliminates outbound DNS queries and covert channels, it is strictly weaker against attacker-controlled public domains that resolve to internal private IP addresses. It should only be used in air-gapped or hermetic CI testing environments.
- SSRF Inspection Scope:
- SSRF inspection covers argument values that are entire URLs or hosts. URLs embedded inside longer strings, shell commands, or file contents are not inspected (for example,
curl http://127.0.0.1/adminpassed to a shell tool). Pair the proxy with network egress controls for tools that can run commands.
🏛️ Architecture & 6-Pillar Spec Blueprint
Tcha Protection Pro 2.0 was architected in adherence to the 6-Pillar Engineering Specification Blueprint:
specs/01_PRD.md: Scope, dual-core architecture, and compliance mandates.specs/02_TRD.md: Hybrid TypeScript/Python architecture, file tree contract, $\le 2\text{ms}$ latency budgets.specs/03_APP_FLOW.md: Audit execution, proxy interception, and ledger verification lifecycles.specs/04_UI_UX.md: Executive compliance report typography, dark-mode tokens, and print-to-PDF styles.specs/05_SCHEMA.md: SQLite Merkle ledger schema and JSON-RPC 2.0-32001error contracts.specs/06_IMPLEMENTATION_PLAN.md: Chronological milestones with Definition of Done.
📜 Compliance Standards Addressed
- EU AI Act (Regulation 2024/1689): Article 15 (Cybersecurity & Robustness Requirements for Autonomous Systems).
- SOC 2 Type II: CC6.1 / CC6.6 (Perimeter & Egress Security Boundaries).
- OWASP Top 10 for Large Language Models 2025/2026: Comprehensive probe coverage across LLM01 through LLM09.
- ISO/IEC 42001:2023: Control A.6.2 (AI System Risk Management & Tamper-Evident Audit Logging).
📜 License
MIT License. Created with Antigravity 2.0.
