![Header card titled ReDoS in AI guardrails, measured: one ordinary line, five regex engines. The rule is (api[_-]?key|token|secret|password)\s*[:=]\s*"([\w-]+)+" and the input is the 37-byte line password="build-agent-nightly-release. Log-scale bars of the time to check it: Python 3.13 re 4.5 s, Node 22 V8 Irregexp 710.3 ms, Node 22 with the linear fallback flag 686.7 ms, Go 1.27 regexp 3.2 µs, Rust regex 1.13 100 ns. The hardened rewrite of the rule is under 10 µs on every engine. Apple M2 Pro, median of 3 runs.](/assets/img/headers/ai/ai-security-guardrail-redos.webp)
AI Security: ReDoS in LLM Guardrail Regexes, Measured in Python, Node, Go and Rust
Five LLM guardrail regexes in Python, Node, Go and Rust: one ordinary 37-byte line took 4.5 s in Python and failed 67% of a guard's traffic. Rust: 0.1 µs.
![Header card titled ReDoS in AI guardrails, measured: one ordinary line, five regex engines. The rule is (api[_-]?key|token|secret|password)\s*[:=]\s*"([\w-]+)+" and the input is the 37-byte line password="build-agent-nightly-release. Log-scale bars of the time to check it: Python 3.13 re 4.5 s, Node 22 V8 Irregexp 710.3 ms, Node 22 with the linear fallback flag 686.7 ms, Go 1.27 regexp 3.2 µs, Rust regex 1.13 100 ns. The hardened rewrite of the rule is under 10 µs on every engine. Apple M2 Pro, median of 3 runs.](/assets/img/headers/ai/ai-security-guardrail-redos.webp)
Five LLM guardrail regexes in Python, Node, Go and Rust: one ordinary 37-byte line took 4.5 s in Python and failed 67% of a guard's traffic. Rust: 0.1 µs.

12 agent-written Go test suites scored 92-97% on mutation testing and caught 15-19 of 26 seeded bugs. Two suites at the same 97.3% caught 15 and 19.

79 read_file argument strings, 7 policy gates, 5 serde executors, real canary reads: a Go encoding/json gate let 13 through to a serde struct.

27 attacks by a hijacked coding agent: a command allowlist stopped 1, argument rules 10, an OS sandbox 24, sandbox plus a scrubbed env all 27. Code included.

10,233 go test runs on 9 agent PRs: re-running red CI jobs merged 70% of flaky defects; one -race -shuffle -count=10 run merged none, in 54 ms.

Go PGO measured on a log router: -pgo cut instructions per line 8.8-10%. All of it came from inlining, and a 0.4 s profile gave nothing.

Mixing 10-50% general text into a SmolLM2-135M fine-tune cut drift from the base model by 22-30%. Cutting the learning rate 10x cut it by 91%.

Review agents flagged 7/7 defective Go PRs with 0 false blocks; fix agents went 7/7 green, yet 1 fix still failed hidden tests and the re-review approved it.

60 LLM calls against one 40,000-token team budget: check-then-bill overspent it by 13%, meter-only by 106%. Reserving max_tokens held spend at 95%.

24 coding-agent PRs from 6 tickets: all had green CI and full diff coverage, but 0 of 12 from one-line tickets met the spec and 12 of 12 from full specs did.