feat(ENG-3869): opt-in ATR rule pack, detect-only

HI
7d ago
+16946-24

Adds an opt-in pack of rules from Agent Threat Rules (ATR, MIT), pinned to 4.3.1. Off by default and detect-only.

Usage

const defense = createPromptDefense({ enableAtrPatterns: true });
const result = await defense.defendToolResult(data, "gmail_get_message");
result.atrMatches; // e.g. ["ATR-2026-00001"], omitted when nothing matched

Matched rule ids go in atrMatches. They never change riskLevel, allowed or detections. Anything in detections counts as a threat signal, so a tool with high base risk would block on an ATR match.

What's in the pack

  • Families: prompt-injection, tool-poisoning, context-exfiltration, agent-manipulation.
  • Rules that apply to tool results (mcp_exchange, llm_io, context_window sources; tool_response, content, user_input, agent_output fields), excluding draft and deprecated rules.
  • scripts/build-atr-pack.mjs generates src/classifiers/atr-pack.json from node_modules/agent-threat-rules. It drops:
    • regexes that recheck can't prove safe from catastrophic backtracking (verdicts cached in node_modules/.cache);
    • regexes that need Unicode-mode features, or don't compile in Python with re.I | re.A, so the Python package can run the same pack;
    • 11 rules that matched benign text too often in internal benign tool-result sets.
  • The pack carries ATR's version and license text.
  • Result: 455 rules, 1,343 regexes.

Matching

  • ATR scans the same strings Tier 1 scans (risky field names plus top-level strings), on the raw text. Normalising the text split emails and URLs and lost most context-exfiltration matches.
  • For each regex the build records words of which every match must contain one. At run time one Aho-Corasick pass finds those words, and only regexes whose words are present run. Regexes that need a non-ASCII character are skipped on ASCII text.
  • specs/atr.spec.ts checks the matcher against running every regex directly.

Measured (Modal, Tier 1 + Tier 2, off vs on in one process)

  • Verdict changes: 0 on every set.
  • Attack recall from ATR matches, over what 0.9.5 already catches: +15.6 points on a held-out attack set and +41.5 on an indirect-injection email set, almost all context-exfiltration.
  • Benign match rate: under 0.5 points per family on every benign set; 0 on two of them.
  • Added latency, mean: +8.4 ms on the largest tool-result set (p50 1.1 ms), +0.5 to +2.9 ms on the others.

Conformance

New conformance/atr.json (12 cases, including benign text and a field Tier 1 doesn't scan). The Python package will sync the pack and fixtures from this ref.

🤖 Generated with Claude Code


Summary by cubic

Adds an opt-in ATR (Agent Threat Rules) rule pack to Tier 1 that reports matched rule IDs in atrMatches and never changes the verdict. Set enableAtrPatterns: true on createPromptDefense; the pack is off by default and detect-only.

What's included

  • Pinned to agent-threat-rules 4.3.1: 455 rules with 1,343 regexes across prompt-injection, tool-poisoning, context-exfiltration, and agent-manipulation families.
  • scripts/build-atr-pack.mjs generates src/classifiers/atr-pack.json and drops regexes that are ReDoS-unsafe, need Unicode features, don't compile in Python, or matched benign tool results in internal tests.
  • Adds conformance cases in conformance/atr.json so the Python package can sync the same pack and fixtures.

Matching and performance

  • Rules run on the raw strings Tier 1 scans (risky field names, top-level strings, nested fields, object keys) as well as base64-decoded text, not on the normalised text, since normalisation split emails and URLs and lost most matches. Even short strings below Tier 1's 3-character minimum are matched, and the public analyze() reports matching rule IDs.
  • An Aho-Corasick prefilter runs only regexes whose required words appear in the text; patterns needing non-ASCII characters are skipped on ASCII text.
  • No verdict changes in measured sets, +15.6 to +41.5 points attack recall over Tier 1 alone, under 0.5 benign matches per family.
  • Added mean latency of +8.4 ms on the largest tool-result set (p50 1.1 ms).