Benchmarking MCP Prompt Injection Defenses: Regex Catches 17%, Semantic Classifier 89%
_AegisLayer_ · reddit · 2026-08-07
The author built a 218-case test set to evaluate prompt injection defenses in MCP clients, comparing regex patterns against a semantic classifier.
- Regex baseline: Using 51 patterns, it achieved only 16.9% recall for attacks and suffered high false positives on normal texts discussing security vulnerabilities.
- Semantic classifier: Powered by claude-haiku-4-5, it reached 89.0% recall and 98.1% precision.
- Adversarial tests: Across 29 hand-authored obfuscation cases (e.g., encoding, indirect injection, foreign language, hidden text), the regex baseline caught zero, while the semantic classifier caught all of them.
The author notes that while effective, running an LLM on every resource read adds latency and cost. A sane architecture would use regex as a first pass and route borderline content to a classifier. Furthermore, defense shouldn't rely solely on detection; irreversible tool calls must be intercepted before invocation.
More from coding & agent
- Rollikey: open-source proxy adds pre-flight snapshots and LIFO rollback for production AI agents — Rollikey · 2026-11-30
- Open-source LoRA restyles MiniMax H3 video from a single reference image — linoy_tsaban · 2026-11-30
- Dev shares Avi home AI companion internals: device control, memory and full system prompt — aloncarmel · 2026-11-30
- Microsoft exec explains AI governance with a 4-step closet-cleaning method — donasarkar · 2026-11-30
- Catching steps your AI agent silently skipped: declare required actions per task — Ok-Machine7983 · 2026-11-30
- MoonBit 1.0 RC Ships with Stable Compiler, Targeting February 2027 Release — harryshum · 2026-11-30