import type { RulesetRef, Severity, ToolDef, WardenGate, WardenGateInput, WardenGateResult, WardenLogger } from "./types.js"; /** * Static tool-definition scanner. * * The MCP tool *description* and *input schema* are attacker-controlled text the * model reads as trusted instructions — this is the tool-poisoning / prompt- * injection surface. We scan that text (never the live tool output) for known * signatures before a single token of it reaches the model. Cheap, deterministic, * and runs first so later gates can reason about its findings. * * Rules are TIERED, and the tier is what decides blocking — not severity: * * block — no plausible benign reading in a tool definition. Blocks at the * policy threshold like any other finding. * advise — legitimately appears in honest tool definitions. Reported, never * blocks, never reduces the score, at any `blockAtSeverity`. * * Ruleset v1 had one tier, so `api_key` in a schema carried the same weight as * "ignore all previous instructions". A GitHub-style server whose `create_issue` * takes an `api_key` and mentions a personal access token scored 0.40 and had the * tool blocked under the default policy — i.e. most real MCP servers were refused, * which is how a scanner gets switched off entirely. */ type Tier = "block" | "advise"; /** * Which part of a tool definition a rule is meaningful against. * * `name` is an IDENTIFIER, not prose, and that difference decides the table * below. A rule that keys on a noun - `api_key`, `private_key`, `.env` - matches * ordinary identifiers (`sign_with_private_key` is a plausible wallet tool), so * running it over names would refuse honest servers on their naming convention: * exactly the ruleset v1 mistake, one surface over. A rule that keys on a PHRASE * needs whitespace and cannot match `snake_case` at all, and the two hidden-payload * rules are about characters that are never legitimate in a name. * * Names were scanned by nothing at all until ruleset v3, which meant zero-width * characters and a base64 blob could sit in the one field that reaches the model * first and WARDEN reported nothing. */ type Surface = "name" | "description" | "inputSchema" | "title" | "outputSchema" | "annotations" | "metadata"; /** * Ruleset version. Bump on ANY change to the table above — a scan result is only * comparable to another scan made under the same version and digest. * * 1 — single tier; credential parameter names blocked real servers. * 2 — block/advise tiers; exfil "send … to" anchored on an external destination; * TOOL_DEF_SECRET_HARVEST added so demoting the credential nouns does not * open a hole; advisory findings no longer affect the score. * 3 — rules gained `surfaces`, and the tool NAME became a scanned surface. Until * v3 the name was scanned by nothing, so zero-width characters, a base64 blob * or an injection phrase in the one field that reaches the model first went * entirely unreported. Noun-keyed rules stay off the name on purpose: they * match ordinary identifiers, and refusing `sign_with_private_key` would be * the v1 calibration error committed on a new surface. * 4 — calibrated against 1 108 live public MCP servers (docs/mcp-survey.md). v3 * blocked 50 of them and only 4 held up on review, so v4 adds context * GUARDS — polarity, quotation, URI form, payload length, entropy, script * adjacency — and demotes four blocking rules the survey showed were * selecting for honest servers: the bare `exfiltrat*` noun, `system prompt`, * `do not tell the user`, and (in severity only) the credential nouns. A * rule's guards are part of this table and therefore of the digest. * 5 — language-independent coverage. Text is FOLDED before matching (see ./fold.ts, FOLD_ID in * the digest): NFKC, Unicode-tag decoding, invisible-character stripping and mixed-script * look-alike mapping, so an English rule cannot be defeated by spelling the words in * fullwidth, with a zero-width space inside a word, in tag characters, or with a Cyrillic * "о". A new TOOL_DEF_SECRET_EXFIL rule blocks on the language-independent PAIR of a secret * store and an external address in one definition. Three field false positives are guarded * out: "send the user to " (a redirect, `navigation`), "without asking the user" in * autonomy phrasing (`autonomy`), and the zero-width joiner inside an emoji sequence. The * hidden-character rule now also catches the Unicode-tag block and the bidi isolates. */ export declare const STATIC_SCAN_RULESET_VERSION = "23"; export interface StaticScanRule { code: string; severity: Severity; tier: Tier; /** Which surfaces the rule is run against, so a re-run scans the same fields. */ surfaces: Surface[]; /** The regex source, so a third party can re-run the exact rule. */ source: string; flags: string; /** * Which context guards this rule is subject to. Published because the regex * alone no longer describes the rule: the same pattern with and without * `polarity` reports different findings on the same text. */ guards: string[]; /** True when the rule matches the raw text rather than the folded form. */ raw: boolean; } export interface StaticScanRuleset extends RulesetRef { /** Identity of the pre-match text fold this ruleset applies. See ./fold.ts. */ fold: string; rules: StaticScanRule[]; } /** * The rule table plus its digest, so a scan result stays checkable after the * rules change. * * Sorted, so the digest depends on the rules and not on the order they happen to * be declared in — and sorted by CODE-UNIT comparison, not `localeCompare`: the * digest is a cross-machine identifier, and a locale-dependent collation would * make the same rule table digest differently on a differently-configured host, * which is exactly the divergence the digest exists to detect. The preimage is * the RFC 8785 canonical form (see ./jcs.ts) so this file does not invent a * second serialization of its own. */ export declare function staticScanRuleset(): StaticScanRuleset; /** Just the identity of the rule table, for embedding in a verdict. */ export declare function staticScanRulesetRef(): RulesetRef; export declare class StaticScanGate implements WardenGate { private readonly semanticallyClean?; readonly name = "static-scan"; private readonly log; /** * @param log where dropped matches are reported. A guard silently discarding a * finding is the one behaviour in this gate that cannot be seen in the * verdict, so it is the one that most needs a debug line. */ constructor(log?: WardenLogger, semanticallyClean?: ((tool: ToolDef) => boolean) | undefined); evaluate(input: WardenGateInput): Promise; } export {}; //# sourceMappingURL=static-scan.d.ts.map