@webdecoy/node 0.11.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-CIRFOOMU.mjs +3351 -0
- package/dist/index.d.mts +1077 -1430
- package/dist/index.d.ts +1077 -1430
- package/dist/index.js +2198 -1190
- package/dist/index.mjs +435 -2689
- package/dist/sdk-DjeCBrHu.d.mts +1347 -0
- package/dist/sdk-DjeCBrHu.d.ts +1347 -0
- package/dist/testing.d.mts +85 -0
- package/dist/testing.d.ts +85 -0
- package/dist/testing.js +2250 -0
- package/dist/testing.mjs +113 -0
- package/package.json +9 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,927 +1,724 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* A local verifier for the WebDecoy Web Bot Auth profile (RFC 9421 HTTP
|
|
5
|
-
* Message Signatures, tag "web-bot-auth"). It answers one question about an
|
|
6
|
-
* inbound request: is it a *cryptographically verified* AI agent, an
|
|
7
|
-
* *impersonator* forging a known agent's identity, an unverifiable *claim*,
|
|
8
|
-
* or plain traffic carrying no agent signature at all?
|
|
9
|
-
*
|
|
10
|
-
* The verdict taxonomy mirrors the server-side verifier in the ingest service
|
|
11
|
-
* so the SDK, the edge validator, and the backend all speak
|
|
12
|
-
* the same language.
|
|
13
|
-
*/
|
|
14
|
-
/** The four possible outcomes of Web Bot Auth verification. */
|
|
15
|
-
type AgentStatus =
|
|
16
|
-
/** No Web Bot Auth signature on the request. Ordinary traffic. */
|
|
17
|
-
'none'
|
|
18
|
-
/** Signature verified against a curated agent's published key. Trustworthy. */
|
|
19
|
-
| 'verified'
|
|
20
|
-
/**
|
|
21
|
-
* A signature claiming a **known** agent's key that did **not** verify (bad
|
|
22
|
-
* signature, or outside its created/expires window). A forgery attempt —
|
|
23
|
-
* deny-able, tripwire-grade.
|
|
24
|
-
*/
|
|
25
|
-
| 'impersonation'
|
|
26
|
-
/**
|
|
27
|
-
* A signature is present but cannot be verified against any curated agent
|
|
28
|
-
* (unknown keyid, or an unsupported / malformed signature). An unverifiable
|
|
29
|
-
* claim — not proof of an agent, not proof of a forgery.
|
|
30
|
-
*/
|
|
31
|
-
| 'claimed';
|
|
32
|
-
/**
|
|
33
|
-
* Category an agent falls into, used for allow/deny policy. Matches the
|
|
34
|
-
* category taxonomy used by the edge validator and backend curation.
|
|
35
|
-
*/
|
|
36
|
-
type AgentCategory = 'ai_crawlers' | 'search_engines' | 'monitoring' | string;
|
|
37
|
-
/** The result of verifying one request. */
|
|
38
|
-
interface AgentVerdict {
|
|
39
|
-
/** Verification outcome. */
|
|
40
|
-
status: AgentStatus;
|
|
41
|
-
/** Human display name of the matched agent (e.g. "OpenAI"). Only on `verified`. */
|
|
42
|
-
agentName?: string;
|
|
43
|
-
/** Category of the matched agent. Only on `verified`. */
|
|
44
|
-
category?: AgentCategory;
|
|
45
|
-
/** The JWK thumbprint keyid the signature claimed. Present on verified/impersonation/claimed. */
|
|
46
|
-
keyId?: string;
|
|
47
|
-
/** Signature algorithm used (e.g. "ed25519", "rsa-pss-sha512"). Only on `verified`. */
|
|
48
|
-
algorithm?: string;
|
|
49
|
-
/**
|
|
50
|
-
* How the verdict was reached — always `'signature'` for now (Web Bot Auth
|
|
51
|
-
* cryptographic verification). Kept for parity with the ingest verifier,
|
|
52
|
-
* which also reports `ip_rdns` / `claimed` methods it derives from other
|
|
53
|
-
* signals unavailable in-process.
|
|
54
|
-
*/
|
|
55
|
-
method?: 'signature';
|
|
56
|
-
/** Short, non-sensitive reason string for non-verified outcomes (diagnostics). */
|
|
57
|
-
reason?: string;
|
|
58
|
-
}
|
|
59
|
-
/** A curated, trusted signing agent whose directory the SDK will fetch. */
|
|
60
|
-
interface SignedAgentDirectory {
|
|
61
|
-
/** Display name, e.g. "OpenAI". */
|
|
62
|
-
name: string;
|
|
63
|
-
/** Category for allow/deny policy. */
|
|
64
|
-
category: AgentCategory;
|
|
65
|
-
/**
|
|
66
|
-
* Origin (scheme + host) whose well-known HTTP Message Signatures directory
|
|
67
|
-
* publishes the agent's keys, e.g. `https://operator.openai.com`. The
|
|
68
|
-
* `/.well-known/http-message-signatures-directory` path is appended
|
|
69
|
-
* automatically. A full URL ending in a path is also accepted verbatim.
|
|
70
|
-
*/
|
|
71
|
-
directory: string;
|
|
72
|
-
}
|
|
73
|
-
/** Options for {@link createAgentVerifier}. */
|
|
74
|
-
interface AgentVerifierOptions {
|
|
75
|
-
/**
|
|
76
|
-
* Trusted agent directories to verify against. Defaults to
|
|
77
|
-
* {@link DEFAULT_SIGNED_AGENT_DIRECTORIES}. Only origins in this list are
|
|
78
|
-
* ever fetched — the request's own `Signature-Agent` header is never used to
|
|
79
|
-
* choose a fetch target, so there is no SSRF surface.
|
|
80
|
-
*/
|
|
81
|
-
directories?: SignedAgentDirectory[];
|
|
82
|
-
/**
|
|
83
|
-
* How long a fetched directory stays fresh, in milliseconds. After this the
|
|
84
|
-
* cached keys are still served (stale-while-revalidate) while a background
|
|
85
|
-
* refresh runs, so the warm path never blocks on the network.
|
|
86
|
-
* @default 21600000 (6 hours)
|
|
87
|
-
*/
|
|
88
|
-
cacheTtlMs?: number;
|
|
89
|
-
/**
|
|
90
|
-
* Per-directory fetch timeout in milliseconds.
|
|
91
|
-
* @default 5000
|
|
92
|
-
*/
|
|
93
|
-
fetchTimeoutMs?: number;
|
|
94
|
-
/**
|
|
95
|
-
* Clock-skew tolerance in seconds applied to a signature's created/expires
|
|
96
|
-
* window.
|
|
97
|
-
* @default 300 (5 minutes)
|
|
98
|
-
*/
|
|
99
|
-
toleranceSec?: number;
|
|
100
|
-
/** Emit debug logging to the console. @default false */
|
|
101
|
-
debug?: boolean;
|
|
102
|
-
/**
|
|
103
|
-
* Injectable fetch, primarily for tests. Defaults to the global `fetch`.
|
|
104
|
-
*/
|
|
105
|
-
fetchImpl?: typeof fetch;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* A request to verify. Either a WHATWG {@link Request} (the natural shape on
|
|
109
|
-
* Vercel Edge / Next.js middleware and Cloudflare Workers) or a plain object
|
|
110
|
-
* carrying the method, absolute URL, and headers.
|
|
111
|
-
*/
|
|
112
|
-
type AgentRequestInput = Request | {
|
|
113
|
-
method: string;
|
|
114
|
-
/** Absolute request URL, e.g. `https://example.com/path?q=1`. */
|
|
115
|
-
url: string;
|
|
116
|
-
/** Headers as a WHATWG `Headers` or a plain (lowercased-key) record. */
|
|
117
|
-
headers: Headers | Record<string, string>;
|
|
118
|
-
};
|
|
1
|
+
import { R as Rule, a as RuleContext, b as RuleResult, D as Decision, W as WebDecoy, c as WebDecoyConfig, P as ProtectOptions, d as RuleEngineResult, e as RateLimitConfig, F as FilterConfig, T as TripwireConfig, B as BotRuleConfig, f as BotAgent, g as BotCategory, A as AgentCategory, h as RateLimitStore, i as RateLimitConsume, j as RateLimitOutcome, k as AgentVerifierOptions, l as AgentRequestInput, m as AgentVerdict, S as SignedAgentDirectory } from './sdk-DjeCBrHu.js';
|
|
2
|
+
export { n as AgentStatus, o as BOT_CATEGORIES, p as BOT_REGISTRY, q as BotVerdict, C as Characteristic, r as Conclusion, s as DEFAULT_CHARACTERISTICS, t as DecisionCache, u as DecisionCacheOptions, v as DecisionInit, E as EDGE_CLASS_HEADER, w as EDGE_CLEARANCE_HEADER, x as EdgeClass, y as EdgeVerdict, I as IPEnrichmentData, L as LocalAnalysis, z as LogFields, G as Logger, M as MemoryRateLimitStore, H as ProtectResult, J as RequestMetadata, K as RuleOutcome, N as RuleState, O as SDKDetectionRequest, Q as SDKDetectionResponse, U as SyncRateLimitStore, V as TLSInfo, X as ViolationEvent, Y as classifyUserAgent, Z as consoleLogger, _ as deriveKey, $ as fromPino, a0 as matchUserAgent, a1 as newDecisionId, a2 as readEdgeVerdict, a3 as silentLogger } from './sdk-DjeCBrHu.js';
|
|
119
3
|
|
|
120
4
|
/**
|
|
121
|
-
* The
|
|
122
|
-
*
|
|
123
|
-
* WHY THIS MODULE EXISTS
|
|
124
|
-
*
|
|
125
|
-
* The Cloudflare clearance worker has set `x-wd-clearance` on every forwarded
|
|
126
|
-
* request since the validator shipped, and nothing has ever read it. Grepping the
|
|
127
|
-
* header across the monorepo, this SDK and the WordPress plugin returned only the
|
|
128
|
-
* worker that writes it, its own tests, and one documentation page. We shipped a
|
|
129
|
-
* tag no customer could act on, then documented it as "watch the header in your
|
|
130
|
-
* logs."
|
|
131
|
-
*
|
|
132
|
-
* That gap matters more than it sounds. On a scoped route the gate's only options
|
|
133
|
-
* were pass or challenge, and a challenge on public content is a 403 to every
|
|
134
|
-
* client that cannot run JavaScript — search crawlers included. Reading the tag
|
|
135
|
-
* gives the application a third option it owns: log it, meter it, skip an
|
|
136
|
-
* expensive query, serve something cheaper. That is the first "yes" a cautious
|
|
137
|
-
* operator can give.
|
|
138
|
-
*
|
|
139
|
-
* WHAT IT IS NOT
|
|
5
|
+
* The reserved test trigger.
|
|
140
6
|
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* strips inbound copies precisely so that the origin can attribute them to us.
|
|
144
|
-
* A request that reaches the origin WITHOUT passing through the proxy — straight
|
|
145
|
-
* to the origin IP, or a route that does not match — can carry anything. Treat
|
|
146
|
-
* `present: false` as "no information", never as "not a bot", and keep the origin
|
|
147
|
-
* unreachable except through the proxy if you intend to branch on this.
|
|
148
|
-
*/
|
|
149
|
-
/** Header the edge validator uses for its clearance verdict. */
|
|
150
|
-
declare const EDGE_CLEARANCE_HEADER = "x-wd-clearance";
|
|
151
|
-
/** Header the edge validator uses for the sensor's client classification. */
|
|
152
|
-
declare const EDGE_CLASS_HEADER = "x-wd-class";
|
|
153
|
-
/**
|
|
154
|
-
* What the edge sensor concluded the client is.
|
|
155
|
-
*
|
|
156
|
-
* - `verified` — an identity something other than the client has attested
|
|
157
|
-
* (Cloudflare's verified-bot signal). **Never degrade these.** This is
|
|
158
|
-
* Googlebot and friends, and quietly serving them less is how a customer loses
|
|
159
|
-
* search presence and blames you six weeks later.
|
|
160
|
-
* - `crawler` — self-declares as a crawler, unproven. Real-but-unverified
|
|
161
|
-
* crawlers and forged ones both land here.
|
|
162
|
-
* - `script` — an HTTP client library, a Chromium user agent sending no client
|
|
163
|
-
* hints, or no user agent at all. Not a browser.
|
|
164
|
-
* - `browser` — nothing that distinguishes a non-human fired. A statement about
|
|
165
|
-
* our signals, not a certificate.
|
|
166
|
-
*/
|
|
167
|
-
type EdgeClass = 'verified' | 'crawler' | 'script' | 'browser';
|
|
168
|
-
/**
|
|
169
|
-
* The edge's annotations on one request, typed.
|
|
7
|
+
* A request whose User-Agent starts with `WebDecoy-Test/` is the documented
|
|
8
|
+
* install-verification probe:
|
|
170
9
|
*
|
|
171
|
-
*
|
|
172
|
-
* in front of this request at all — and the difference between "the edge said
|
|
173
|
-
* browser" and "there is no edge here" is the difference between a safe
|
|
174
|
-
* optimisation and a security hole.
|
|
175
|
-
*/
|
|
176
|
-
interface EdgeVerdict {
|
|
177
|
-
/**
|
|
178
|
-
* True when the edge validator annotated this request. False means no
|
|
179
|
-
* information — not "human", not "safe".
|
|
180
|
-
*/
|
|
181
|
-
present: boolean;
|
|
182
|
-
/**
|
|
183
|
-
* The clearance verdict, e.g. `valid`, `missing`, `verified-bot`,
|
|
184
|
-
* `signed-agent`, `machine`, `insufficient-trust`. Free-form on purpose: the
|
|
185
|
-
* validator gains labels faster than an SDK release can enumerate them, and an
|
|
186
|
-
* unknown label must not become `undefined`.
|
|
187
|
-
*/
|
|
188
|
-
clearance?: string;
|
|
189
|
-
/** The sensor's classification, when it classified this request. */
|
|
190
|
-
class?: EdgeClass;
|
|
191
|
-
/** `class === 'verified'`. Convenience so callers need no string literals. */
|
|
192
|
-
isVerified: boolean;
|
|
193
|
-
/** `class === 'crawler'`. */
|
|
194
|
-
isCrawler: boolean;
|
|
195
|
-
/** `class === 'script'`. */
|
|
196
|
-
isScript: boolean;
|
|
197
|
-
/** `class === 'browser'`. */
|
|
198
|
-
isBrowser: boolean;
|
|
199
|
-
/**
|
|
200
|
-
* True for a class that is not a browser and is not attested — `script` or
|
|
201
|
-
* `crawler`.
|
|
202
|
-
*
|
|
203
|
-
* This is the predicate most applications actually want, and it deliberately
|
|
204
|
-
* excludes `verified`: the common intent is "cheapen this response", and the one
|
|
205
|
-
* population you must never cheapen for is the one whose identity was proven.
|
|
206
|
-
*/
|
|
207
|
-
isUnattestedNonBrowser: boolean;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Read the edge validator's annotations out of a request's headers.
|
|
10
|
+
* curl -A "WebDecoy-Test/1.0" http://localhost:3000/
|
|
211
11
|
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
12
|
+
* The SDK always reports it to ingest — before rules, before local-analysis
|
|
13
|
+
* thresholds, before sampling of any kind — so the developer who just
|
|
14
|
+
* installed the middleware gets a guaranteed, labeled detection in the
|
|
15
|
+
* dashboard within seconds, including from localhost. Ingest recognizes the
|
|
16
|
+
* same prefix server-side, marks the row `is_test`, and keeps it out of
|
|
17
|
+
* stats, billing, actor scoring, and enforcement.
|
|
214
18
|
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* that is not our worker, and in both cases silence beats a value a caller might
|
|
218
|
-
* branch on.
|
|
19
|
+
* Prefix-anchored on purpose: a UA that merely mentions the string mid-way
|
|
20
|
+
* is NOT the trigger, so real traffic can't hide behind the test label.
|
|
219
21
|
*/
|
|
220
|
-
|
|
22
|
+
/** Any User-Agent starting with this (case-insensitive) is a test trigger. */
|
|
23
|
+
declare const TEST_TRIGGER_UA_PREFIX = "WebDecoy-Test/";
|
|
24
|
+
/** The exact value the quickstart docs tell developers to send. */
|
|
25
|
+
declare const TEST_TRIGGER_USER_AGENT = "WebDecoy-Test/1.0";
|
|
26
|
+
/** Whether this User-Agent is the reserved test trigger. */
|
|
27
|
+
declare function isTestTriggerUserAgent(userAgent: string | undefined): boolean;
|
|
221
28
|
|
|
222
29
|
/**
|
|
223
|
-
*
|
|
30
|
+
* Resolving the client IP address behind a proxy.
|
|
224
31
|
*
|
|
225
|
-
*
|
|
226
|
-
* Regenerate with `packages/webdecoy/scripts/gen-bot-registry.mjs`; see that
|
|
227
|
-
* script for the command.
|
|
32
|
+
* WHY THIS MODULE EXISTS
|
|
228
33
|
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
34
|
+
* Every adapter used to read the leftmost value of `X-Forwarded-For` and call it
|
|
35
|
+
* the client. That header is written by the client for the first hop, so the
|
|
36
|
+
* leftmost value is whatever the caller decided to put there. One
|
|
37
|
+
* `-H 'X-Forwarded-For: 1.2.3.4'` gave an attacker a fresh rate-limit bucket per
|
|
38
|
+
* forged address, put an address of their choosing on every violation we
|
|
39
|
+
* reported, and made `filter({ expression: 'ip.tor' })` an opt-in check.
|
|
40
|
+
*
|
|
41
|
+
* A forwarding header is only evidence if you know who wrote it. So the default
|
|
42
|
+
* here is to not read one at all: use the address the connection actually came
|
|
43
|
+
* from, and make the operator say how many proxies sit in front before we
|
|
44
|
+
* believe anything else. The WordPress plugin already works this way; this
|
|
45
|
+
* brings the Node adapters in line.
|
|
46
|
+
*
|
|
47
|
+
* THE MODEL
|
|
48
|
+
*
|
|
49
|
+
* Each proxy appends the address it received the connection from, so the
|
|
50
|
+
* observed chain outermost-first is `[...X-Forwarded-For, peer]` and the entries
|
|
51
|
+
* to the RIGHT are the ones added by infrastructure you control. Trust is
|
|
52
|
+
* therefore counted from the right: with one proxy in front of you, the client
|
|
53
|
+
* is the last `X-Forwarded-For` entry; with two, the second from last. Anything
|
|
54
|
+
* further left was supplied by someone you have no reason to believe.
|
|
55
|
+
*
|
|
56
|
+
* No `node:net` — this runs in Edge and Workers runtimes too, so the address
|
|
57
|
+
* parsing is hand-rolled and covered by tests.
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* How much of the forwarding chain to believe.
|
|
61
|
+
*
|
|
62
|
+
* - `false` (default) — read no forwarding headers; the peer address is the
|
|
63
|
+
* client. Correct for an app exposed directly, and safe for one that isn't:
|
|
64
|
+
* it attributes traffic to your proxy rather than to a forged address.
|
|
65
|
+
* - `number` — the number of trusted proxies between the client and this
|
|
66
|
+
* process. The client is the Nth entry from the right of `X-Forwarded-For`.
|
|
67
|
+
* - `'cloudflare'` — use `CF-Connecting-IP`. Only meaningful if the origin is
|
|
68
|
+
* unreachable except through Cloudflare, since the header is otherwise just
|
|
69
|
+
* another thing a client can send.
|
|
70
|
+
* - `string[]` — CIDRs (or bare addresses) of the proxies you run. The chain is
|
|
71
|
+
* walked right to left and the first address that isn't one of yours is the
|
|
72
|
+
* client. Use this when the depth varies.
|
|
73
|
+
*/
|
|
74
|
+
type TrustedProxies = false | number | 'cloudflare' | string[];
|
|
75
|
+
/** Headers as either a Node-style bag or a WHATWG `Headers`. */
|
|
76
|
+
type HeaderSource = Record<string, string | string[] | undefined> | {
|
|
77
|
+
get(name: string): string | null;
|
|
78
|
+
};
|
|
79
|
+
interface ResolveClientIpOptions {
|
|
80
|
+
/** Request headers. */
|
|
81
|
+
headers: HeaderSource;
|
|
82
|
+
/** The address the connection came from, when the runtime exposes one. */
|
|
83
|
+
peer?: string;
|
|
84
|
+
/** How much of the forwarding chain to believe. Defaults to `false`. */
|
|
85
|
+
trustProxy?: TrustedProxies;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Strip the decoration real-world sources add to an address — brackets, a port,
|
|
89
|
+
* an IPv6 zone id — and return it in a canonical form, or null if what's left
|
|
90
|
+
* isn't an address at all.
|
|
234
91
|
*
|
|
235
|
-
*
|
|
92
|
+
* IPv4-mapped IPv6 (`::ffff:203.0.113.9`) collapses to the IPv4 form, so a
|
|
93
|
+
* dual-stack listener and an `X-Forwarded-For` entry for the same client
|
|
94
|
+
* produce the same key.
|
|
236
95
|
*/
|
|
96
|
+
declare function normalizeIp(raw: string | undefined | null): string | null;
|
|
237
97
|
/**
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* Declared here rather than hand-written next door so a category added in Go
|
|
241
|
-
* cannot go missing in TypeScript.
|
|
98
|
+
* Whether an address falls inside a CIDR range. A bare address is treated as a
|
|
99
|
+
* single-host range. Families never match across each other.
|
|
242
100
|
*/
|
|
243
|
-
|
|
244
|
-
/** One entry in the registry. */
|
|
245
|
-
interface BotAgent {
|
|
246
|
-
/** Stable lowercase slug, e.g. `gptbot`. */
|
|
247
|
-
id: string;
|
|
248
|
-
/** Display name, e.g. `GPTBot`. */
|
|
249
|
-
name: string;
|
|
250
|
-
category: BotCategory;
|
|
251
|
-
/** Operator, e.g. `OpenAI`. */
|
|
252
|
-
organization: string;
|
|
253
|
-
/** The registry's default threat score for this agent (0-100). */
|
|
254
|
-
baseScore: number;
|
|
255
|
-
/** Whether the operator documents honouring robots.txt. */
|
|
256
|
-
respectsRobots: boolean;
|
|
257
|
-
/** Lowercase User-Agent substrings that identify it. */
|
|
258
|
-
uaPatterns: readonly string[];
|
|
259
|
-
}
|
|
260
|
-
/** Every declared category, including any with no agents yet. */
|
|
261
|
-
declare const BOT_CATEGORIES: readonly BotCategory[];
|
|
262
|
-
/** The agent table, in match order. */
|
|
263
|
-
declare const BOT_REGISTRY: readonly BotAgent[];
|
|
264
|
-
|
|
101
|
+
declare function ipInCidr(ip: string, cidr: string): boolean;
|
|
265
102
|
/**
|
|
266
|
-
*
|
|
103
|
+
* Resolve the client IP for a request.
|
|
267
104
|
*
|
|
268
|
-
*
|
|
105
|
+
* Returns `undefined` only when there is nothing to go on: no peer address and
|
|
106
|
+
* no header the configuration says to believe. Callers supply their own last
|
|
107
|
+
* resort, because what that should be is a per-framework question.
|
|
269
108
|
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
* registry is generated into {@link BOT_REGISTRY} and matched here.
|
|
275
|
-
*
|
|
276
|
-
* WHAT THIS IS NOT
|
|
277
|
-
*
|
|
278
|
-
* This is a User-Agent lookup. It identifies agents that say who they are, and
|
|
279
|
-
* nothing else. An agent that spoofs Chrome is invisible to it, and always will
|
|
280
|
-
* be — that is the point of the 1% User-Agent weight in the unified score, and
|
|
281
|
-
* nothing here changes that arithmetic.
|
|
282
|
-
*
|
|
283
|
-
* That is a feature for the use case it serves. GPTBot, ClaudeBot and Googlebot
|
|
284
|
-
* all self-identify honestly, and the decision a customer wants to make about
|
|
285
|
-
* them ("don't train on my content") is a POLICY choice about a cooperative
|
|
286
|
-
* agent, not a threat judgement about a hostile one. Acting on a claim is
|
|
287
|
-
* correct when the claim is the thing you care about.
|
|
288
|
-
*
|
|
289
|
-
* For agents that lie, the answer is the rest of the product: tripwires,
|
|
290
|
-
* honeytokens and the edge classifier see behaviour, which cannot be spoofed by
|
|
291
|
-
* editing a header.
|
|
109
|
+
* Whenever the configured source is missing or malformed this falls back to the
|
|
110
|
+
* peer address rather than reaching further left in the chain. The peer is the
|
|
111
|
+
* one address on a request that cannot be forged, so a wrong-but-real proxy
|
|
112
|
+
* address beats a plausible-looking value the caller chose.
|
|
292
113
|
*/
|
|
114
|
+
declare function resolveClientIp(options: ResolveClientIpOptions): string | undefined;
|
|
293
115
|
|
|
294
116
|
/**
|
|
295
|
-
*
|
|
117
|
+
* Detection engine types.
|
|
296
118
|
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
|
|
301
|
-
interface BotVerdict {
|
|
302
|
-
/** Whether the User-Agent matched a known agent. */
|
|
303
|
-
known: boolean;
|
|
304
|
-
/** Registry slug, e.g. `gptbot`. Undefined when unknown. */
|
|
305
|
-
id?: string;
|
|
306
|
-
/** Display name, e.g. `GPTBot`. Undefined when unknown. */
|
|
307
|
-
name?: string;
|
|
308
|
-
/** Customer-facing category — the same vocabulary as the dashboard. */
|
|
309
|
-
category: BotCategory;
|
|
310
|
-
/** Operator, e.g. `OpenAI`. Undefined when unknown. */
|
|
311
|
-
organization?: string;
|
|
312
|
-
/** The registry's threat score for this agent, 0-100. 0 when unknown. */
|
|
313
|
-
score: number;
|
|
314
|
-
/**
|
|
315
|
-
* Whether the operator documents honouring robots.txt. Undefined when unknown.
|
|
316
|
-
*
|
|
317
|
-
* Documented behaviour, not observed behaviour — it is what the operator
|
|
318
|
-
* publishes, so treat it as a claim like any other.
|
|
319
|
-
*/
|
|
320
|
-
respectsRobots?: boolean;
|
|
321
|
-
/** True for training crawlers, AI search crawlers, AI agents and assistants. */
|
|
322
|
-
isAI: boolean;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Find the agent behind a User-Agent string, or undefined.
|
|
119
|
+
* The detection engine scores a set of client-collected `Signals` against ~40
|
|
120
|
+
* behavioral, environmental, and fingerprint heuristics and produces a verdict.
|
|
121
|
+
* Ported from the FCaptcha scoring engine so behavior matches the self-hosted
|
|
122
|
+
* server (server.js `runVerification`).
|
|
326
123
|
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*/
|
|
331
|
-
declare function matchUserAgent(userAgent: string | undefined | null): BotAgent | undefined;
|
|
332
|
-
/** Classify a User-Agent into the verdict rules evaluate against. */
|
|
333
|
-
declare function classifyUserAgent(userAgent: string | undefined | null): BotVerdict;
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Rules Engine Types
|
|
337
|
-
* Core interfaces for the WebDecoy rules engine
|
|
338
|
-
*/
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Context available to rules during evaluation
|
|
342
|
-
*/
|
|
343
|
-
interface RuleContext {
|
|
344
|
-
/** Client IP address */
|
|
345
|
-
ip: string;
|
|
346
|
-
/** Request path */
|
|
347
|
-
path: string;
|
|
348
|
-
/** HTTP method */
|
|
349
|
-
method: string;
|
|
350
|
-
/** User-Agent string */
|
|
351
|
-
userAgent?: string;
|
|
352
|
-
/** Request headers (lowercase keys) */
|
|
353
|
-
headers: Record<string, string>;
|
|
354
|
-
/** Request timestamp */
|
|
355
|
-
timestamp: number;
|
|
356
|
-
/** IP enrichment data (populated async when available) */
|
|
357
|
-
enrichment?: IPEnrichmentData;
|
|
358
|
-
/**
|
|
359
|
-
* Web Bot Auth verdict (populated async before evaluation when a
|
|
360
|
-
* `webBotAuth` rule is
|
|
361
|
-
* present). Lets a synchronous rule act on cryptographic agent verification.
|
|
362
|
-
*/
|
|
363
|
-
agent?: AgentVerdict;
|
|
364
|
-
/**
|
|
365
|
-
* The edge validator's annotations on this request, parsed from
|
|
366
|
-
* `x-wd-clearance` and `x-wd-class`. Always populated — `present: false` when
|
|
367
|
-
* the edge did not front this request. Filter expressions read it as
|
|
368
|
-
* `edge.class`, `edge.clearance` and `edge.present`.
|
|
369
|
-
*/
|
|
370
|
-
edge?: EdgeVerdict;
|
|
371
|
-
/**
|
|
372
|
-
* Who the User-Agent says it is, matched against the generated agent
|
|
373
|
-
* registry. Always populated — `known: false` when nothing matched. Filter
|
|
374
|
-
* expressions read it as `bot.category`, `bot.name`, `bot.ai` and friends.
|
|
375
|
-
*
|
|
376
|
-
* A self-declared identity, so it is evidence about cooperative agents only.
|
|
377
|
-
* See {@link BotVerdict}.
|
|
378
|
-
*/
|
|
379
|
-
bot?: BotVerdict;
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* Result of evaluating a single rule
|
|
383
|
-
*/
|
|
384
|
-
interface RuleResult {
|
|
385
|
-
/** Action to take */
|
|
386
|
-
action: 'ALLOW' | 'DENY' | 'THROTTLE';
|
|
387
|
-
/** Name of the rule that produced this result */
|
|
388
|
-
rule: string;
|
|
389
|
-
/** Human-readable reason */
|
|
390
|
-
reason?: string;
|
|
391
|
-
/** Additional metadata */
|
|
392
|
-
metadata?: Record<string, any>;
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* A rule that can evaluate request context and produce a decision
|
|
396
|
-
*/
|
|
397
|
-
interface Rule {
|
|
398
|
-
/** Unique name for this rule */
|
|
399
|
-
name: string;
|
|
400
|
-
/** Evaluate the rule against request context */
|
|
401
|
-
evaluate(context: RuleContext): RuleResult;
|
|
402
|
-
/** Clean up resources (timers, etc.) */
|
|
403
|
-
destroy?(): void;
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Configuration for rate limiting
|
|
407
|
-
*/
|
|
408
|
-
interface RateLimitConfig {
|
|
409
|
-
/** Maximum requests allowed in the window */
|
|
410
|
-
max: number;
|
|
411
|
-
/** Window size in seconds */
|
|
412
|
-
window: number;
|
|
413
|
-
/** Algorithm: 'fixed' (default) or 'sliding' */
|
|
414
|
-
algorithm?: 'fixed' | 'sliding';
|
|
415
|
-
/** Custom key derivation function. Default: by IP */
|
|
416
|
-
keyBy?: (context: RuleContext) => string;
|
|
417
|
-
/** Action when limit is exceeded: 'DENY' or 'THROTTLE' (default: 'THROTTLE') */
|
|
418
|
-
action?: 'DENY' | 'THROTTLE';
|
|
419
|
-
/** Dry run mode: log violations but don't block */
|
|
420
|
-
dryRun?: boolean;
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Configuration for filter rules
|
|
124
|
+
* Signals originate from an untrusted client, so every field is optional and the
|
|
125
|
+
* detectors fall back to neutral defaults (mirroring the `?? default` pattern in
|
|
126
|
+
* the reference implementation).
|
|
424
127
|
*/
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
128
|
+
/** A single triggered heuristic. */
|
|
129
|
+
interface Detection {
|
|
130
|
+
/** Scoring bucket this detection contributes to (see {@link Weights}). */
|
|
131
|
+
category: string;
|
|
132
|
+
/** Likelihood this signal indicates a bot/attack, 0..1. */
|
|
133
|
+
score: number;
|
|
134
|
+
/** Certainty of the score, 0..1, used to weight the per-category aggregate. */
|
|
135
|
+
confidence: number;
|
|
136
|
+
/** Human-readable explanation. */
|
|
137
|
+
reason: string;
|
|
138
|
+
/** Optional structured detail (e.g. keystroke-cadence metrics). */
|
|
139
|
+
details?: Record<string, unknown>;
|
|
432
140
|
}
|
|
433
|
-
/**
|
|
434
|
-
|
|
435
|
-
*/
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
141
|
+
/** Per-category aggregated scores (0..1), keyed by category name. */
|
|
142
|
+
type CategoryScores = Record<string, number>;
|
|
143
|
+
/** Final action recommendation derived from the weighted score. */
|
|
144
|
+
type Recommendation = 'allow' | 'challenge' | 'block';
|
|
145
|
+
/** Behavioral signals: mouse, touch, keyboard, and interaction timing. */
|
|
146
|
+
interface BehavioralSignals {
|
|
147
|
+
totalPoints?: number;
|
|
148
|
+
trajectoryLength?: number;
|
|
149
|
+
approachPoints?: number;
|
|
150
|
+
touchEvents?: number;
|
|
151
|
+
keyEvents?: number;
|
|
152
|
+
microTremorScore?: number;
|
|
153
|
+
approachDirectness?: number;
|
|
154
|
+
clickPrecision?: number;
|
|
155
|
+
explorationRatio?: number;
|
|
156
|
+
velocityVariance?: number;
|
|
157
|
+
overshootCorrections?: number;
|
|
158
|
+
interactionDuration?: number;
|
|
159
|
+
mouseEventRate?: number;
|
|
160
|
+
straightLineRatio?: number;
|
|
161
|
+
directionChanges?: number;
|
|
162
|
+
eventDeltaVariance?: number;
|
|
163
|
+
touchTotalPoints?: number;
|
|
164
|
+
touchForceMin?: number;
|
|
165
|
+
touchForceMax?: number;
|
|
166
|
+
touchForceVariance?: number;
|
|
167
|
+
touchForceAllOne?: boolean;
|
|
168
|
+
touchForceAllZero?: boolean;
|
|
169
|
+
touchRadiusMin?: number;
|
|
170
|
+
touchRadiusMax?: number;
|
|
171
|
+
touchRadiusVariance?: number;
|
|
172
|
+
touchUniqueIdentifiers?: number;
|
|
173
|
+
touchMultiTouchSeen?: boolean;
|
|
174
|
+
touchStraightLineRatio?: number;
|
|
175
|
+
touchMicroTremorScore?: number;
|
|
176
|
+
touchDirectionChanges?: number;
|
|
177
|
+
[key: string]: unknown;
|
|
458
178
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
/** Exact hidden honeypot paths (e.g. a honeytoken path or `/admin-backup.zip`). */
|
|
464
|
-
paths?: string[];
|
|
465
|
-
/** Path prefixes treated as tripwires (e.g. `/.git/`). */
|
|
466
|
-
prefixes?: string[];
|
|
467
|
-
/** Regex patterns for tripwire paths. */
|
|
468
|
-
patterns?: RegExp[];
|
|
469
|
-
/** Include the built-in scanner/scraper bait paths. Default `true`. */
|
|
470
|
-
includeDefaults?: boolean;
|
|
471
|
-
/** Action when a tripwire is hit: 'DENY' (default) or 'THROTTLE'. */
|
|
472
|
-
action?: 'DENY' | 'THROTTLE';
|
|
473
|
-
/** Dry run mode: log the violation but don't block. */
|
|
474
|
-
dryRun?: boolean;
|
|
179
|
+
interface PoWTiming {
|
|
180
|
+
duration?: number;
|
|
181
|
+
iterations?: number;
|
|
182
|
+
[key: string]: unknown;
|
|
475
183
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
/** Rule that triggered */
|
|
481
|
-
rule: string;
|
|
482
|
-
/** Action taken */
|
|
483
|
-
action: 'DENY' | 'THROTTLE' | 'ALLOW';
|
|
484
|
-
/** Client IP */
|
|
485
|
-
ip: string;
|
|
486
|
-
/** Request path */
|
|
487
|
-
path?: string;
|
|
488
|
-
/** HTTP method */
|
|
489
|
-
method?: string;
|
|
490
|
-
/** User-Agent */
|
|
491
|
-
userAgent?: string;
|
|
492
|
-
/** Reason for the violation */
|
|
493
|
-
reason?: string;
|
|
494
|
-
/**
|
|
495
|
-
* The request's wd_clearance token, when present. Lets the backend bind a
|
|
496
|
-
* tripwire hit to the actor's device fingerprint and deny it — the same
|
|
497
|
-
* durable lockout a decoy hit produces. Only carried
|
|
498
|
-
* for deception rules (tripwires); undefined otherwise.
|
|
499
|
-
*/
|
|
500
|
-
clearance?: string;
|
|
501
|
-
/** Additional metadata */
|
|
502
|
-
metadata?: Record<string, any>;
|
|
503
|
-
/** Whether this was a dry run */
|
|
504
|
-
dryRun: boolean;
|
|
505
|
-
/** When the violation occurred (ISO 8601) */
|
|
506
|
-
timestamp: string;
|
|
184
|
+
interface TemporalSignals {
|
|
185
|
+
pow?: PoWTiming;
|
|
186
|
+
pageLoadToFirstInteraction?: number | null;
|
|
187
|
+
[key: string]: unknown;
|
|
507
188
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
proxy: boolean;
|
|
516
|
-
tor: boolean;
|
|
517
|
-
relay: boolean;
|
|
518
|
-
hosting: boolean;
|
|
189
|
+
interface EnvironmentalSignals {
|
|
190
|
+
webdriver?: boolean;
|
|
191
|
+
headlessIndicators?: {
|
|
192
|
+
hasOuterDimensions?: boolean;
|
|
193
|
+
innerEqualsOuter?: boolean;
|
|
194
|
+
notificationPermission?: string;
|
|
195
|
+
[key: string]: unknown;
|
|
519
196
|
};
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
197
|
+
automationFlags?: {
|
|
198
|
+
plugins?: number;
|
|
199
|
+
languages?: boolean;
|
|
200
|
+
chrome?: boolean;
|
|
201
|
+
platform?: string;
|
|
202
|
+
maxTouchPoints?: number;
|
|
203
|
+
hardwareConcurrency?: number;
|
|
204
|
+
[key: string]: unknown;
|
|
525
205
|
};
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
206
|
+
navigator?: {
|
|
207
|
+
platform?: string;
|
|
208
|
+
maxTouchPoints?: number;
|
|
209
|
+
[key: string]: unknown;
|
|
529
210
|
};
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
is_high_risk: boolean;
|
|
211
|
+
webglInfo?: {
|
|
212
|
+
renderer?: string;
|
|
213
|
+
[key: string]: unknown;
|
|
534
214
|
};
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
* Threat score threshold for blocking (0-100)
|
|
575
|
-
* Requests with scores above this will be blocked
|
|
576
|
-
* @default 80
|
|
577
|
-
*/
|
|
578
|
-
threatScoreThreshold?: number;
|
|
579
|
-
/**
|
|
580
|
-
* Timeout for API requests in milliseconds
|
|
581
|
-
* @default 5000
|
|
582
|
-
*/
|
|
583
|
-
timeout?: number;
|
|
584
|
-
/**
|
|
585
|
-
* Enable debug logging
|
|
586
|
-
* @default false
|
|
587
|
-
*/
|
|
588
|
-
debug?: boolean;
|
|
589
|
-
/**
|
|
590
|
-
* Whether to reject unauthorized TLS certificates
|
|
591
|
-
* Set to false for development/testing with self-signed certificates
|
|
592
|
-
* @default true
|
|
593
|
-
*/
|
|
594
|
-
tlsRejectUnauthorized?: boolean;
|
|
595
|
-
/**
|
|
596
|
-
* Rules to evaluate before calling the detection API
|
|
597
|
-
* Rules are evaluated in order; first DENY/THROTTLE wins
|
|
598
|
-
*/
|
|
599
|
-
rules?: Rule[];
|
|
600
|
-
/**
|
|
601
|
-
* Options for local Web Bot Auth agent verification (used by `detectBot()`
|
|
602
|
-
* and the `webBotAuth()` rule) — trusted directories, cache TTL, etc.
|
|
603
|
-
* Defaults are sensible; override only to curate your own agent allowlist.
|
|
604
|
-
*/
|
|
605
|
-
webBotAuth?: AgentVerifierOptions;
|
|
215
|
+
playwright?: {
|
|
216
|
+
detected?: boolean;
|
|
217
|
+
signals?: string[];
|
|
218
|
+
};
|
|
219
|
+
cdp?: {
|
|
220
|
+
detected?: boolean;
|
|
221
|
+
signals?: string[];
|
|
222
|
+
};
|
|
223
|
+
jsExecutionTime?: {
|
|
224
|
+
mathOps?: number;
|
|
225
|
+
[key: string]: unknown;
|
|
226
|
+
};
|
|
227
|
+
rafConsistency?: {
|
|
228
|
+
frameTimeVariance?: number;
|
|
229
|
+
[key: string]: unknown;
|
|
230
|
+
};
|
|
231
|
+
canvasHash?: {
|
|
232
|
+
hash?: string;
|
|
233
|
+
error?: unknown;
|
|
234
|
+
supported?: boolean;
|
|
235
|
+
[key: string]: unknown;
|
|
236
|
+
};
|
|
237
|
+
sensor?: {
|
|
238
|
+
motionEventCount?: number;
|
|
239
|
+
motionAccelVariance?: number;
|
|
240
|
+
orientationEventCount?: number;
|
|
241
|
+
orientationVariance?: number;
|
|
242
|
+
[key: string]: unknown;
|
|
243
|
+
};
|
|
244
|
+
webrtcInfo?: WebRTCInfo;
|
|
245
|
+
speechInfo?: SpeechInfo;
|
|
246
|
+
workerConsistency?: WorkerConsistencyInfo;
|
|
247
|
+
cssMediaQueries?: CSSMediaQueriesInfo;
|
|
248
|
+
fontsInfo?: FontsInfo;
|
|
249
|
+
permissionsInfo?: PermissionsInfo;
|
|
250
|
+
domRectFingerprint?: DOMRectInfo;
|
|
251
|
+
audioInfo?: AudioContextInfo;
|
|
252
|
+
lieDetection?: LieDetectionInfo;
|
|
253
|
+
[key: string]: unknown;
|
|
606
254
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
/** EC point formats */
|
|
620
|
-
ec_point_formats?: number[];
|
|
621
|
-
/** Signature algorithms */
|
|
622
|
-
signature_algorithms?: number[];
|
|
623
|
-
/** Server name indication */
|
|
624
|
-
server_name?: string;
|
|
625
|
-
/** ALPN protocols */
|
|
626
|
-
alpn_protocols?: string[];
|
|
255
|
+
interface WebRTCInfo {
|
|
256
|
+
supported?: boolean;
|
|
257
|
+
mediaDevices?: {
|
|
258
|
+
supported?: boolean;
|
|
259
|
+
audioInputs?: number;
|
|
260
|
+
audioOutputs?: number;
|
|
261
|
+
videoInputs?: number;
|
|
262
|
+
totalDevices?: number;
|
|
263
|
+
};
|
|
264
|
+
hasLocalIP?: boolean;
|
|
265
|
+
localIPError?: unknown;
|
|
266
|
+
[key: string]: unknown;
|
|
627
267
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
method: string;
|
|
634
|
-
/** Request path */
|
|
635
|
-
path: string;
|
|
636
|
-
/** Client IP address (REQUIRED) */
|
|
637
|
-
ip: string;
|
|
638
|
-
/** User-Agent header */
|
|
639
|
-
user_agent?: string;
|
|
640
|
-
/** All request headers */
|
|
641
|
-
headers: Record<string, string>;
|
|
642
|
-
/** TLS connection information */
|
|
643
|
-
tls_info?: TLSInfo;
|
|
644
|
-
/** Request timestamp (Unix milliseconds) */
|
|
645
|
-
timestamp: number;
|
|
268
|
+
interface SpeechInfo {
|
|
269
|
+
supported?: boolean;
|
|
270
|
+
totalVoices?: number;
|
|
271
|
+
localVoices?: number;
|
|
272
|
+
[key: string]: unknown;
|
|
646
273
|
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
/** True if Sec-CH-UA header is missing */
|
|
654
|
-
missing_sec_ch_ua: boolean;
|
|
655
|
-
/** True if IP is from a known datacenter */
|
|
656
|
-
datacenter_ip: boolean;
|
|
657
|
-
/** Local threat score (0-100) */
|
|
658
|
-
local_score: number;
|
|
659
|
-
/** True if server-side verification is needed */
|
|
660
|
-
needs_verification: boolean;
|
|
661
|
-
/** Detection flags */
|
|
662
|
-
flags: string[];
|
|
274
|
+
interface WorkerConsistencyInfo {
|
|
275
|
+
supported?: boolean;
|
|
276
|
+
consistent?: boolean;
|
|
277
|
+
mismatches?: string[];
|
|
278
|
+
mismatchCount?: number;
|
|
279
|
+
[key: string]: unknown;
|
|
663
280
|
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
local_analysis: LocalAnalysis;
|
|
281
|
+
interface CSSMediaQueriesInfo {
|
|
282
|
+
supported?: boolean;
|
|
283
|
+
pointer?: string;
|
|
284
|
+
hover?: boolean;
|
|
285
|
+
[key: string]: unknown;
|
|
670
286
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
287
|
+
interface FontsInfo {
|
|
288
|
+
supported?: boolean;
|
|
289
|
+
count?: number;
|
|
290
|
+
hasSegoeUI?: boolean;
|
|
291
|
+
hasSFPro?: boolean;
|
|
292
|
+
hasDejaVuSans?: boolean;
|
|
293
|
+
[key: string]: unknown;
|
|
294
|
+
}
|
|
295
|
+
interface PermissionsInfo {
|
|
296
|
+
supported?: boolean;
|
|
297
|
+
[key: string]: unknown;
|
|
298
|
+
}
|
|
299
|
+
interface DOMRectInfo {
|
|
300
|
+
supported?: boolean;
|
|
301
|
+
rectAWidth?: number;
|
|
302
|
+
rectBWidth?: number;
|
|
303
|
+
rangeWidth?: number;
|
|
304
|
+
[key: string]: unknown;
|
|
305
|
+
}
|
|
306
|
+
/** AudioContext fingerprint. A real audio stack exposes `baseLatency` and a
|
|
307
|
+
* conventional sample rate; headless/mocked stacks omit or fake these. */
|
|
308
|
+
interface AudioContextInfo {
|
|
309
|
+
supported?: boolean;
|
|
310
|
+
sampleRate?: number;
|
|
311
|
+
state?: string;
|
|
312
|
+
baseLatency?: number | null;
|
|
313
|
+
[key: string]: unknown;
|
|
314
|
+
}
|
|
315
|
+
/** Native-function integrity check. `patched` lists native functions whose
|
|
316
|
+
* `toString()` no longer reports `[native code]` (or whose prototype was
|
|
317
|
+
* tampered with) — the signature of stealth automation hiding itself. A real
|
|
318
|
+
* browser never patches its own natives. */
|
|
319
|
+
interface LieDetectionInfo {
|
|
320
|
+
supported?: boolean;
|
|
321
|
+
patched?: string[];
|
|
322
|
+
patchedCount?: number;
|
|
323
|
+
[key: string]: unknown;
|
|
324
|
+
}
|
|
325
|
+
/** Per-field keystroke statistics for one textarea. */
|
|
326
|
+
interface TextareaKeyboardStats {
|
|
327
|
+
keyCount?: number;
|
|
328
|
+
pasteCount?: number;
|
|
329
|
+
avgKeyInterval?: number;
|
|
330
|
+
keyIntervalVariance?: number;
|
|
331
|
+
keydownUpRatio?: number;
|
|
332
|
+
noKeyboardEvents?: boolean;
|
|
333
|
+
contentLength?: number;
|
|
334
|
+
intervals?: number[];
|
|
335
|
+
dwellTimes?: number[];
|
|
336
|
+
rollovers?: number;
|
|
337
|
+
[key: string]: unknown;
|
|
338
|
+
}
|
|
339
|
+
interface FormSubmitInfo {
|
|
340
|
+
method?: string;
|
|
341
|
+
timeSincePageLoad?: number | null;
|
|
342
|
+
eventsBeforeSubmit?: number;
|
|
343
|
+
hadTriggerEvent?: boolean;
|
|
344
|
+
[key: string]: unknown;
|
|
345
|
+
}
|
|
346
|
+
interface FormAnalysisSignals {
|
|
347
|
+
pageLoadToFirstInteraction?: number | null;
|
|
348
|
+
submit?: FormSubmitInfo;
|
|
349
|
+
textareaKeyboard?: Record<string, TextareaKeyboardStats>;
|
|
350
|
+
[key: string]: unknown;
|
|
351
|
+
}
|
|
352
|
+
/** The full set of signals the client widget reports. */
|
|
353
|
+
interface Signals {
|
|
354
|
+
behavioral?: BehavioralSignals;
|
|
355
|
+
temporal?: TemporalSignals;
|
|
356
|
+
environmental?: EnvironmentalSignals;
|
|
357
|
+
formAnalysis?: FormAnalysisSignals;
|
|
358
|
+
meta?: {
|
|
359
|
+
challengeNonce?: string;
|
|
360
|
+
[key: string]: unknown;
|
|
361
|
+
};
|
|
362
|
+
[key: string]: unknown;
|
|
689
363
|
}
|
|
690
364
|
/**
|
|
691
|
-
*
|
|
365
|
+
* Outcome of proof-of-work verification, supplied by the caller (the PoW
|
|
366
|
+
* subsystem lands in Phase 2). When omitted and `requirePoW` is enabled the
|
|
367
|
+
* engine emits a hard-fail "No PoW solution provided" detection, matching the
|
|
368
|
+
* reference server.
|
|
692
369
|
*/
|
|
693
|
-
interface
|
|
694
|
-
/** Whether
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
|
|
698
|
-
/**
|
|
699
|
-
|
|
700
|
-
/**
|
|
701
|
-
|
|
702
|
-
/**
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
370
|
+
interface PoWOutcome {
|
|
371
|
+
/** Whether a PoW solution was submitted at all. */
|
|
372
|
+
provided: boolean;
|
|
373
|
+
/** Whether the submitted solution verified. */
|
|
374
|
+
valid?: boolean;
|
|
375
|
+
/** Failure reason when `valid` is false. */
|
|
376
|
+
reason?: string;
|
|
377
|
+
/** Server-measured solve time in ms (un-spoofable). */
|
|
378
|
+
serverElapsed?: number;
|
|
379
|
+
/** Nonce bound to the verified challenge. */
|
|
380
|
+
nonce?: string;
|
|
381
|
+
}
|
|
382
|
+
/** Per-request context for scoring. */
|
|
383
|
+
interface DetectionContext {
|
|
384
|
+
ip: string;
|
|
385
|
+
siteKey: string;
|
|
386
|
+
userAgent: string;
|
|
387
|
+
/** Lower-cased request headers. */
|
|
388
|
+
headers?: Record<string, string>;
|
|
389
|
+
/** Client-supplied JA3 hash (spoofable). */
|
|
390
|
+
ja3Hash?: string | null;
|
|
391
|
+
/** Trusted reverse-proxy header names carrying a JA4 fingerprint. */
|
|
392
|
+
trustedJA4Headers?: string[];
|
|
393
|
+
/** Proof-of-work verification outcome (supplied by the PoW subsystem). */
|
|
394
|
+
pow?: PoWOutcome;
|
|
708
395
|
/**
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
*
|
|
712
|
-
* Always present. Check `edge.present` before branching: false means the edge
|
|
713
|
-
* did not front this request, which is no information rather than a clean bill
|
|
714
|
-
* of health.
|
|
396
|
+
* Additional detections to fold into scoring, produced by an outer
|
|
397
|
+
* orchestrator (e.g. the signals-tampering check in the Captcha service).
|
|
715
398
|
*/
|
|
716
|
-
|
|
399
|
+
extraDetections?: Detection[];
|
|
400
|
+
}
|
|
401
|
+
/** Final verdict returned by {@link DetectionEngine.score}. */
|
|
402
|
+
interface Verdict {
|
|
403
|
+
/** True when the weighted score is below the success threshold (< 0.5). */
|
|
404
|
+
success: boolean;
|
|
405
|
+
/** Weighted final score, 0..1. */
|
|
406
|
+
score: number;
|
|
407
|
+
/** Recommended action. */
|
|
408
|
+
recommendation: Recommendation;
|
|
409
|
+
/** Per-category aggregated scores. */
|
|
410
|
+
categoryScores: CategoryScores;
|
|
411
|
+
/** Every triggered detection. */
|
|
412
|
+
detections: Detection[];
|
|
413
|
+
/** Unix seconds at evaluation time. */
|
|
414
|
+
timestamp: number;
|
|
717
415
|
}
|
|
416
|
+
|
|
718
417
|
/**
|
|
719
|
-
*
|
|
418
|
+
* In-memory stores backing the stateful detectors (fingerprint correlation and
|
|
419
|
+
* rate abuse). Ported from FCaptcha index.js.
|
|
420
|
+
*
|
|
421
|
+
* These are defined behind interfaces so Phase 2 can swap in a shared/Redis
|
|
422
|
+
* backend for serverless and multi-instance deployments.
|
|
720
423
|
*/
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
/**
|
|
725
|
-
|
|
726
|
-
/**
|
|
727
|
-
|
|
424
|
+
/** Tracks fingerprint ↔ IP relationships to spot distributed attacks. */
|
|
425
|
+
interface FingerprintStore {
|
|
426
|
+
record(fp: string, ip: string, siteKey: string): void;
|
|
427
|
+
/** Number of distinct fingerprints seen from `ip`. */
|
|
428
|
+
getIpFpCount(ip: string): number;
|
|
429
|
+
/** Number of distinct IPs that produced fingerprint `fp` for `siteKey`. */
|
|
430
|
+
getFpIpCount(fp: string, siteKey: string): number;
|
|
431
|
+
}
|
|
432
|
+
/** Sliding-window request counter. */
|
|
433
|
+
interface RateLimiter {
|
|
434
|
+
/** Returns `[exceeded, count]` for the window, recording this hit. */
|
|
435
|
+
check(key: string, windowSeconds?: number, maxRequests?: number): [boolean, number];
|
|
436
|
+
}
|
|
437
|
+
declare class InMemoryFingerprintStore implements FingerprintStore {
|
|
438
|
+
private fingerprints;
|
|
439
|
+
private ipFingerprints;
|
|
440
|
+
record(fp: string, ip: string, siteKey: string): void;
|
|
441
|
+
getIpFpCount(ip: string): number;
|
|
442
|
+
getFpIpCount(fp: string, siteKey: string): number;
|
|
443
|
+
}
|
|
444
|
+
declare class InMemoryRateLimiter implements RateLimiter {
|
|
445
|
+
private requests;
|
|
446
|
+
check(key: string, windowSeconds?: number, maxRequests?: number): [boolean, number];
|
|
728
447
|
}
|
|
729
448
|
|
|
730
449
|
/**
|
|
731
|
-
*
|
|
732
|
-
* Handles communication with the ingest service.
|
|
450
|
+
* Detection engine.
|
|
733
451
|
*
|
|
734
|
-
*
|
|
735
|
-
*
|
|
736
|
-
*
|
|
452
|
+
* Runs the full FCaptcha detector suite in-process and produces a {@link Verdict}.
|
|
453
|
+
* Mirrors the reference server's `runVerification` orchestration. The actual
|
|
454
|
+
* proof-of-work crypto and token issuance land in Phase 2 — for now the caller
|
|
455
|
+
* supplies a {@link PoWOutcome} and the engine emits the matching detections.
|
|
737
456
|
*/
|
|
738
457
|
|
|
739
|
-
interface
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
timeout: number;
|
|
743
|
-
debug: boolean;
|
|
458
|
+
interface DetectionEngineOptions {
|
|
459
|
+
/** Override the per-category weights (defaults to {@link DEFAULT_WEIGHTS}). */
|
|
460
|
+
weights?: Record<string, number>;
|
|
744
461
|
/**
|
|
745
|
-
*
|
|
746
|
-
*
|
|
747
|
-
*
|
|
462
|
+
* When true (default), a request with no PoW outcome emits a hard-fail "No PoW
|
|
463
|
+
* solution provided" detection — matching the reference server. Set false to
|
|
464
|
+
* score raw signals without requiring proof-of-work.
|
|
748
465
|
*/
|
|
749
|
-
|
|
466
|
+
requirePoW?: boolean;
|
|
467
|
+
/** Fingerprint-correlation store (defaults to an in-memory store). */
|
|
468
|
+
fingerprintStore?: FingerprintStore;
|
|
469
|
+
/** Rate limiter for rate-abuse detection (defaults to in-memory). */
|
|
470
|
+
rateLimiter?: RateLimiter;
|
|
750
471
|
}
|
|
751
|
-
declare class
|
|
752
|
-
private
|
|
753
|
-
private
|
|
754
|
-
private
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
/**
|
|
758
|
-
|
|
759
|
-
*/
|
|
760
|
-
detect(request: SDKDetectionRequest): Promise<SDKDetectionResponse>;
|
|
761
|
-
/**
|
|
762
|
-
* Send violation events to the ingest service
|
|
763
|
-
*/
|
|
764
|
-
sendViolations(events: ViolationEvent[]): Promise<void>;
|
|
765
|
-
/**
|
|
766
|
-
* Get IP enrichment data from the ingest service
|
|
767
|
-
*/
|
|
768
|
-
getIPEnrichment(ip: string): Promise<IPEnrichmentData | null>;
|
|
769
|
-
/**
|
|
770
|
-
* Validate the API key by making a test request
|
|
771
|
-
*/
|
|
772
|
-
validateAPIKey(): Promise<boolean>;
|
|
472
|
+
declare class DetectionEngine {
|
|
473
|
+
private readonly weights;
|
|
474
|
+
private readonly requirePoW;
|
|
475
|
+
private readonly fingerprintStore;
|
|
476
|
+
private readonly rateLimiter;
|
|
477
|
+
constructor(options?: DetectionEngineOptions);
|
|
478
|
+
/** Score `signals` for the given request context and return a verdict. */
|
|
479
|
+
score(signals: Signals, context: DetectionContext): Verdict;
|
|
773
480
|
}
|
|
774
481
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
482
|
+
/** Score aggregation: per-category confidence-weighted means → weighted total. */
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Aggregate detections into per-category scores. Each category's score is the
|
|
486
|
+
* confidence-weighted mean of its detections' scores, capped at 1.0. Categories
|
|
487
|
+
* present in `weights` but with no detections are filled with 0.
|
|
488
|
+
*/
|
|
489
|
+
declare function calculateCategoryScores(detections: Detection[], weights: Record<string, number>): CategoryScores;
|
|
490
|
+
/** Combine category scores into the final weighted score (capped at 1.0). */
|
|
491
|
+
declare function calculateFinalScore(categoryScores: CategoryScores, weights: Record<string, number>): number;
|
|
492
|
+
/** Map a final score to an action recommendation. */
|
|
493
|
+
declare function recommend(finalScore: number): Recommendation;
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Category weights and automation UA patterns.
|
|
497
|
+
*
|
|
498
|
+
* Values match the FCaptcha standalone server (server.js), which is the most
|
|
499
|
+
* complete variant of the engine and the one the reference test suite exercises.
|
|
500
|
+
*/
|
|
501
|
+
/**
|
|
502
|
+
* Default per-category weights used to compute the final score.
|
|
503
|
+
*
|
|
504
|
+
* `stealth` carries deliberate anti-detection tampering (native functions
|
|
505
|
+
* patched to hide automation). This is the least-ambiguous evidence of a bot —
|
|
506
|
+
* a genuine browser never patches its own natives — so it is weighted highest.
|
|
507
|
+
* Because weights are a simple weighted sum (not required to total 1.0), and
|
|
508
|
+
* `stealth` is 0 for any clean browser, this raises stealth-bot scores without
|
|
509
|
+
* affecting legitimate traffic.
|
|
510
|
+
*/
|
|
511
|
+
declare const DEFAULT_WEIGHTS: Record<string, number>;
|
|
512
|
+
|
|
513
|
+
/** True when `ip` falls inside a known datacenter CIDR block (IPv4 only). */
|
|
514
|
+
declare function isDatacenterIP(ip: string): boolean;
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* User-Agent parsing and bot-pattern matching. Ported from FCaptcha detection.js.
|
|
518
|
+
*/
|
|
519
|
+
interface UserAgentInfo {
|
|
520
|
+
browser: string | null;
|
|
521
|
+
os: string | null;
|
|
522
|
+
isMobile: boolean;
|
|
523
|
+
isBot: boolean;
|
|
524
|
+
botName: string | null;
|
|
525
|
+
}
|
|
526
|
+
/** True when the UA looks like a mobile device. */
|
|
527
|
+
declare function isMobileUA(userAgent: string): boolean;
|
|
528
|
+
/** Extract browser/OS/bot info from a User-Agent string. */
|
|
529
|
+
declare function parseUserAgent(ua: string): UserAgentInfo;
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* What the browser told us, made available to the request that follows.
|
|
533
|
+
*
|
|
534
|
+
* WHY THIS EXISTS
|
|
535
|
+
*
|
|
536
|
+
* `@webdecoy/client` collects behavioural, environmental and form signals and
|
|
537
|
+
* can run proof-of-work; `DetectionEngine` scores them; `/score` already
|
|
538
|
+
* accepted a submission and returned a verdict. The parts were all there and
|
|
539
|
+
* they were not connected: the verdict went back to the browser, and the next
|
|
540
|
+
* request to the origin knew nothing about it. Joining the two was left as an
|
|
541
|
+
* exercise for the developer, so in practice nobody did.
|
|
542
|
+
*
|
|
543
|
+
* That matters because this is the SDK's answer to the one thing a tripwire
|
|
544
|
+
* cannot catch — a real browser, driven by Playwright, that follows no hidden
|
|
545
|
+
* links and requests no honeypot paths. It has a genuine fingerprint and it
|
|
546
|
+
* still cannot fake human interaction. Competitors launched exactly this shape
|
|
547
|
+
* as a headline feature; we have had the parts for longer and no way to use
|
|
548
|
+
* them.
|
|
549
|
+
*
|
|
550
|
+
* WHAT IT IS NOT
|
|
551
|
+
*
|
|
552
|
+
* A client signal is a claim by code running on the client, so it is evidence
|
|
553
|
+
* about a cooperative browser and nothing else. No JavaScript means no signals,
|
|
554
|
+
* which is why {@link ClientSignalRule} treats "absent" as `NOT_RUN` rather than
|
|
555
|
+
* as suspicion: a curl request and a search crawler both send nothing, and
|
|
556
|
+
* scoring silence would deny the crawlers we most need to keep.
|
|
557
|
+
*
|
|
558
|
+
* This augments the keyless deterministic rules. It does not replace them.
|
|
559
|
+
*/
|
|
560
|
+
|
|
561
|
+
/** The engine's verdict on one browser session. */
|
|
562
|
+
interface ClientVerdict {
|
|
563
|
+
/** Session id supplied by the browser widget. */
|
|
564
|
+
sessionId: string;
|
|
565
|
+
/** 0–1, higher is more bot-like. */
|
|
566
|
+
score: number;
|
|
567
|
+
/** What the engine recommends doing about it. */
|
|
568
|
+
recommendation: Recommendation;
|
|
569
|
+
/** When the verdict was recorded, Unix ms. */
|
|
570
|
+
at: number;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Where verdicts live between the `/score` submission and the requests that
|
|
574
|
+
* follow it.
|
|
575
|
+
*
|
|
576
|
+
* Same sync/async split as the rate-limit store, and for the same reason: an
|
|
577
|
+
* in-memory default must not make every rule evaluation a promise.
|
|
578
|
+
*/
|
|
579
|
+
interface ClientSignalStore {
|
|
580
|
+
readonly sync: boolean;
|
|
581
|
+
get(sessionId: string): ClientVerdict | undefined | Promise<ClientVerdict | undefined>;
|
|
582
|
+
set(verdict: ClientVerdict): void | Promise<void>;
|
|
583
|
+
}
|
|
584
|
+
interface MemoryClientSignalStoreOptions {
|
|
585
|
+
/** How long a verdict stays usable. @default 900_000 (15 minutes) */
|
|
586
|
+
ttl?: number;
|
|
587
|
+
/** Maximum sessions held. @default 10_000 */
|
|
588
|
+
max?: number;
|
|
589
|
+
}
|
|
590
|
+
declare class MemoryClientSignalStore implements ClientSignalStore {
|
|
591
|
+
readonly sync: true;
|
|
592
|
+
private readonly ttl;
|
|
593
|
+
private readonly max;
|
|
594
|
+
private entries;
|
|
595
|
+
constructor(options?: MemoryClientSignalStoreOptions);
|
|
596
|
+
get(sessionId: string): ClientVerdict | undefined;
|
|
597
|
+
set(verdict: ClientVerdict): void;
|
|
598
|
+
get size(): number;
|
|
599
|
+
}
|
|
600
|
+
/** The cookie the widget sets, and the header it will also accept. */
|
|
601
|
+
declare const CLIENT_SESSION_COOKIE = "wd_cs";
|
|
602
|
+
declare const CLIENT_SESSION_HEADER = "x-wd-session";
|
|
603
|
+
/** Read the browser session id off a request, cookie first then header. */
|
|
604
|
+
declare function readClientSession(headers: Record<string, string>): string | undefined;
|
|
605
|
+
interface ClientSignalConfig {
|
|
606
|
+
/** Where verdicts are read from. Must be the store `/score` writes to. */
|
|
607
|
+
store: ClientSignalStore;
|
|
849
608
|
/**
|
|
850
|
-
*
|
|
851
|
-
*
|
|
852
|
-
* @param metadata - Request metadata to analyze
|
|
853
|
-
* @param options - Optional configuration for this specific request
|
|
854
|
-
* @returns Protection result with decision and detection details
|
|
609
|
+
* Deny at or above this score, 0–1. The engine's own `recommendation` is used
|
|
610
|
+
* when this is omitted.
|
|
855
611
|
*/
|
|
856
|
-
|
|
857
|
-
|
|
612
|
+
minScore?: number;
|
|
613
|
+
/** Action on a match. @default 'DENY' */
|
|
614
|
+
action?: 'DENY' | 'THROTTLE';
|
|
615
|
+
/** Log the violation but do not block. */
|
|
616
|
+
dryRun?: boolean;
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Act on what the browser widget reported for this session.
|
|
620
|
+
*
|
|
621
|
+
* A request with no session — no JavaScript, no widget, a crawler, curl — is
|
|
622
|
+
* `NOT_RUN`, never a denial. See the module note.
|
|
623
|
+
*/
|
|
624
|
+
declare class ClientSignalRule implements Rule {
|
|
625
|
+
readonly name = "client-signals";
|
|
626
|
+
private readonly store;
|
|
627
|
+
private readonly minScore?;
|
|
628
|
+
private readonly action;
|
|
629
|
+
private readonly dryRun;
|
|
630
|
+
constructor(config: ClientSignalConfig);
|
|
631
|
+
prepare(context: RuleContext): Promise<void>;
|
|
632
|
+
evaluate(context: RuleContext): RuleResult;
|
|
633
|
+
}
|
|
634
|
+
/** Act on the browser widget's verdict for this session. See {@link ClientSignalConfig}. */
|
|
635
|
+
declare function clientSignals(config: ClientSignalConfig): Rule;
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* One adapter, for every runtime that speaks `Request` and `Response`.
|
|
639
|
+
*
|
|
640
|
+
* WHY THIS EXISTS
|
|
641
|
+
*
|
|
642
|
+
* Express, Fastify and Next.js each grew their own copy of the same middleware:
|
|
643
|
+
* skip-path matching, monitor-versus-enforce, honeytoken arming, the 429 with a
|
|
644
|
+
* `Retry-After`, fail-open error handling. Three copies of a decision tree is
|
|
645
|
+
* three places for the branch that matters to be subtly different — and it
|
|
646
|
+
* already had been, which is how the leftmost-`X-Forwarded-For` bug survived in
|
|
647
|
+
* two adapters after the WordPress plugin fixed it.
|
|
648
|
+
*
|
|
649
|
+
* It is also the answer to "which framework do you support?". Hono, Bun, Deno,
|
|
650
|
+
* Astro, Nitro, SvelteKit and Remix all hand you a WHATWG `Request` and want a
|
|
651
|
+
* `Response` back. Written once here, each of those is a translation layer thin
|
|
652
|
+
* enough not to need a package — see the README recipe — and `@webdecoy/hono` is
|
|
653
|
+
* the one that does, because Hono has a middleware contract worth fitting.
|
|
654
|
+
*
|
|
655
|
+
* No `node:` imports: this is the code path that has to run on Workers.
|
|
656
|
+
*/
|
|
657
|
+
|
|
658
|
+
interface FetchGuardOptions extends WebDecoyConfig, ProtectOptions {
|
|
858
659
|
/**
|
|
859
|
-
*
|
|
660
|
+
* Whether a blocking verdict actually blocks. Defaults to `'monitor'`.
|
|
860
661
|
*
|
|
861
|
-
*
|
|
862
|
-
*
|
|
863
|
-
* their middleware acted, Arcjet-quickstart style. (The default monitor
|
|
864
|
-
* mode still serves the request; the dashboard row is the real receipt.)
|
|
865
|
-
*
|
|
866
|
-
* Without an API key nothing can reach the dashboard, so the verdict says
|
|
867
|
-
* so via `error` instead of pretending the test ran.
|
|
868
|
-
*/
|
|
869
|
-
private reportTestTrigger;
|
|
870
|
-
/**
|
|
871
|
-
* Validate the API key configuration
|
|
872
|
-
* Useful for testing integration during setup
|
|
662
|
+
* Nobody adopts a defence by having it break their site on the first install.
|
|
663
|
+
* Watch what it would have done, then switch.
|
|
873
664
|
*/
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
}>;
|
|
665
|
+
mode?: 'monitor' | 'enforce';
|
|
666
|
+
/** Paths to skip entirely — health checks, static assets. */
|
|
667
|
+
skipPaths?: (string | RegExp)[];
|
|
878
668
|
/**
|
|
879
|
-
*
|
|
880
|
-
*
|
|
669
|
+
* How much of the `X-Forwarded-For` chain to believe. Defaults to `1` trusted
|
|
670
|
+
* hop: a fetch handler has no socket to fall back on, so there is no
|
|
671
|
+
* believe-nothing default available. See `resolveClientIp`.
|
|
881
672
|
*/
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
destroy(): Promise<void>;
|
|
886
|
-
}): void;
|
|
673
|
+
trustProxy?: TrustedProxies;
|
|
674
|
+
/** Override IP resolution entirely. */
|
|
675
|
+
getIP?: (request: Request) => string;
|
|
887
676
|
/**
|
|
888
|
-
*
|
|
677
|
+
* Inject a hidden honeytoken link into HTML responses, and arm the tripwire it
|
|
678
|
+
* points at. Defaults to on when an `apiKey` is present.
|
|
889
679
|
*/
|
|
890
|
-
|
|
680
|
+
honeytoken?: boolean;
|
|
681
|
+
/** Build the blocking response. Defaults to 403, or 429 for a throttle. */
|
|
682
|
+
onBlocked?: (request: Request, decision: Decision) => Response | Promise<Response>;
|
|
683
|
+
}
|
|
684
|
+
interface GuardOutcome {
|
|
685
|
+
/** What the SDK concluded. Always present, in both modes. */
|
|
686
|
+
decision: Decision;
|
|
891
687
|
/**
|
|
892
|
-
*
|
|
688
|
+
* The response to return instead of calling the handler, or undefined to
|
|
689
|
+
* carry on. Undefined in monitor mode even when the decision is a denial.
|
|
893
690
|
*/
|
|
894
|
-
|
|
691
|
+
response?: Response;
|
|
692
|
+
}
|
|
693
|
+
interface FetchGuard {
|
|
694
|
+
/** Evaluate one request. */
|
|
695
|
+
check(request: Request, peer?: string): Promise<GuardOutcome>;
|
|
895
696
|
/**
|
|
896
|
-
*
|
|
697
|
+
* Rewrite an HTML response to carry the honeytoken link. Returns the response
|
|
698
|
+
* unchanged when there is no token yet, or the body is not injectable HTML.
|
|
897
699
|
*/
|
|
898
|
-
|
|
700
|
+
decorate(response: Response): Promise<Response>;
|
|
701
|
+
/** Whether this path is skipped. */
|
|
702
|
+
skips(pathname: string): boolean;
|
|
703
|
+
/** The underlying SDK, for `detectBot()` and friends. */
|
|
704
|
+
sdk: WebDecoy;
|
|
899
705
|
}
|
|
900
|
-
|
|
901
706
|
/**
|
|
902
|
-
*
|
|
903
|
-
*
|
|
904
|
-
* A request whose User-Agent starts with `WebDecoy-Test/` is the documented
|
|
905
|
-
* install-verification probe:
|
|
906
|
-
*
|
|
907
|
-
* curl -A "WebDecoy-Test/1.0" http://localhost:3000/
|
|
707
|
+
* A guard over WHATWG `Request`/`Response`.
|
|
908
708
|
*
|
|
909
|
-
*
|
|
910
|
-
*
|
|
911
|
-
*
|
|
912
|
-
*
|
|
913
|
-
*
|
|
914
|
-
*
|
|
915
|
-
*
|
|
916
|
-
*
|
|
917
|
-
*
|
|
709
|
+
* ```ts
|
|
710
|
+
* const guard = createFetchGuard({ rules: [tripwire()] });
|
|
711
|
+
*
|
|
712
|
+
* export default {
|
|
713
|
+
* async fetch(request) {
|
|
714
|
+
* const { response } = await guard.check(request);
|
|
715
|
+
* if (response) return response;
|
|
716
|
+
* return guard.decorate(await handle(request));
|
|
717
|
+
* },
|
|
718
|
+
* };
|
|
719
|
+
* ```
|
|
918
720
|
*/
|
|
919
|
-
|
|
920
|
-
declare const TEST_TRIGGER_UA_PREFIX = "WebDecoy-Test/";
|
|
921
|
-
/** The exact value the quickstart docs tell developers to send. */
|
|
922
|
-
declare const TEST_TRIGGER_USER_AGENT = "WebDecoy-Test/1.0";
|
|
923
|
-
/** Whether this User-Agent is the reserved test trigger. */
|
|
924
|
-
declare function isTestTriggerUserAgent(userAgent: string | undefined): boolean;
|
|
721
|
+
declare function createFetchGuard(options?: FetchGuardOptions): FetchGuard;
|
|
925
722
|
|
|
926
723
|
/**
|
|
927
724
|
* Rule Engine
|
|
@@ -957,9 +754,20 @@ declare class RuleEngine {
|
|
|
957
754
|
|
|
958
755
|
declare class RateLimitRule implements Rule {
|
|
959
756
|
readonly name: string;
|
|
960
|
-
private
|
|
757
|
+
private store;
|
|
961
758
|
private config;
|
|
962
759
|
constructor(config: RateLimitConfig);
|
|
760
|
+
/**
|
|
761
|
+
* Which bucket this request counts against.
|
|
762
|
+
*
|
|
763
|
+
* Precedence: this rule's own keyBy, then the SDK-wide characteristics, then
|
|
764
|
+
* the IP. `context.key` is always populated, so the last fallback only matters
|
|
765
|
+
* for a context built by hand.
|
|
766
|
+
*/
|
|
767
|
+
private keyFor;
|
|
768
|
+
private consumption;
|
|
769
|
+
/** Consume from a networked store before evaluation. No-op for a sync store. */
|
|
770
|
+
prepare(context: RuleContext): Promise<void>;
|
|
963
771
|
evaluate(context: RuleContext): RuleResult;
|
|
964
772
|
destroy(): void;
|
|
965
773
|
}
|
|
@@ -1046,6 +854,174 @@ declare class BotRule implements Rule {
|
|
|
1046
854
|
evaluate(context: RuleContext): RuleResult;
|
|
1047
855
|
}
|
|
1048
856
|
|
|
857
|
+
/**
|
|
858
|
+
* One bot policy, published and enforced.
|
|
859
|
+
*
|
|
860
|
+
* WHY THIS EXISTS
|
|
861
|
+
*
|
|
862
|
+
* `BOT_REGISTRY` is generated from the Go registry and already carries the
|
|
863
|
+
* customer-facing categories. `bots()` enforces against that table. Nothing
|
|
864
|
+
* published from it — so every site that wanted to control AI crawlers
|
|
865
|
+
* hand-wrote a `robots.txt` that drifted from whatever the code actually did.
|
|
866
|
+
*
|
|
867
|
+
* Drift here is not cosmetic. A `robots.txt` that disallows GPTBot while the
|
|
868
|
+
* middleware lets it through is a policy the operator believes is in force and
|
|
869
|
+
* is not. The reverse — enforcing against a crawler the published file invites —
|
|
870
|
+
* is how a site quietly disappears from a search index.
|
|
871
|
+
*
|
|
872
|
+
* So the two come from one object:
|
|
873
|
+
*
|
|
874
|
+
* ```ts
|
|
875
|
+
* const policy = botPolicy({ deny: ['training_crawler'], allow: ['perplexitybot'] });
|
|
876
|
+
*
|
|
877
|
+
* app.get('/robots.txt', (_req, res) => res.type('text/plain').send(policy.robotsTxt()));
|
|
878
|
+
* const wd = new WebDecoy({ rules: [policy.rule()] });
|
|
879
|
+
* ```
|
|
880
|
+
*
|
|
881
|
+
* WHAT ROBOTS.TXT IS AND IS NOT
|
|
882
|
+
*
|
|
883
|
+
* It is a request, honoured at the crawler's discretion. The registry records
|
|
884
|
+
* whether each operator *documents* honouring it, which is a claim rather than
|
|
885
|
+
* an observation, and {@link BotPolicy.unenforceable} lists the agents in your
|
|
886
|
+
* deny set that do not even claim it. Those are the ones the rule is actually
|
|
887
|
+
* doing the work for, and `robotsTxt()` names them in a comment so the file
|
|
888
|
+
* itself says which half of the policy is voluntary.
|
|
889
|
+
*/
|
|
890
|
+
|
|
891
|
+
interface BotPolicyOptions {
|
|
892
|
+
/**
|
|
893
|
+
* What the policy is against: category names (`'training_crawler'`), agent
|
|
894
|
+
* slugs or display names (`'gptbot'`, `'GPTBot'`), or the literal `'ai'` for
|
|
895
|
+
* every AI client.
|
|
896
|
+
*/
|
|
897
|
+
deny?: (BotCategory | 'ai' | string)[];
|
|
898
|
+
/** Never act on these, whatever else matches. Applied last. */
|
|
899
|
+
allow?: string[];
|
|
900
|
+
/** Action the rule takes on a match. @default 'DENY' */
|
|
901
|
+
action?: 'DENY' | 'THROTTLE';
|
|
902
|
+
/** Rule logs but does not block. Does not change what `robotsTxt()` emits. */
|
|
903
|
+
dryRun?: boolean;
|
|
904
|
+
}
|
|
905
|
+
interface RobotsTxtOptions {
|
|
906
|
+
/** Absolute sitemap URL, emitted as a `Sitemap:` line. */
|
|
907
|
+
sitemap?: string;
|
|
908
|
+
/** `Crawl-delay` in seconds, applied to the wildcard group. */
|
|
909
|
+
crawlDelay?: number;
|
|
910
|
+
/**
|
|
911
|
+
* Emit a trailing `User-agent: *` group allowing everything else.
|
|
912
|
+
* @default true
|
|
913
|
+
*/
|
|
914
|
+
allowOthers?: boolean;
|
|
915
|
+
/** Paths to disallow for every agent, e.g. `['/admin']`. */
|
|
916
|
+
disallow?: string[];
|
|
917
|
+
/**
|
|
918
|
+
* Include the header comment naming agents that do not document honouring
|
|
919
|
+
* robots.txt. @default true
|
|
920
|
+
*/
|
|
921
|
+
annotate?: boolean;
|
|
922
|
+
}
|
|
923
|
+
declare class BotPolicy {
|
|
924
|
+
private readonly config;
|
|
925
|
+
/** The agents this policy is against, resolved from the registry. */
|
|
926
|
+
readonly matched: readonly BotAgent[];
|
|
927
|
+
constructor(options?: BotPolicyOptions);
|
|
928
|
+
/**
|
|
929
|
+
* Agents in the deny set whose operator does not document honouring
|
|
930
|
+
* robots.txt. Publishing still declares the policy; only the rule enforces it
|
|
931
|
+
* against these.
|
|
932
|
+
*/
|
|
933
|
+
get unenforceable(): readonly BotAgent[];
|
|
934
|
+
/** The enforcing rule. Denies exactly the agents in {@link matched}. */
|
|
935
|
+
rule(): Rule;
|
|
936
|
+
/** The published policy, as a `robots.txt` body. */
|
|
937
|
+
robotsTxt(options?: RobotsTxtOptions): string;
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* A bot policy you can both publish and enforce. See {@link BotPolicy}.
|
|
941
|
+
*/
|
|
942
|
+
declare function botPolicy(options?: BotPolicyOptions): BotPolicy;
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* Attack payloads in the request.
|
|
946
|
+
*
|
|
947
|
+
* WHAT THIS IS, AND WHAT IT REFUSES TO BE
|
|
948
|
+
*
|
|
949
|
+
* Tripwires catch scanners by the **path** they ask for. Nothing here looked at
|
|
950
|
+
* what those same scanners *send* — the injection strings in a query, the
|
|
951
|
+
* traversal in a parameter, the `${jndi:` in a header. Their absence read as
|
|
952
|
+
* "this only does honeypots".
|
|
953
|
+
*
|
|
954
|
+
* This is not a WAF and should not grow into one. A WAF's value is breadth, and
|
|
955
|
+
* breadth is bought with false positives on ordinary traffic — which is the
|
|
956
|
+
* complaint every incumbent's customers have. What this is: a small, curated set
|
|
957
|
+
* of signatures that are unambiguous, cheap, and useful precisely because they
|
|
958
|
+
* compose with the deterministic signals. A request that carries an injection
|
|
959
|
+
* payload *and* walks into a tripwire is a far stronger detection than either
|
|
960
|
+
* alone, and both are facts rather than probabilities.
|
|
961
|
+
*
|
|
962
|
+
* FALSE POSITIVES ARE THE DESIGN CONSTRAINT
|
|
963
|
+
*
|
|
964
|
+
* By default only the path and query string are inspected. Bodies and headers
|
|
965
|
+
* are opt-in, because a CMS saving an article, a template in a JSON payload and
|
|
966
|
+
* a URL passed as a query parameter all legitimately contain things that look
|
|
967
|
+
* like attacks. Inspecting them is the right call for an API that never carries
|
|
968
|
+
* markup, and the wrong one for a publishing tool — so it is the operator's
|
|
969
|
+
* call, and `dryRun` is the way to find out.
|
|
970
|
+
*
|
|
971
|
+
* PERFORMANCE IS ALSO A CONSTRAINT
|
|
972
|
+
*
|
|
973
|
+
* Every pattern is anchored or literal, with no nested quantifiers — a regex
|
|
974
|
+
* that backtracks catastrophically on a crafted input turns a detection rule
|
|
975
|
+
* into the denial of service it was meant to catch. Input is truncated before
|
|
976
|
+
* matching, and decoded a bounded number of times.
|
|
977
|
+
*/
|
|
978
|
+
|
|
979
|
+
interface AttackSignatureConfig {
|
|
980
|
+
/**
|
|
981
|
+
* Which parts of the request to inspect.
|
|
982
|
+
*
|
|
983
|
+
* Defaults to `['path', 'query']`, which is where a signature has no innocent
|
|
984
|
+
* reading. `'body'` and `'headers'` are opt-in: a CMS saving an article, a
|
|
985
|
+
* template inside a JSON payload and a URL passed as a parameter all
|
|
986
|
+
* legitimately contain things that look like attacks. Start those in `dryRun`.
|
|
987
|
+
*
|
|
988
|
+
* @default ['path', 'query']
|
|
989
|
+
*/
|
|
990
|
+
inspect?: ('path' | 'query' | 'body' | 'headers')[];
|
|
991
|
+
/**
|
|
992
|
+
* Bytes of each inspected part to scan. Beyond this the input is truncated,
|
|
993
|
+
* so a large body cannot turn matching into the denial of service the rule
|
|
994
|
+
* exists to catch.
|
|
995
|
+
* @default 8192
|
|
996
|
+
*/
|
|
997
|
+
maxBytes?: number;
|
|
998
|
+
/** Signature ids to skip, e.g. `['traversal']`. */
|
|
999
|
+
exclude?: string[];
|
|
1000
|
+
/** Action on a match. @default 'DENY' */
|
|
1001
|
+
action?: 'DENY' | 'THROTTLE';
|
|
1002
|
+
/** Log the violation but do not block. */
|
|
1003
|
+
dryRun?: boolean;
|
|
1004
|
+
}
|
|
1005
|
+
declare class AttackSignatureRule implements Rule {
|
|
1006
|
+
readonly name = "attack-signatures";
|
|
1007
|
+
private readonly inspect;
|
|
1008
|
+
private readonly maxBytes;
|
|
1009
|
+
private readonly signatures;
|
|
1010
|
+
private readonly action;
|
|
1011
|
+
private readonly dryRun;
|
|
1012
|
+
constructor(config?: AttackSignatureConfig);
|
|
1013
|
+
evaluate(context: RuleContext): RuleResult;
|
|
1014
|
+
private parts;
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Deny requests carrying unambiguous attack payloads. See
|
|
1018
|
+
* {@link AttackSignatureConfig} — and note that this is a small curated set, not
|
|
1019
|
+
* a WAF.
|
|
1020
|
+
*/
|
|
1021
|
+
declare function attackSignatures(config?: AttackSignatureConfig): Rule;
|
|
1022
|
+
/** The signature ids, for `exclude` and for tests. */
|
|
1023
|
+
declare const ATTACK_SIGNATURE_IDS: readonly string[];
|
|
1024
|
+
|
|
1049
1025
|
/**
|
|
1050
1026
|
* Web Bot Auth rule (the main application repo).
|
|
1051
1027
|
*
|
|
@@ -1144,6 +1120,86 @@ interface Honeytoken {
|
|
|
1144
1120
|
*/
|
|
1145
1121
|
declare function honeytoken(options?: HoneytokenOptions): Honeytoken;
|
|
1146
1122
|
|
|
1123
|
+
/**
|
|
1124
|
+
* Rate-limit counters in Upstash Redis.
|
|
1125
|
+
*
|
|
1126
|
+
* WHY UPSTASH, AND WHY NO DEPENDENCY
|
|
1127
|
+
*
|
|
1128
|
+
* Upstash speaks Redis over HTTP, which is the only shape that works everywhere
|
|
1129
|
+
* this SDK runs: Vercel Edge, Cloudflare Workers and Deno have no `node:net`, so
|
|
1130
|
+
* an ordinary Redis client cannot open a socket there. The core package already
|
|
1131
|
+
* passes an edge-compatibility gate, and a store that only worked on Node would
|
|
1132
|
+
* be unavailable in exactly the serverless deployments that need shared counters
|
|
1133
|
+
* most.
|
|
1134
|
+
*
|
|
1135
|
+
* It talks to the REST API with `fetch` rather than pulling in `@upstash/redis`.
|
|
1136
|
+
* Two commands in a pipeline is not worth a dependency, a version to track, or a
|
|
1137
|
+
* transitive `node:` import finding its way into an edge bundle.
|
|
1138
|
+
*
|
|
1139
|
+
* ```ts
|
|
1140
|
+
* rateLimit({
|
|
1141
|
+
* max: 100,
|
|
1142
|
+
* window: 60,
|
|
1143
|
+
* store: upstashRateLimitStore({
|
|
1144
|
+
* url: process.env.UPSTASH_REDIS_REST_URL!,
|
|
1145
|
+
* token: process.env.UPSTASH_REDIS_REST_TOKEN!,
|
|
1146
|
+
* }),
|
|
1147
|
+
* })
|
|
1148
|
+
* ```
|
|
1149
|
+
*/
|
|
1150
|
+
|
|
1151
|
+
interface UpstashStoreOptions {
|
|
1152
|
+
/** REST endpoint, e.g. `https://eu1-xxx.upstash.io`. */
|
|
1153
|
+
url: string;
|
|
1154
|
+
/** REST token. */
|
|
1155
|
+
token: string;
|
|
1156
|
+
/** Prefix for every key written. @default 'wd:rl:' */
|
|
1157
|
+
prefix?: string;
|
|
1158
|
+
/** Request timeout in milliseconds. @default 1000 */
|
|
1159
|
+
timeout?: number;
|
|
1160
|
+
/**
|
|
1161
|
+
* What to do when Redis is unreachable.
|
|
1162
|
+
*
|
|
1163
|
+
* `'open'` (default) allows the request: a rate limiter that takes the site
|
|
1164
|
+
* down when its datastore has a bad minute has done more damage than the
|
|
1165
|
+
* traffic it was shaping. `'closed'` denies, for a limit that is protecting
|
|
1166
|
+
* something more expensive than availability.
|
|
1167
|
+
*
|
|
1168
|
+
* Either way the outcome is reported, so the decision says which happened
|
|
1169
|
+
* rather than looking like a normal evaluation.
|
|
1170
|
+
*/
|
|
1171
|
+
onError?: 'open' | 'closed';
|
|
1172
|
+
}
|
|
1173
|
+
declare class UpstashRateLimitStore implements RateLimitStore {
|
|
1174
|
+
readonly sync: false;
|
|
1175
|
+
private readonly url;
|
|
1176
|
+
private readonly token;
|
|
1177
|
+
private readonly prefix;
|
|
1178
|
+
private readonly timeout;
|
|
1179
|
+
private readonly failOpen;
|
|
1180
|
+
constructor(options: UpstashStoreOptions);
|
|
1181
|
+
consume(input: RateLimitConsume): Promise<RateLimitOutcome>;
|
|
1182
|
+
/**
|
|
1183
|
+
* Fixed window: one counter per key per window.
|
|
1184
|
+
*
|
|
1185
|
+
* The window id is in the key rather than tracked separately, so expiry is the
|
|
1186
|
+
* only cleanup needed and two processes incrementing concurrently cannot
|
|
1187
|
+
* disagree about which window they are in.
|
|
1188
|
+
*/
|
|
1189
|
+
private fixed;
|
|
1190
|
+
/**
|
|
1191
|
+
* Sliding window: a sorted set of request timestamps, trimmed on every read.
|
|
1192
|
+
*
|
|
1193
|
+
* The member is timestamp plus random bytes because two requests in the same
|
|
1194
|
+
* millisecond would otherwise be one ZADD that overwrites rather than two that
|
|
1195
|
+
* count — undercounting exactly when the limit matters.
|
|
1196
|
+
*/
|
|
1197
|
+
private sliding;
|
|
1198
|
+
private pipeline;
|
|
1199
|
+
}
|
|
1200
|
+
/** Rate-limit counters shared through Upstash Redis. See {@link UpstashStoreOptions}. */
|
|
1201
|
+
declare function upstashRateLimitStore(options: UpstashStoreOptions): RateLimitStore;
|
|
1202
|
+
|
|
1147
1203
|
/**
|
|
1148
1204
|
* Site honeytoken — a stable, derivable trap the adapters can inject for you
|
|
1149
1205
|
*.
|
|
@@ -1267,604 +1323,189 @@ declare function isInjectableHtml(contentType: string | undefined | null): boole
|
|
|
1267
1323
|
*
|
|
1268
1324
|
* const sdk = new WebDecoy({
|
|
1269
1325
|
* rules: [
|
|
1270
|
-
* rateLimit({ max: 100, window: 60 }),
|
|
1271
|
-
* ],
|
|
1272
|
-
* });
|
|
1273
|
-
* ```
|
|
1274
|
-
*/
|
|
1275
|
-
declare function rateLimit(config: RateLimitConfig): Rule;
|
|
1276
|
-
/**
|
|
1277
|
-
* Factory function to create a filter rule
|
|
1278
|
-
*
|
|
1279
|
-
* @example
|
|
1280
|
-
* ```typescript
|
|
1281
|
-
* import { filter } from '@webdecoy/node';
|
|
1282
|
-
*
|
|
1283
|
-
* const sdk = new WebDecoy({
|
|
1284
|
-
* apiKey: process.env.WEBDECOY_API_KEY,
|
|
1285
|
-
* rules: [
|
|
1286
|
-
* filter({ expression: 'ip.vpn or ip.tor', action: 'DENY' }),
|
|
1287
|
-
* filter({ expression: 'ip.country in ["CN", "RU"]', action: 'DENY' }),
|
|
1288
|
-
* ],
|
|
1289
|
-
* });
|
|
1290
|
-
* ```
|
|
1291
|
-
*/
|
|
1292
|
-
declare function filter(config: FilterConfig): Rule;
|
|
1293
|
-
/**
|
|
1294
|
-
* Factory function to create a tripwire (honeypot-path) rule.
|
|
1295
|
-
*
|
|
1296
|
-
* Deterministic, zero-false-positive: any request for a hidden honeypot path is
|
|
1297
|
-
* automated by construction. Detects intent (going where a human can't), which
|
|
1298
|
-
* stealth fingerprint-spoofing (e.g. botasaurus) cannot evade.
|
|
1299
|
-
*
|
|
1300
|
-
* @example
|
|
1301
|
-
* ```typescript
|
|
1302
|
-
* import { WebDecoy, tripwire, honeytoken } from '@webdecoy/node';
|
|
1303
|
-
*
|
|
1304
|
-
* const hp = honeytoken();
|
|
1305
|
-
* const sdk = new WebDecoy({
|
|
1306
|
-
* rules: [
|
|
1307
|
-
* tripwire({ paths: [hp.path] }), // + built-in scanner-bait paths
|
|
1308
|
-
* ],
|
|
1309
|
-
* });
|
|
1310
|
-
* // inject hp.linkHtml into your pages
|
|
1311
|
-
* ```
|
|
1312
|
-
*/
|
|
1313
|
-
declare function tripwire(config?: TripwireConfig): Rule;
|
|
1314
|
-
/**
|
|
1315
|
-
* Factory function to create a bot-category rule.
|
|
1316
|
-
*
|
|
1317
|
-
* Acts on agents that identify themselves in the User-Agent, matched against the
|
|
1318
|
-
* registry generated from the same table the scoring pipeline uses — so
|
|
1319
|
-
* `'training_crawler'` here means what `ai_scraper_category` means in your
|
|
1320
|
-
* dashboard.
|
|
1321
|
-
*
|
|
1322
|
-
* @example
|
|
1323
|
-
* ```typescript
|
|
1324
|
-
* import { WebDecoy, bots } from '@webdecoy/node';
|
|
1325
|
-
*
|
|
1326
|
-
* const sdk = new WebDecoy({
|
|
1327
|
-
* rules: [
|
|
1328
|
-
* // Keep AI models out of your content, keep your search ranking.
|
|
1329
|
-
* bots({ categories: ['training_crawler'] }),
|
|
1330
|
-
*
|
|
1331
|
-
* // Or everything AI, minus the one you want referral traffic from.
|
|
1332
|
-
* bots({ ai: true, allow: ['perplexitybot'] }),
|
|
1333
|
-
*
|
|
1334
|
-
* // Or a specific operator.
|
|
1335
|
-
* bots({ agents: ['gptbot', 'ClaudeBot'], action: 'THROTTLE' }),
|
|
1336
|
-
* ],
|
|
1337
|
-
* });
|
|
1338
|
-
* ```
|
|
1339
|
-
*
|
|
1340
|
-
* Only catches agents that declare themselves — anything spoofing a browser
|
|
1341
|
-
* passes through, by design. Pair with {@link tripwire} for agents that lie.
|
|
1342
|
-
*/
|
|
1343
|
-
declare function bots(config?: BotRuleConfig): Rule;
|
|
1344
|
-
|
|
1345
|
-
/**
|
|
1346
|
-
* AgentVerifier — the public entry point for local Web Bot Auth verification.
|
|
1347
|
-
*
|
|
1348
|
-
* Wraps the cached directory client and the signature core into a single
|
|
1349
|
-
* `verify(request)` call returning an {@link AgentVerdict}. Designed for the
|
|
1350
|
-
* hot path of edge/Node middleware: warm verification is a header parse, one
|
|
1351
|
-
* map lookup, and one WebCrypto verify — no network, well under the 5ms p95
|
|
1352
|
-
* budget in the acceptance criteria.
|
|
1353
|
-
*/
|
|
1354
|
-
|
|
1355
|
-
declare class AgentVerifier {
|
|
1356
|
-
private readonly cache;
|
|
1357
|
-
private readonly toleranceSec;
|
|
1358
|
-
constructor(options?: AgentVerifierOptions);
|
|
1359
|
-
/** Pre-fetch trusted directories so the first request verifies warm. */
|
|
1360
|
-
warmup(): void;
|
|
1361
|
-
/** Verify a request's Web Bot Auth signature (if any) locally. */
|
|
1362
|
-
verify(request: AgentRequestInput): Promise<AgentVerdict>;
|
|
1363
|
-
/** Cached-key count (diagnostics/tests). */
|
|
1364
|
-
get cachedKeyCount(): number;
|
|
1365
|
-
}
|
|
1366
|
-
/** Convenience factory mirroring the SDK's other `create*` helpers. */
|
|
1367
|
-
declare function createAgentVerifier(options?: AgentVerifierOptions): AgentVerifier;
|
|
1368
|
-
|
|
1369
|
-
/**
|
|
1370
|
-
* RFC 9421 HTTP Message Signatures — the Web Bot Auth verification core.
|
|
1371
|
-
*
|
|
1372
|
-
* Verifies signatures tagged `web-bot-auth`: parse `Signature-Input` /
|
|
1373
|
-
* `Signature`, rebuild the signature base for each covered-component set, and
|
|
1374
|
-
* check the raw signature with WebCrypto against a key resolved by its JWK
|
|
1375
|
-
* thumbprint keyid. Adapted from the WebDecoy edge validator
|
|
1376
|
-
* (`edge/clearance-worker/src/web-bot-auth.ts`), generalized to resolve keys
|
|
1377
|
-
* from a directory cache instead of a pushed key list.
|
|
1378
|
-
*
|
|
1379
|
-
* Zero dependencies, Edge-runtime safe: only `crypto.subtle`, `TextEncoder`,
|
|
1380
|
-
* `atob`, and `URL` are used.
|
|
1381
|
-
*/
|
|
1382
|
-
/** A verification key resolved from a trusted directory, ready for WebCrypto. */
|
|
1383
|
-
interface VerificationKey {
|
|
1384
|
-
cryptoKey: CryptoKey;
|
|
1385
|
-
/** WebCrypto verify params (e.g. `{ name: 'Ed25519' }`). */
|
|
1386
|
-
verifyParams: AlgorithmIdentifier | RsaPssParams;
|
|
1387
|
-
/** Human-readable algorithm label, e.g. "ed25519". */
|
|
1388
|
-
algorithm: string;
|
|
1389
|
-
/** Display name of the owning agent. */
|
|
1390
|
-
name: string;
|
|
1391
|
-
/** Category of the owning agent. */
|
|
1392
|
-
category: string;
|
|
1393
|
-
/** Key validity bounds in Unix seconds, if the directory published them. */
|
|
1394
|
-
nbf?: number;
|
|
1395
|
-
exp?: number;
|
|
1396
|
-
}
|
|
1397
|
-
/** Resolves a JWK-thumbprint keyid to a verification key, or undefined if unknown. */
|
|
1398
|
-
type KeyResolver = (keyId: string) => Promise<VerificationKey | undefined>;
|
|
1399
|
-
|
|
1400
|
-
/**
|
|
1401
|
-
* Cached Web Bot Auth directory client.
|
|
1402
|
-
*
|
|
1403
|
-
* Fetches the JWK sets of a **curated** set of trusted agent directories,
|
|
1404
|
-
* imports their keys into WebCrypto, and indexes them by JWK-thumbprint keyid
|
|
1405
|
-
* so signatures resolve in O(1) with zero network on the warm path.
|
|
1406
|
-
*
|
|
1407
|
-
* Security posture — the reason this is curated-only:
|
|
1408
|
-
* a request's own `Signature-Agent` header is **never** used to choose a fetch
|
|
1409
|
-
* target, so an attacker cannot make the middleware fetch an arbitrary URL
|
|
1410
|
-
* (no SSRF). Only the origins in {@link AgentVerifierOptions.directories} are
|
|
1411
|
-
* ever contacted. This mirrors the backend curation
|
|
1412
|
-
* (`backend/internal/services/signed_agents.go`).
|
|
1413
|
-
*
|
|
1414
|
-
* Freshness — stale-while-revalidate: once populated, an expired cache keeps
|
|
1415
|
-
* serving its keys while a background refresh runs, so verification latency is
|
|
1416
|
-
* never coupled to a directory fetch. A cold cache (never populated) blocks
|
|
1417
|
-
* once to fetch, then backs off briefly if every directory is unreachable so a
|
|
1418
|
-
* degraded network can't be hammered per request.
|
|
1419
|
-
*/
|
|
1420
|
-
|
|
1421
|
-
/**
|
|
1422
|
-
* The default curated allowlist. These are the agents that sign production
|
|
1423
|
-
* traffic today; kept in lock-step with the backend's curated list.
|
|
1424
|
-
*/
|
|
1425
|
-
declare const DEFAULT_SIGNED_AGENT_DIRECTORIES: SignedAgentDirectory[];
|
|
1426
|
-
interface DirectoryCacheOptions {
|
|
1427
|
-
directories: SignedAgentDirectory[];
|
|
1428
|
-
cacheTtlMs: number;
|
|
1429
|
-
fetchTimeoutMs: number;
|
|
1430
|
-
debug: boolean;
|
|
1431
|
-
fetchImpl: typeof fetch;
|
|
1432
|
-
}
|
|
1433
|
-
declare class DirectoryCache {
|
|
1434
|
-
private readonly opts;
|
|
1435
|
-
private keys;
|
|
1436
|
-
private refreshedAt;
|
|
1437
|
-
private nextColdRetryAt;
|
|
1438
|
-
private inflight;
|
|
1439
|
-
constructor(opts: DirectoryCacheOptions);
|
|
1440
|
-
/** Resolve a keyid to a verification key, fetching/refreshing as needed. */
|
|
1441
|
-
resolveKey: KeyResolver;
|
|
1442
|
-
/** Kick off a fetch without blocking — call at startup to warm the cache. */
|
|
1443
|
-
prime(): void;
|
|
1444
|
-
/** Number of keys currently cached (diagnostics/tests). */
|
|
1445
|
-
get size(): number;
|
|
1446
|
-
private ensureFresh;
|
|
1447
|
-
/** Re-fetch every directory. De-duplicated: concurrent callers share one run. */
|
|
1448
|
-
refresh(): Promise<void>;
|
|
1449
|
-
private doRefresh;
|
|
1450
|
-
private fetchDirectory;
|
|
1451
|
-
private debug;
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1454
|
-
/**
|
|
1455
|
-
* Detection engine types.
|
|
1456
|
-
*
|
|
1457
|
-
* The detection engine scores a set of client-collected `Signals` against ~40
|
|
1458
|
-
* behavioral, environmental, and fingerprint heuristics and produces a verdict.
|
|
1459
|
-
* Ported from the FCaptcha scoring engine so behavior matches the self-hosted
|
|
1460
|
-
* server (server.js `runVerification`).
|
|
1461
|
-
*
|
|
1462
|
-
* Signals originate from an untrusted client, so every field is optional and the
|
|
1463
|
-
* detectors fall back to neutral defaults (mirroring the `?? default` pattern in
|
|
1464
|
-
* the reference implementation).
|
|
1465
|
-
*/
|
|
1466
|
-
/** A single triggered heuristic. */
|
|
1467
|
-
interface Detection {
|
|
1468
|
-
/** Scoring bucket this detection contributes to (see {@link Weights}). */
|
|
1469
|
-
category: string;
|
|
1470
|
-
/** Likelihood this signal indicates a bot/attack, 0..1. */
|
|
1471
|
-
score: number;
|
|
1472
|
-
/** Certainty of the score, 0..1, used to weight the per-category aggregate. */
|
|
1473
|
-
confidence: number;
|
|
1474
|
-
/** Human-readable explanation. */
|
|
1475
|
-
reason: string;
|
|
1476
|
-
/** Optional structured detail (e.g. keystroke-cadence metrics). */
|
|
1477
|
-
details?: Record<string, unknown>;
|
|
1478
|
-
}
|
|
1479
|
-
/** Per-category aggregated scores (0..1), keyed by category name. */
|
|
1480
|
-
type CategoryScores = Record<string, number>;
|
|
1481
|
-
/** Final action recommendation derived from the weighted score. */
|
|
1482
|
-
type Recommendation = 'allow' | 'challenge' | 'block';
|
|
1483
|
-
/** Behavioral signals: mouse, touch, keyboard, and interaction timing. */
|
|
1484
|
-
interface BehavioralSignals {
|
|
1485
|
-
totalPoints?: number;
|
|
1486
|
-
trajectoryLength?: number;
|
|
1487
|
-
approachPoints?: number;
|
|
1488
|
-
touchEvents?: number;
|
|
1489
|
-
keyEvents?: number;
|
|
1490
|
-
microTremorScore?: number;
|
|
1491
|
-
approachDirectness?: number;
|
|
1492
|
-
clickPrecision?: number;
|
|
1493
|
-
explorationRatio?: number;
|
|
1494
|
-
velocityVariance?: number;
|
|
1495
|
-
overshootCorrections?: number;
|
|
1496
|
-
interactionDuration?: number;
|
|
1497
|
-
mouseEventRate?: number;
|
|
1498
|
-
straightLineRatio?: number;
|
|
1499
|
-
directionChanges?: number;
|
|
1500
|
-
eventDeltaVariance?: number;
|
|
1501
|
-
touchTotalPoints?: number;
|
|
1502
|
-
touchForceMin?: number;
|
|
1503
|
-
touchForceMax?: number;
|
|
1504
|
-
touchForceVariance?: number;
|
|
1505
|
-
touchForceAllOne?: boolean;
|
|
1506
|
-
touchForceAllZero?: boolean;
|
|
1507
|
-
touchRadiusMin?: number;
|
|
1508
|
-
touchRadiusMax?: number;
|
|
1509
|
-
touchRadiusVariance?: number;
|
|
1510
|
-
touchUniqueIdentifiers?: number;
|
|
1511
|
-
touchMultiTouchSeen?: boolean;
|
|
1512
|
-
touchStraightLineRatio?: number;
|
|
1513
|
-
touchMicroTremorScore?: number;
|
|
1514
|
-
touchDirectionChanges?: number;
|
|
1515
|
-
[key: string]: unknown;
|
|
1516
|
-
}
|
|
1517
|
-
interface PoWTiming {
|
|
1518
|
-
duration?: number;
|
|
1519
|
-
iterations?: number;
|
|
1520
|
-
[key: string]: unknown;
|
|
1521
|
-
}
|
|
1522
|
-
interface TemporalSignals {
|
|
1523
|
-
pow?: PoWTiming;
|
|
1524
|
-
pageLoadToFirstInteraction?: number | null;
|
|
1525
|
-
[key: string]: unknown;
|
|
1526
|
-
}
|
|
1527
|
-
interface EnvironmentalSignals {
|
|
1528
|
-
webdriver?: boolean;
|
|
1529
|
-
headlessIndicators?: {
|
|
1530
|
-
hasOuterDimensions?: boolean;
|
|
1531
|
-
innerEqualsOuter?: boolean;
|
|
1532
|
-
notificationPermission?: string;
|
|
1533
|
-
[key: string]: unknown;
|
|
1534
|
-
};
|
|
1535
|
-
automationFlags?: {
|
|
1536
|
-
plugins?: number;
|
|
1537
|
-
languages?: boolean;
|
|
1538
|
-
chrome?: boolean;
|
|
1539
|
-
platform?: string;
|
|
1540
|
-
maxTouchPoints?: number;
|
|
1541
|
-
hardwareConcurrency?: number;
|
|
1542
|
-
[key: string]: unknown;
|
|
1543
|
-
};
|
|
1544
|
-
navigator?: {
|
|
1545
|
-
platform?: string;
|
|
1546
|
-
maxTouchPoints?: number;
|
|
1547
|
-
[key: string]: unknown;
|
|
1548
|
-
};
|
|
1549
|
-
webglInfo?: {
|
|
1550
|
-
renderer?: string;
|
|
1551
|
-
[key: string]: unknown;
|
|
1552
|
-
};
|
|
1553
|
-
playwright?: {
|
|
1554
|
-
detected?: boolean;
|
|
1555
|
-
signals?: string[];
|
|
1556
|
-
};
|
|
1557
|
-
cdp?: {
|
|
1558
|
-
detected?: boolean;
|
|
1559
|
-
signals?: string[];
|
|
1560
|
-
};
|
|
1561
|
-
jsExecutionTime?: {
|
|
1562
|
-
mathOps?: number;
|
|
1563
|
-
[key: string]: unknown;
|
|
1564
|
-
};
|
|
1565
|
-
rafConsistency?: {
|
|
1566
|
-
frameTimeVariance?: number;
|
|
1567
|
-
[key: string]: unknown;
|
|
1568
|
-
};
|
|
1569
|
-
canvasHash?: {
|
|
1570
|
-
hash?: string;
|
|
1571
|
-
error?: unknown;
|
|
1572
|
-
supported?: boolean;
|
|
1573
|
-
[key: string]: unknown;
|
|
1574
|
-
};
|
|
1575
|
-
sensor?: {
|
|
1576
|
-
motionEventCount?: number;
|
|
1577
|
-
motionAccelVariance?: number;
|
|
1578
|
-
orientationEventCount?: number;
|
|
1579
|
-
orientationVariance?: number;
|
|
1580
|
-
[key: string]: unknown;
|
|
1581
|
-
};
|
|
1582
|
-
webrtcInfo?: WebRTCInfo;
|
|
1583
|
-
speechInfo?: SpeechInfo;
|
|
1584
|
-
workerConsistency?: WorkerConsistencyInfo;
|
|
1585
|
-
cssMediaQueries?: CSSMediaQueriesInfo;
|
|
1586
|
-
fontsInfo?: FontsInfo;
|
|
1587
|
-
permissionsInfo?: PermissionsInfo;
|
|
1588
|
-
domRectFingerprint?: DOMRectInfo;
|
|
1589
|
-
audioInfo?: AudioContextInfo;
|
|
1590
|
-
lieDetection?: LieDetectionInfo;
|
|
1591
|
-
[key: string]: unknown;
|
|
1592
|
-
}
|
|
1593
|
-
interface WebRTCInfo {
|
|
1594
|
-
supported?: boolean;
|
|
1595
|
-
mediaDevices?: {
|
|
1596
|
-
supported?: boolean;
|
|
1597
|
-
audioInputs?: number;
|
|
1598
|
-
audioOutputs?: number;
|
|
1599
|
-
videoInputs?: number;
|
|
1600
|
-
totalDevices?: number;
|
|
1601
|
-
};
|
|
1602
|
-
hasLocalIP?: boolean;
|
|
1603
|
-
localIPError?: unknown;
|
|
1604
|
-
[key: string]: unknown;
|
|
1605
|
-
}
|
|
1606
|
-
interface SpeechInfo {
|
|
1607
|
-
supported?: boolean;
|
|
1608
|
-
totalVoices?: number;
|
|
1609
|
-
localVoices?: number;
|
|
1610
|
-
[key: string]: unknown;
|
|
1611
|
-
}
|
|
1612
|
-
interface WorkerConsistencyInfo {
|
|
1613
|
-
supported?: boolean;
|
|
1614
|
-
consistent?: boolean;
|
|
1615
|
-
mismatches?: string[];
|
|
1616
|
-
mismatchCount?: number;
|
|
1617
|
-
[key: string]: unknown;
|
|
1618
|
-
}
|
|
1619
|
-
interface CSSMediaQueriesInfo {
|
|
1620
|
-
supported?: boolean;
|
|
1621
|
-
pointer?: string;
|
|
1622
|
-
hover?: boolean;
|
|
1623
|
-
[key: string]: unknown;
|
|
1624
|
-
}
|
|
1625
|
-
interface FontsInfo {
|
|
1626
|
-
supported?: boolean;
|
|
1627
|
-
count?: number;
|
|
1628
|
-
hasSegoeUI?: boolean;
|
|
1629
|
-
hasSFPro?: boolean;
|
|
1630
|
-
hasDejaVuSans?: boolean;
|
|
1631
|
-
[key: string]: unknown;
|
|
1632
|
-
}
|
|
1633
|
-
interface PermissionsInfo {
|
|
1634
|
-
supported?: boolean;
|
|
1635
|
-
[key: string]: unknown;
|
|
1636
|
-
}
|
|
1637
|
-
interface DOMRectInfo {
|
|
1638
|
-
supported?: boolean;
|
|
1639
|
-
rectAWidth?: number;
|
|
1640
|
-
rectBWidth?: number;
|
|
1641
|
-
rangeWidth?: number;
|
|
1642
|
-
[key: string]: unknown;
|
|
1643
|
-
}
|
|
1644
|
-
/** AudioContext fingerprint. A real audio stack exposes `baseLatency` and a
|
|
1645
|
-
* conventional sample rate; headless/mocked stacks omit or fake these. */
|
|
1646
|
-
interface AudioContextInfo {
|
|
1647
|
-
supported?: boolean;
|
|
1648
|
-
sampleRate?: number;
|
|
1649
|
-
state?: string;
|
|
1650
|
-
baseLatency?: number | null;
|
|
1651
|
-
[key: string]: unknown;
|
|
1652
|
-
}
|
|
1653
|
-
/** Native-function integrity check. `patched` lists native functions whose
|
|
1654
|
-
* `toString()` no longer reports `[native code]` (or whose prototype was
|
|
1655
|
-
* tampered with) — the signature of stealth automation hiding itself. A real
|
|
1656
|
-
* browser never patches its own natives. */
|
|
1657
|
-
interface LieDetectionInfo {
|
|
1658
|
-
supported?: boolean;
|
|
1659
|
-
patched?: string[];
|
|
1660
|
-
patchedCount?: number;
|
|
1661
|
-
[key: string]: unknown;
|
|
1662
|
-
}
|
|
1663
|
-
/** Per-field keystroke statistics for one textarea. */
|
|
1664
|
-
interface TextareaKeyboardStats {
|
|
1665
|
-
keyCount?: number;
|
|
1666
|
-
pasteCount?: number;
|
|
1667
|
-
avgKeyInterval?: number;
|
|
1668
|
-
keyIntervalVariance?: number;
|
|
1669
|
-
keydownUpRatio?: number;
|
|
1670
|
-
noKeyboardEvents?: boolean;
|
|
1671
|
-
contentLength?: number;
|
|
1672
|
-
intervals?: number[];
|
|
1673
|
-
dwellTimes?: number[];
|
|
1674
|
-
rollovers?: number;
|
|
1675
|
-
[key: string]: unknown;
|
|
1676
|
-
}
|
|
1677
|
-
interface FormSubmitInfo {
|
|
1678
|
-
method?: string;
|
|
1679
|
-
timeSincePageLoad?: number | null;
|
|
1680
|
-
eventsBeforeSubmit?: number;
|
|
1681
|
-
hadTriggerEvent?: boolean;
|
|
1682
|
-
[key: string]: unknown;
|
|
1683
|
-
}
|
|
1684
|
-
interface FormAnalysisSignals {
|
|
1685
|
-
pageLoadToFirstInteraction?: number | null;
|
|
1686
|
-
submit?: FormSubmitInfo;
|
|
1687
|
-
textareaKeyboard?: Record<string, TextareaKeyboardStats>;
|
|
1688
|
-
[key: string]: unknown;
|
|
1689
|
-
}
|
|
1690
|
-
/** The full set of signals the client widget reports. */
|
|
1691
|
-
interface Signals {
|
|
1692
|
-
behavioral?: BehavioralSignals;
|
|
1693
|
-
temporal?: TemporalSignals;
|
|
1694
|
-
environmental?: EnvironmentalSignals;
|
|
1695
|
-
formAnalysis?: FormAnalysisSignals;
|
|
1696
|
-
meta?: {
|
|
1697
|
-
challengeNonce?: string;
|
|
1698
|
-
[key: string]: unknown;
|
|
1699
|
-
};
|
|
1700
|
-
[key: string]: unknown;
|
|
1701
|
-
}
|
|
1702
|
-
/**
|
|
1703
|
-
* Outcome of proof-of-work verification, supplied by the caller (the PoW
|
|
1704
|
-
* subsystem lands in Phase 2). When omitted and `requirePoW` is enabled the
|
|
1705
|
-
* engine emits a hard-fail "No PoW solution provided" detection, matching the
|
|
1706
|
-
* reference server.
|
|
1707
|
-
*/
|
|
1708
|
-
interface PoWOutcome {
|
|
1709
|
-
/** Whether a PoW solution was submitted at all. */
|
|
1710
|
-
provided: boolean;
|
|
1711
|
-
/** Whether the submitted solution verified. */
|
|
1712
|
-
valid?: boolean;
|
|
1713
|
-
/** Failure reason when `valid` is false. */
|
|
1714
|
-
reason?: string;
|
|
1715
|
-
/** Server-measured solve time in ms (un-spoofable). */
|
|
1716
|
-
serverElapsed?: number;
|
|
1717
|
-
/** Nonce bound to the verified challenge. */
|
|
1718
|
-
nonce?: string;
|
|
1719
|
-
}
|
|
1720
|
-
/** Per-request context for scoring. */
|
|
1721
|
-
interface DetectionContext {
|
|
1722
|
-
ip: string;
|
|
1723
|
-
siteKey: string;
|
|
1724
|
-
userAgent: string;
|
|
1725
|
-
/** Lower-cased request headers. */
|
|
1726
|
-
headers?: Record<string, string>;
|
|
1727
|
-
/** Client-supplied JA3 hash (spoofable). */
|
|
1728
|
-
ja3Hash?: string | null;
|
|
1729
|
-
/** Trusted reverse-proxy header names carrying a JA4 fingerprint. */
|
|
1730
|
-
trustedJA4Headers?: string[];
|
|
1731
|
-
/** Proof-of-work verification outcome (supplied by the PoW subsystem). */
|
|
1732
|
-
pow?: PoWOutcome;
|
|
1733
|
-
/**
|
|
1734
|
-
* Additional detections to fold into scoring, produced by an outer
|
|
1735
|
-
* orchestrator (e.g. the signals-tampering check in the Captcha service).
|
|
1736
|
-
*/
|
|
1737
|
-
extraDetections?: Detection[];
|
|
1738
|
-
}
|
|
1739
|
-
/** Final verdict returned by {@link DetectionEngine.score}. */
|
|
1740
|
-
interface Verdict {
|
|
1741
|
-
/** True when the weighted score is below the success threshold (< 0.5). */
|
|
1742
|
-
success: boolean;
|
|
1743
|
-
/** Weighted final score, 0..1. */
|
|
1744
|
-
score: number;
|
|
1745
|
-
/** Recommended action. */
|
|
1746
|
-
recommendation: Recommendation;
|
|
1747
|
-
/** Per-category aggregated scores. */
|
|
1748
|
-
categoryScores: CategoryScores;
|
|
1749
|
-
/** Every triggered detection. */
|
|
1750
|
-
detections: Detection[];
|
|
1751
|
-
/** Unix seconds at evaluation time. */
|
|
1752
|
-
timestamp: number;
|
|
1753
|
-
}
|
|
1754
|
-
|
|
1326
|
+
* rateLimit({ max: 100, window: 60 }),
|
|
1327
|
+
* ],
|
|
1328
|
+
* });
|
|
1329
|
+
* ```
|
|
1330
|
+
*/
|
|
1331
|
+
declare function rateLimit(config: RateLimitConfig): Rule;
|
|
1755
1332
|
/**
|
|
1756
|
-
*
|
|
1757
|
-
* rate abuse). Ported from FCaptcha index.js.
|
|
1333
|
+
* Factory function to create a filter rule
|
|
1758
1334
|
*
|
|
1759
|
-
*
|
|
1760
|
-
*
|
|
1335
|
+
* @example
|
|
1336
|
+
* ```typescript
|
|
1337
|
+
* import { filter } from '@webdecoy/node';
|
|
1338
|
+
*
|
|
1339
|
+
* const sdk = new WebDecoy({
|
|
1340
|
+
* apiKey: process.env.WEBDECOY_API_KEY,
|
|
1341
|
+
* rules: [
|
|
1342
|
+
* filter({ expression: 'ip.vpn or ip.tor', action: 'DENY' }),
|
|
1343
|
+
* filter({ expression: 'ip.country in ["CN", "RU"]', action: 'DENY' }),
|
|
1344
|
+
* ],
|
|
1345
|
+
* });
|
|
1346
|
+
* ```
|
|
1761
1347
|
*/
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1348
|
+
declare function filter(config: FilterConfig): Rule;
|
|
1349
|
+
/**
|
|
1350
|
+
* Factory function to create a tripwire (honeypot-path) rule.
|
|
1351
|
+
*
|
|
1352
|
+
* Deterministic, zero-false-positive: any request for a hidden honeypot path is
|
|
1353
|
+
* automated by construction. Detects intent (going where a human can't), which
|
|
1354
|
+
* stealth fingerprint-spoofing (e.g. botasaurus) cannot evade.
|
|
1355
|
+
*
|
|
1356
|
+
* @example
|
|
1357
|
+
* ```typescript
|
|
1358
|
+
* import { WebDecoy, tripwire, honeytoken } from '@webdecoy/node';
|
|
1359
|
+
*
|
|
1360
|
+
* const hp = honeytoken();
|
|
1361
|
+
* const sdk = new WebDecoy({
|
|
1362
|
+
* rules: [
|
|
1363
|
+
* tripwire({ paths: [hp.path] }), // + built-in scanner-bait paths
|
|
1364
|
+
* ],
|
|
1365
|
+
* });
|
|
1366
|
+
* // inject hp.linkHtml into your pages
|
|
1367
|
+
* ```
|
|
1368
|
+
*/
|
|
1369
|
+
declare function tripwire(config?: TripwireConfig): Rule;
|
|
1370
|
+
/**
|
|
1371
|
+
* Factory function to create a bot-category rule.
|
|
1372
|
+
*
|
|
1373
|
+
* Acts on agents that identify themselves in the User-Agent, matched against the
|
|
1374
|
+
* registry generated from the same table the scoring pipeline uses — so
|
|
1375
|
+
* `'training_crawler'` here means what `ai_scraper_category` means in your
|
|
1376
|
+
* dashboard.
|
|
1377
|
+
*
|
|
1378
|
+
* @example
|
|
1379
|
+
* ```typescript
|
|
1380
|
+
* import { WebDecoy, bots } from '@webdecoy/node';
|
|
1381
|
+
*
|
|
1382
|
+
* const sdk = new WebDecoy({
|
|
1383
|
+
* rules: [
|
|
1384
|
+
* // Keep AI models out of your content, keep your search ranking.
|
|
1385
|
+
* bots({ categories: ['training_crawler'] }),
|
|
1386
|
+
*
|
|
1387
|
+
* // Or everything AI, minus the one you want referral traffic from.
|
|
1388
|
+
* bots({ ai: true, allow: ['perplexitybot'] }),
|
|
1389
|
+
*
|
|
1390
|
+
* // Or a specific operator.
|
|
1391
|
+
* bots({ agents: ['gptbot', 'ClaudeBot'], action: 'THROTTLE' }),
|
|
1392
|
+
* ],
|
|
1393
|
+
* });
|
|
1394
|
+
* ```
|
|
1395
|
+
*
|
|
1396
|
+
* Only catches agents that declare themselves — anything spoofing a browser
|
|
1397
|
+
* passes through, by design. Pair with {@link tripwire} for agents that lie.
|
|
1398
|
+
*/
|
|
1399
|
+
declare function bots(config?: BotRuleConfig): Rule;
|
|
1786
1400
|
|
|
1787
1401
|
/**
|
|
1788
|
-
*
|
|
1402
|
+
* AgentVerifier — the public entry point for local Web Bot Auth verification.
|
|
1789
1403
|
*
|
|
1790
|
-
*
|
|
1791
|
-
*
|
|
1792
|
-
*
|
|
1793
|
-
*
|
|
1404
|
+
* Wraps the cached directory client and the signature core into a single
|
|
1405
|
+
* `verify(request)` call returning an {@link AgentVerdict}. Designed for the
|
|
1406
|
+
* hot path of edge/Node middleware: warm verification is a header parse, one
|
|
1407
|
+
* map lookup, and one WebCrypto verify — no network, well under the 5ms p95
|
|
1408
|
+
* budget in the acceptance criteria.
|
|
1794
1409
|
*/
|
|
1795
1410
|
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
fingerprintStore?: FingerprintStore;
|
|
1807
|
-
/** Rate limiter for rate-abuse detection (defaults to in-memory). */
|
|
1808
|
-
rateLimiter?: RateLimiter;
|
|
1809
|
-
}
|
|
1810
|
-
declare class DetectionEngine {
|
|
1811
|
-
private readonly weights;
|
|
1812
|
-
private readonly requirePoW;
|
|
1813
|
-
private readonly fingerprintStore;
|
|
1814
|
-
private readonly rateLimiter;
|
|
1815
|
-
constructor(options?: DetectionEngineOptions);
|
|
1816
|
-
/** Score `signals` for the given request context and return a verdict. */
|
|
1817
|
-
score(signals: Signals, context: DetectionContext): Verdict;
|
|
1411
|
+
declare class AgentVerifier {
|
|
1412
|
+
private readonly cache;
|
|
1413
|
+
private readonly toleranceSec;
|
|
1414
|
+
constructor(options?: AgentVerifierOptions);
|
|
1415
|
+
/** Pre-fetch trusted directories so the first request verifies warm. */
|
|
1416
|
+
warmup(): void;
|
|
1417
|
+
/** Verify a request's Web Bot Auth signature (if any) locally. */
|
|
1418
|
+
verify(request: AgentRequestInput): Promise<AgentVerdict>;
|
|
1419
|
+
/** Cached-key count (diagnostics/tests). */
|
|
1420
|
+
get cachedKeyCount(): number;
|
|
1818
1421
|
}
|
|
1819
|
-
|
|
1820
|
-
|
|
1422
|
+
/** Convenience factory mirroring the SDK's other `create*` helpers. */
|
|
1423
|
+
declare function createAgentVerifier(options?: AgentVerifierOptions): AgentVerifier;
|
|
1821
1424
|
|
|
1822
1425
|
/**
|
|
1823
|
-
*
|
|
1824
|
-
*
|
|
1825
|
-
*
|
|
1426
|
+
* RFC 9421 HTTP Message Signatures — the Web Bot Auth verification core.
|
|
1427
|
+
*
|
|
1428
|
+
* Verifies signatures tagged `web-bot-auth`: parse `Signature-Input` /
|
|
1429
|
+
* `Signature`, rebuild the signature base for each covered-component set, and
|
|
1430
|
+
* check the raw signature with WebCrypto against a key resolved by its JWK
|
|
1431
|
+
* thumbprint keyid. Adapted from the WebDecoy edge validator
|
|
1432
|
+
* (`edge/clearance-worker/src/web-bot-auth.ts`), generalized to resolve keys
|
|
1433
|
+
* from a directory cache instead of a pushed key list.
|
|
1434
|
+
*
|
|
1435
|
+
* Zero dependencies, Edge-runtime safe: only `crypto.subtle`, `TextEncoder`,
|
|
1436
|
+
* `atob`, and `URL` are used.
|
|
1826
1437
|
*/
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
/**
|
|
1831
|
-
|
|
1438
|
+
/** A verification key resolved from a trusted directory, ready for WebCrypto. */
|
|
1439
|
+
interface VerificationKey {
|
|
1440
|
+
cryptoKey: CryptoKey;
|
|
1441
|
+
/** WebCrypto verify params (e.g. `{ name: 'Ed25519' }`). */
|
|
1442
|
+
verifyParams: AlgorithmIdentifier | RsaPssParams;
|
|
1443
|
+
/** Human-readable algorithm label, e.g. "ed25519". */
|
|
1444
|
+
algorithm: string;
|
|
1445
|
+
/** Display name of the owning agent. */
|
|
1446
|
+
name: string;
|
|
1447
|
+
/** Category of the owning agent. */
|
|
1448
|
+
category: string;
|
|
1449
|
+
/** Key validity bounds in Unix seconds, if the directory published them. */
|
|
1450
|
+
nbf?: number;
|
|
1451
|
+
exp?: number;
|
|
1452
|
+
}
|
|
1453
|
+
/** Resolves a JWK-thumbprint keyid to a verification key, or undefined if unknown. */
|
|
1454
|
+
type KeyResolver = (keyId: string) => Promise<VerificationKey | undefined>;
|
|
1832
1455
|
|
|
1833
1456
|
/**
|
|
1834
|
-
*
|
|
1457
|
+
* Cached Web Bot Auth directory client.
|
|
1835
1458
|
*
|
|
1836
|
-
*
|
|
1837
|
-
*
|
|
1838
|
-
|
|
1839
|
-
/**
|
|
1840
|
-
* Default per-category weights used to compute the final score.
|
|
1459
|
+
* Fetches the JWK sets of a **curated** set of trusted agent directories,
|
|
1460
|
+
* imports their keys into WebCrypto, and indexes them by JWK-thumbprint keyid
|
|
1461
|
+
* so signatures resolve in O(1) with zero network on the warm path.
|
|
1841
1462
|
*
|
|
1842
|
-
*
|
|
1843
|
-
*
|
|
1844
|
-
*
|
|
1845
|
-
*
|
|
1846
|
-
*
|
|
1847
|
-
*
|
|
1463
|
+
* Security posture — the reason this is curated-only:
|
|
1464
|
+
* a request's own `Signature-Agent` header is **never** used to choose a fetch
|
|
1465
|
+
* target, so an attacker cannot make the middleware fetch an arbitrary URL
|
|
1466
|
+
* (no SSRF). Only the origins in {@link AgentVerifierOptions.directories} are
|
|
1467
|
+
* ever contacted. This mirrors the backend curation
|
|
1468
|
+
* (`backend/internal/services/signed_agents.go`).
|
|
1469
|
+
*
|
|
1470
|
+
* Freshness — stale-while-revalidate: once populated, an expired cache keeps
|
|
1471
|
+
* serving its keys while a background refresh runs, so verification latency is
|
|
1472
|
+
* never coupled to a directory fetch. A cold cache (never populated) blocks
|
|
1473
|
+
* once to fetch, then backs off briefly if every directory is unreachable so a
|
|
1474
|
+
* degraded network can't be hammered per request.
|
|
1848
1475
|
*/
|
|
1849
|
-
declare const DEFAULT_WEIGHTS: Record<string, number>;
|
|
1850
|
-
|
|
1851
|
-
/** True when `ip` falls inside a known datacenter CIDR block (IPv4 only). */
|
|
1852
|
-
declare function isDatacenterIP(ip: string): boolean;
|
|
1853
1476
|
|
|
1854
1477
|
/**
|
|
1855
|
-
*
|
|
1478
|
+
* The default curated allowlist. These are the agents that sign production
|
|
1479
|
+
* traffic today; kept in lock-step with the backend's curated list.
|
|
1856
1480
|
*/
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1481
|
+
declare const DEFAULT_SIGNED_AGENT_DIRECTORIES: SignedAgentDirectory[];
|
|
1482
|
+
interface DirectoryCacheOptions {
|
|
1483
|
+
directories: SignedAgentDirectory[];
|
|
1484
|
+
cacheTtlMs: number;
|
|
1485
|
+
fetchTimeoutMs: number;
|
|
1486
|
+
debug: boolean;
|
|
1487
|
+
fetchImpl: typeof fetch;
|
|
1488
|
+
}
|
|
1489
|
+
declare class DirectoryCache {
|
|
1490
|
+
private readonly opts;
|
|
1491
|
+
private keys;
|
|
1492
|
+
private refreshedAt;
|
|
1493
|
+
private nextColdRetryAt;
|
|
1494
|
+
private inflight;
|
|
1495
|
+
constructor(opts: DirectoryCacheOptions);
|
|
1496
|
+
/** Resolve a keyid to a verification key, fetching/refreshing as needed. */
|
|
1497
|
+
resolveKey: KeyResolver;
|
|
1498
|
+
/** Kick off a fetch without blocking — call at startup to warm the cache. */
|
|
1499
|
+
prime(): void;
|
|
1500
|
+
/** Number of keys currently cached (diagnostics/tests). */
|
|
1501
|
+
get size(): number;
|
|
1502
|
+
private ensureFresh;
|
|
1503
|
+
/** Re-fetch every directory. De-duplicated: concurrent callers share one run. */
|
|
1504
|
+
refresh(): Promise<void>;
|
|
1505
|
+
private doRefresh;
|
|
1506
|
+
private fetchDirectory;
|
|
1507
|
+
private debug;
|
|
1863
1508
|
}
|
|
1864
|
-
/** True when the UA looks like a mobile device. */
|
|
1865
|
-
declare function isMobileUA(userAgent: string): boolean;
|
|
1866
|
-
/** Extract browser/OS/bot info from a User-Agent string. */
|
|
1867
|
-
declare function parseUserAgent(ua: string): UserAgentInfo;
|
|
1868
1509
|
|
|
1869
1510
|
/** Types for the self-hosted captcha service (PoW + scoring + tokens). */
|
|
1870
1511
|
|
|
@@ -2117,6 +1758,12 @@ interface CaptchaHttpResponse {
|
|
|
2117
1758
|
body: unknown;
|
|
2118
1759
|
}
|
|
2119
1760
|
interface CaptchaEndpointsOptions extends CaptchaOptions {
|
|
1761
|
+
/**
|
|
1762
|
+
* Where `/score` records its verdict, for `clientSignals()` to read on
|
|
1763
|
+
* subsequent requests. Omit and the score is returned to the browser and
|
|
1764
|
+
* forgotten, which is what happened before this existed.
|
|
1765
|
+
*/
|
|
1766
|
+
signalStore?: ClientSignalStore;
|
|
2120
1767
|
/** Base path the routes are mounted under (default `/__webdecoy`). */
|
|
2121
1768
|
basePath?: string;
|
|
2122
1769
|
}
|
|
@@ -2132,4 +1779,4 @@ declare function createCaptchaEndpoints(options?: CaptchaEndpointsOptions): {
|
|
|
2132
1779
|
};
|
|
2133
1780
|
type CaptchaEndpoints = ReturnType<typeof createCaptchaEndpoints>;
|
|
2134
1781
|
|
|
2135
|
-
export {
|
|
1782
|
+
export { ATTACK_SIGNATURE_IDS, AgentCategory, AgentRequestInput, AgentVerdict, AgentVerifier, AgentVerifierOptions, type AttackSignatureConfig, AttackSignatureRule, type BehavioralSignals, BotAgent, BotCategory, BotPolicy, type BotPolicyOptions, BotRule, BotRuleConfig, CLIENT_SESSION_COOKIE, CLIENT_SESSION_HEADER, Captcha, type CaptchaEndpoints, type CaptchaEndpointsOptions, type CaptchaHttpResponse, type CaptchaOptions, type CaptchaRequest, type CategoryScores, type ChallengeData, type ChallengeStore, type ClientSignalConfig, ClientSignalRule, type ClientSignalStore, type ClientVerdict, DEFAULT_SIGNED_AGENT_DIRECTORIES, DEFAULT_TRIPWIRE_PATHS, DEFAULT_WEIGHTS, Decision, type Detection, type DetectionContext, DetectionEngine, type DetectionEngineOptions, DirectoryCache, type EnvironmentalSignals, type FetchGuard, type FetchGuardOptions, FilterConfig, FilterRule, type FingerprintStore, type FormAnalysisSignals, type GuardOutcome, HONEYTOKEN_BASE_PATH, type HeaderSource, type Honeytoken, type HoneytokenLinkProps, type HoneytokenOptions, InMemoryChallengeStore, InMemoryFingerprintStore, InMemoryRateLimiter, InMemoryTokenStore, MemoryClientSignalStore, type MemoryClientSignalStoreOptions, PoWManager, type PoWManagerOptions, type PoWOutcome, type PoWSolution, type PoWVerification, ProtectOptions, RateLimitConfig, RateLimitConsume, RateLimitOutcome, RateLimitRule, RateLimitStore, type RateLimiter, type Recommendation, type ResolveClientIpOptions, type RobotsTxtOptions, Rule, RuleContext, RuleEngine, RuleEngineResult, RuleResult, type ScoreResult, type Signals, SignedAgentDirectory, type SiteHoneytoken, type SiteHoneytokenOptions, type StoredChallenge, TEST_TRIGGER_UA_PREFIX, TEST_TRIGGER_USER_AGENT, type TemporalSignals, type TextareaKeyboardStats, TokenManager, type TokenManagerOptions, type TokenStore, type TokenVerification, TripwireConfig, TripwireRule, type TrustedProxies, UpstashRateLimitStore, type UpstashStoreOptions, type Verdict, type VerifyInput, type VerifyResult, type WebBotAuthConfig, WebBotAuthRule, WebDecoy, WebDecoyConfig, attackSignatures, botPolicy, bots, calculateCategoryScores, calculateFinalScore, clientSignals, createAgentVerifier, createCaptchaEndpoints, createFetchGuard, filter, honeytoken, injectHoneytokenLink, ipInCidr, isDatacenterIP, isInjectableHtml, isMobileUA, isTestTriggerUserAgent, normalizeIp, parseUserAgent, rateLimit, readClientSession, recommend, resolveClientIp, resolveSecret, siteHoneytoken, tripwire, upstashRateLimitStore, webBotAuth };
|