When you wire up Atlassian Forge apps, Rovo agents, or MCP tools, untrusted text shows up in places people tend to overlook: Jira issue descriptions, PR comments, Teamwork Graph nodes, and even tool error messages. If that text carries hidden instructions—Unicode Tag characters that render as nothing, BiDi controls that flip what a human reviewer sees, zero-width characters splitting a keyword, or plain injection phrases—an LLM-based filter is often too slow, hard to audit, and itself an attack surface.

So I built forge-contextguard (MIT, TypeScript on Node 22) with a live browser sandbox at xgbtxy.github.io/forge-contextguard. It takes the deterministic scanning and fail-closed verification ideas from my pure-Rust agent toolkit ap and applies them to Forge, Rovo, and MCP capability gating.

Why deterministic, regex-free code-point scanning

Regex engines are awkward to reason about across non-BMP Unicode planes and surrogate pairs, and complex patterns carry backtracking risk. Instead, the scanner in forge-contextguard walks code points directly against fixed tables with zero regexes in the detection path:

  • BiDi controls (U+202A..U+202E, U+2066..U+2069): catches directional overrides and isolates that reorder rendered text relative to token order.
  • Unicode Tag block (U+E0000..E007F): detects invisible tag characters and decodes them back to ASCII so the audit receipt surfaces what was hidden inside an otherwise normal string.
  • Zero-width obfuscation: detects ZWSP, ZWNJ, ZWJ, WJ, BOM, and soft-hyphen splitting so obfuscated keywords cannot slip past phrase checks.
  • 22 fixed CaMeL-style injection phrases: treats untrusted content as data and flags instruction/delimiter breakouts without invoking a model.

Because tool errors are an under-watched injection vector, the same scanner runs on tool error strings before they reach an agent loop.

Policy gate, capability checks, and fail-closed receipts

Scanning text alone is not enough—a completely clean-looking input can still ask a read-only tool to perform a write or delete. forge-contextguard pairs the content scan with a pure-function policy gate that checks an explicit tool allow-list and capability allow-list.

Every evaluation returns ALLOW, QUARANTINE, or BLOCK alongside a structured audit receipt (verdict, errorClass, reasons, findings, failClosed). Malformed inputs or unexpected evaluator exceptions fail closed to BLOCK while keeping errorClass and failClosed visible so bugs are not silently swallowed.

Surfaces in the repo (and honest scope)

The repository includes:

  • A manifest.yml defining a rovo:agent, an action module (scan-content-action), and a jira:issuePanel UI.
  • A transport-agnostic MCP JSON-RPC handler (initialize, tools/list, tools/call exposing contextguard_scan).
  • A Teamwork Graph node filter whose annotate() passes through only ALLOW nodes and withholds the rest.

To be clear about scope: the MCP handler and Teamwork Graph filter are transport-agnostic libraries, not deployed to a live customer tenant. Wiring them into a specific tenant is left to the deployer.

Byte-synced browser sandbox and benchmarks

One thing I wanted to avoid was a demo page drifting away from the actual TypeScript library. In forge-contextguard, docs/engine.js is generated directly from src/, and a unit test asserts that the generated browser engine is byte-identical. The live sandbox ships 12 presets—including benign Jira, benign PR, benign multilingual text, Unicode Tags, BiDi, zero-width splits, visible CaMeL IPI, tool-error injection, capability escalation, and unknown-tool checks—so anyone can inspect the exact receipt in a browser tab.

On verification and performance:

  • 32+ passing tests (32/32) including benign negative controls (ordinary Jira issues, PR comments, and multilingual UTF-8 text) so the gate is verified not to trigger on normal developer traffic, plus tsc --noEmit clean in CI.
  • Throughput (Node v22.21.0, Windows x64): roughly 20,000–25,000 full evaluations/s on 1 KB inputs (p50 ~30–40 microseconds) and 1,500–1,700 evals/s on 16 KB inputs (p50 ~0.5 ms, ~20–26 MB/s).

Where deterministic gates stop

A fixed rule set will not catch an arbitrary natural-language semantic attack, and it is not meant to replace architectural isolation. Where it helps is giving Forge, Rovo, and MCP tool loops a fast, auditable floor—catching hidden-channel smuggling and capability escalation deterministically before a model ever sees the text.

If you are building Forge or MCP tools, are you sanitizing tool outputs and error strings at the capability boundary, or relying on prompt-level instructions?

我觉得技术没有壁垒,在合适的时间做合适的事情就好,hhh