/** * `*`-glob matching, without a regular expression. * * WARDEN matches two kinds of glob against attacker-controlled text: threat-feed * patterns (a signed publisher chooses the pattern, a hostile server chooses the * haystack) and `policy.sensitiveToolPatterns` (the operator chooses the pattern, * the server chooses the tool name). Both used to compile `*` into `.*` and run a * regex, which is a denial of service: * * pattern "*a*a*a*a*a*a*a*a*a*a*a*a*a*a*zzz" (32 characters) * haystack "aaaa..." (220 characters) * -> 112 SECONDS inside one RegExp.test * * The engine has to try every way of distributing the wildcards over the haystack * before it can conclude "no match" - exponential in the number of `*`. That * mattered more than an ordinary performance bug: the threat feed's whole trust * story is that a compromised publisher can only ever ADD protection, never * remove it, and a record that hangs `vet()` forever removes all of it. The same * shape let a hostile server freeze the agent inspecting it, by advertising a * long enough tool name against an operator's own `*a*b*c*` pattern. * * The two-pointer algorithm below is the standard wildcard matcher: it walks the * haystack once and remembers only the most recent `*` to fall back to, so the * work is bounded by `pattern.length x value.length` with no backtracking tree to * explode. The same 32/220 case returns in microseconds. * * Semantics, matching what the regex did: `*` matches any run of zero or more * UTF-16 code units (including newlines - the old regex needed the `s` flag for * that), every other character is literal, and the match is anchored at both * ends. Case folding is the caller's job: both sides arrive already lowercased. */ export declare function wildcardMatch(pattern: string, value: string): boolean; /** * How many wildcards a pattern may carry. * * The matcher above is not exponential, but `*`-heavy patterns still cost * `pattern x value` per match and buy nothing: a real threat pattern names a * command, a path or a keyword. A record with more than this many wildcards is * refused rather than run - refusing an *addition* to the deny-list is the safe * direction, and it is reported loudly. */ export declare const MAX_GLOB_WILDCARDS = 12; /** Count `*` in a pattern, for the record validator. */ export declare function countWildcards(pattern: string): number; /** * Largest gap an INTERIOR `*` in a threat pattern may span. * * A field survey of 1 108 public MCP servers (see docs/mcp-survey.md) found every * multi-segment built-in firing on unrelated words that merely happened to appear * in the same paragraph: `*drain*wallet*` matched an anti-drainer scanner because * it says "drainer" in one clause and "wallet" in another, and `*seed*phrase*` * matched "for a **seed** topic, returns suggested search **phrases**". A real * threat pattern names something whose parts sit next to each other; 24 characters * is roughly "a few words apart" and comfortably covers "wallet seed or recovery * phrase". */ export declare const THREAT_MAX_GAP = 24; /** * Threat-pattern matching: `wildcardMatch` plus two constraints that only make * sense for a deny-list. * * 1. **Interior gaps are bounded** to {@link THREAT_MAX_GAP}. Leading and trailing * `*` stay unbounded — `*id_rsa*` must still find `id_rsa` anywhere. * 2. **A segment that starts with a word character must start at a word boundary.** * `*sweep*funds*` matched an ENS floor-sweeping tool because `funds` sits inside * "re**funds**". Only the START is anchored: a pattern author writing `*drain*` * means "drainer" too, so anchoring the end as well would break ordinary * stemming. * * Kept separate from {@link wildcardMatch} on purpose. That function is also what * `policy.sensitiveToolPatterns` runs on, where the operator wrote the pattern * against their own tool names and plain glob semantics are what they expect. * * Completeness matters here in a way it does not for a display filter: a missed * match is a deny-list entry that silently stopped working. So this explores every * reachable position per segment (deduplicated, so the work stays bounded by * `segments x value.length`) rather than taking the leftmost occurrence greedily, * which would report "no match" for a pattern that does match further along. */ export declare function threatMatch(pattern: string, value: string): boolean; //# sourceMappingURL=glob.d.ts.map