@webdecoy/node 0.4.0 → 0.5.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/README.md +2 -2
- package/dist/index.d.mts +383 -14
- package/dist/index.d.ts +383 -14
- package/dist/index.js +963 -138
- package/dist/index.mjs +955 -126
- package/package.json +6 -8
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ const webdecoy = new WebDecoy({
|
|
|
45
45
|
apiKey: 'sk_live_xxxxx',
|
|
46
46
|
|
|
47
47
|
// Optional: API endpoint (defaults to production)
|
|
48
|
-
apiUrl: 'https://
|
|
48
|
+
apiUrl: 'https://ingest.webdecoy.com',
|
|
49
49
|
|
|
50
50
|
// Optional: Enable TLS fingerprinting (default: true)
|
|
51
51
|
enableTLSFingerprinting: true,
|
|
@@ -231,7 +231,7 @@ API keys start with `sk_live_` for production or `sk_test_` for testing.
|
|
|
231
231
|
|
|
232
232
|
## Documentation
|
|
233
233
|
|
|
234
|
-
For full documentation, visit the [GitHub repository](https://github.com/WebDecoy/node
|
|
234
|
+
For full documentation, visit the [GitHub repository](https://github.com/WebDecoy/node).
|
|
235
235
|
|
|
236
236
|
## License
|
|
237
237
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Bot Auth verification — public types.
|
|
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
|
+
* (WebDecoy/app#320) 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
|
+
};
|
|
119
|
+
|
|
1
120
|
/**
|
|
2
121
|
* Rules Engine Types
|
|
3
122
|
* Core interfaces for the WebDecoy rules engine
|
|
4
123
|
*/
|
|
124
|
+
|
|
5
125
|
/**
|
|
6
126
|
* Context available to rules during evaluation
|
|
7
127
|
*/
|
|
@@ -20,6 +140,12 @@ interface RuleContext {
|
|
|
20
140
|
timestamp: number;
|
|
21
141
|
/** IP enrichment data (populated async when available) */
|
|
22
142
|
enrichment?: IPEnrichmentData;
|
|
143
|
+
/**
|
|
144
|
+
* Web Bot Auth verdict (populated async before evaluation when a
|
|
145
|
+
* {@link https://github.com/WebDecoy/app/issues/323 webBotAuth} rule is
|
|
146
|
+
* present). Lets a synchronous rule act on cryptographic agent verification.
|
|
147
|
+
*/
|
|
148
|
+
agent?: AgentVerdict;
|
|
23
149
|
}
|
|
24
150
|
/**
|
|
25
151
|
* Result of evaluating a single rule
|
|
@@ -108,6 +234,13 @@ interface ViolationEvent {
|
|
|
108
234
|
userAgent?: string;
|
|
109
235
|
/** Reason for the violation */
|
|
110
236
|
reason?: string;
|
|
237
|
+
/**
|
|
238
|
+
* The request's wd_clearance token, when present. Lets the backend bind a
|
|
239
|
+
* tripwire hit to the actor's device fingerprint and deny it — the same
|
|
240
|
+
* durable lockout a decoy hit produces (enforcement issue #136). Only carried
|
|
241
|
+
* for deception rules (tripwires); undefined otherwise.
|
|
242
|
+
*/
|
|
243
|
+
clearance?: string;
|
|
111
244
|
/** Additional metadata */
|
|
112
245
|
metadata?: Record<string, any>;
|
|
113
246
|
/** Whether this was a dry run */
|
|
@@ -172,7 +305,7 @@ interface WebDecoyConfig {
|
|
|
172
305
|
apiKey?: string;
|
|
173
306
|
/**
|
|
174
307
|
* API URL for the Web Decoy ingest service
|
|
175
|
-
* @default 'https://
|
|
308
|
+
* @default 'https://ingest.webdecoy.com'
|
|
176
309
|
*/
|
|
177
310
|
apiUrl?: string;
|
|
178
311
|
/**
|
|
@@ -207,6 +340,12 @@ interface WebDecoyConfig {
|
|
|
207
340
|
* Rules are evaluated in order; first DENY/THROTTLE wins
|
|
208
341
|
*/
|
|
209
342
|
rules?: Rule[];
|
|
343
|
+
/**
|
|
344
|
+
* Options for local Web Bot Auth agent verification (used by `detectBot()`
|
|
345
|
+
* and the `webBotAuth()` rule) — trusted directories, cache TTL, etc.
|
|
346
|
+
* Defaults are sensible; override only to curate your own agent allowlist.
|
|
347
|
+
*/
|
|
348
|
+
webBotAuth?: AgentVerifierOptions;
|
|
210
349
|
}
|
|
211
350
|
/**
|
|
212
351
|
* TLS connection information from the request
|
|
@@ -303,6 +442,12 @@ interface ProtectResult {
|
|
|
303
442
|
error?: string;
|
|
304
443
|
/** Rule engine result (if rules were evaluated) */
|
|
305
444
|
ruleResult?: RuleEngineResult;
|
|
445
|
+
/**
|
|
446
|
+
* Web Bot Auth verdict, present when a `webBotAuth()` rule triggered the
|
|
447
|
+
* local agent verification for this request. Lets middleware treat a
|
|
448
|
+
* `verified` agent specially (e.g. allow) without re-verifying.
|
|
449
|
+
*/
|
|
450
|
+
agent?: AgentVerdict;
|
|
306
451
|
}
|
|
307
452
|
/**
|
|
308
453
|
* Options for the protect() method
|
|
@@ -318,7 +463,11 @@ interface ProtectOptions {
|
|
|
318
463
|
|
|
319
464
|
/**
|
|
320
465
|
* Web Decoy API Client
|
|
321
|
-
* Handles communication with the ingest service
|
|
466
|
+
* Handles communication with the ingest service.
|
|
467
|
+
*
|
|
468
|
+
* Uses the Web-standard `fetch` API (no axios, no `node:` imports) so the SDK
|
|
469
|
+
* runs in Node >= 18 and edge runtimes (Vercel Edge Middleware, Cloudflare
|
|
470
|
+
* Workers) alike.
|
|
322
471
|
*/
|
|
323
472
|
|
|
324
473
|
interface ClientConfig {
|
|
@@ -326,12 +475,19 @@ interface ClientConfig {
|
|
|
326
475
|
apiUrl: string;
|
|
327
476
|
timeout: number;
|
|
328
477
|
debug: boolean;
|
|
478
|
+
/**
|
|
479
|
+
* Kept for API compatibility; the fetch transport does not support disabling
|
|
480
|
+
* TLS verification. For local self-signed certs in Node, trust the CA
|
|
481
|
+
* instead: `NODE_EXTRA_CA_CERTS=/path/to/ca.pem`.
|
|
482
|
+
*/
|
|
329
483
|
tlsRejectUnauthorized: boolean;
|
|
330
484
|
}
|
|
331
485
|
declare class WebDecoyClient {
|
|
332
|
-
private axios;
|
|
333
486
|
private config;
|
|
487
|
+
private baseUrl;
|
|
488
|
+
private headers;
|
|
334
489
|
constructor(config: ClientConfig);
|
|
490
|
+
private request;
|
|
335
491
|
/**
|
|
336
492
|
* Send a detection request to the ingest service
|
|
337
493
|
*/
|
|
@@ -362,6 +518,9 @@ declare class WebDecoy {
|
|
|
362
518
|
private violationReporter;
|
|
363
519
|
private ipEnrichmentClient;
|
|
364
520
|
private _hasFilterRules;
|
|
521
|
+
private _hasAgentRules;
|
|
522
|
+
private agentVerifier;
|
|
523
|
+
private readonly webBotAuthOptions?;
|
|
365
524
|
constructor(config: WebDecoyConfig);
|
|
366
525
|
/**
|
|
367
526
|
* Evaluate rules against request metadata (synchronous).
|
|
@@ -369,14 +528,54 @@ declare class WebDecoy {
|
|
|
369
528
|
*/
|
|
370
529
|
evaluateRules(metadata: RequestMetadata): RuleEngineResult | null;
|
|
371
530
|
/**
|
|
372
|
-
* Evaluate rules with async IP enrichment
|
|
373
|
-
* Use this instead of evaluateRules() when filter rules
|
|
531
|
+
* Evaluate rules with async pre-fetch (IP enrichment, Web Bot Auth
|
|
532
|
+
* verification). Use this instead of evaluateRules() when filter rules or
|
|
533
|
+
* webBotAuth() rules are present.
|
|
374
534
|
*/
|
|
375
535
|
evaluateRulesAsync(metadata: RequestMetadata): Promise<RuleEngineResult | null>;
|
|
536
|
+
/** Build the base (synchronous) rule context from request metadata. */
|
|
537
|
+
private buildContext;
|
|
538
|
+
/**
|
|
539
|
+
* Build a rule context with async signals resolved: IP enrichment (for
|
|
540
|
+
* filter rules) and the Web Bot Auth verdict (for webBotAuth() rules).
|
|
541
|
+
*/
|
|
542
|
+
private buildAsyncContext;
|
|
543
|
+
/** Evaluate rules against a prepared context and report any violations. */
|
|
544
|
+
private runRules;
|
|
545
|
+
/** Lazily construct the shared Web Bot Auth verifier (one directory cache). */
|
|
546
|
+
private getAgentVerifier;
|
|
547
|
+
/**
|
|
548
|
+
* Verify a request's Web Bot Auth signature locally, deriving the request
|
|
549
|
+
* URL/authority from its metadata. Returns undefined when the request lacks
|
|
550
|
+
* the host information needed to verify (verdict is then simply absent).
|
|
551
|
+
*/
|
|
552
|
+
private computeAgentVerdict;
|
|
553
|
+
/**
|
|
554
|
+
* Verify an inbound request's Web Bot Auth signature locally (RFC 9421, tag
|
|
555
|
+
* "web-bot-auth"). Returns whether it is a cryptographically `verified`
|
|
556
|
+
* agent, an `impersonation` of a known one, an unverifiable `claimed`
|
|
557
|
+
* signature, or `none`. No network on the warm path.
|
|
558
|
+
*
|
|
559
|
+
* Accepts a WHATWG `Request` (edge/Next.js) or a `{ method, url, headers }`
|
|
560
|
+
* object (Node).
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* ```ts
|
|
564
|
+
* const verdict = await webdecoy.detectBot(request);
|
|
565
|
+
* if (verdict.status === 'impersonation') return new Response('Forbidden', { status: 403 });
|
|
566
|
+
* if (verdict.status === 'verified') console.log('verified agent:', verdict.agentName);
|
|
567
|
+
* ```
|
|
568
|
+
*/
|
|
569
|
+
detectBot(request: AgentRequestInput): Promise<AgentVerdict>;
|
|
376
570
|
/**
|
|
377
571
|
* Whether this SDK instance has filter rules that need async enrichment
|
|
378
572
|
*/
|
|
379
573
|
get hasFilterRules(): boolean;
|
|
574
|
+
/**
|
|
575
|
+
* Whether this SDK instance has Web Bot Auth rules that need async
|
|
576
|
+
* verification before evaluation.
|
|
577
|
+
*/
|
|
578
|
+
get hasAgentRules(): boolean;
|
|
380
579
|
/**
|
|
381
580
|
* Protect a request by checking it against Web Decoy's bot detection
|
|
382
581
|
*
|
|
@@ -496,6 +695,67 @@ declare class TripwireRule implements Rule {
|
|
|
496
695
|
evaluate(context: RuleContext): RuleResult;
|
|
497
696
|
}
|
|
498
697
|
|
|
698
|
+
/**
|
|
699
|
+
* Web Bot Auth rule (WebDecoy/app#323).
|
|
700
|
+
*
|
|
701
|
+
* Acts on the Web Bot Auth verdict the SDK computes before rule evaluation
|
|
702
|
+
* (`context.agent`). Its headline job is to make **impersonation deny-able in
|
|
703
|
+
* middleware**: a request forging a known agent's identity (a signature that
|
|
704
|
+
* claims a curated agent's key but fails cryptographic verification) is a
|
|
705
|
+
* tripwire-grade signal, denied by default.
|
|
706
|
+
*
|
|
707
|
+
* Verification itself is async (it may touch a directory cache), so — like the
|
|
708
|
+
* filter rules and their IP enrichment — the verdict is precomputed into the
|
|
709
|
+
* context and this rule stays synchronous.
|
|
710
|
+
*/
|
|
711
|
+
|
|
712
|
+
interface WebBotAuthConfig {
|
|
713
|
+
/**
|
|
714
|
+
* Action when a request **impersonates** a known agent (signature matched a
|
|
715
|
+
* curated key but failed verification / window). Default `'DENY'`.
|
|
716
|
+
*/
|
|
717
|
+
onImpersonation?: 'DENY' | 'THROTTLE' | 'ALLOW';
|
|
718
|
+
/**
|
|
719
|
+
* Action when a Web Bot Auth signature is present but **unverifiable**
|
|
720
|
+
* (unknown keyid, malformed). Default `'ALLOW'` — an unknown signer is not
|
|
721
|
+
* proof of abuse; leave the decision to detection/other rules. Set `'DENY'`
|
|
722
|
+
* to require that every signed agent be one you trust.
|
|
723
|
+
*/
|
|
724
|
+
onClaimed?: 'DENY' | 'THROTTLE' | 'ALLOW';
|
|
725
|
+
/**
|
|
726
|
+
* Restrict which categories of **verified** agents this rule treats as
|
|
727
|
+
* acceptable. When set, a verified agent whose category is not listed is
|
|
728
|
+
* handled per {@link onClaimed} (i.e. its signature checks out, but you
|
|
729
|
+
* don't want that kind of agent). When omitted, all verified agents pass.
|
|
730
|
+
*/
|
|
731
|
+
allowCategories?: AgentCategory[];
|
|
732
|
+
/** Log the violation but never block. Default `false`. */
|
|
733
|
+
dryRun?: boolean;
|
|
734
|
+
}
|
|
735
|
+
declare class WebBotAuthRule implements Rule {
|
|
736
|
+
readonly name = "web-bot-auth";
|
|
737
|
+
private readonly onImpersonation;
|
|
738
|
+
private readonly onClaimed;
|
|
739
|
+
private readonly allowCategories?;
|
|
740
|
+
private readonly dryRun;
|
|
741
|
+
constructor(config?: WebBotAuthConfig);
|
|
742
|
+
evaluate(context: RuleContext): RuleResult;
|
|
743
|
+
private act;
|
|
744
|
+
private allow;
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Deny requests that impersonate a verified AI agent (default), acting on the
|
|
748
|
+
* SDK's local Web Bot Auth verification.
|
|
749
|
+
*
|
|
750
|
+
* @example
|
|
751
|
+
* ```ts
|
|
752
|
+
* import { WebDecoy, webBotAuth } from '@webdecoy/node';
|
|
753
|
+
*
|
|
754
|
+
* const wd = new WebDecoy({ rules: [webBotAuth()] });
|
|
755
|
+
* ```
|
|
756
|
+
*/
|
|
757
|
+
declare function webBotAuth(config?: WebBotAuthConfig): WebBotAuthRule;
|
|
758
|
+
|
|
499
759
|
/**
|
|
500
760
|
* Honeytoken generator (F4 — deception layer)
|
|
501
761
|
*
|
|
@@ -591,6 +851,115 @@ declare function filter(config: FilterConfig): Rule;
|
|
|
591
851
|
*/
|
|
592
852
|
declare function tripwire(config?: TripwireConfig): Rule;
|
|
593
853
|
|
|
854
|
+
/**
|
|
855
|
+
* AgentVerifier — the public entry point for local Web Bot Auth verification.
|
|
856
|
+
*
|
|
857
|
+
* Wraps the cached directory client and the signature core into a single
|
|
858
|
+
* `verify(request)` call returning an {@link AgentVerdict}. Designed for the
|
|
859
|
+
* hot path of edge/Node middleware: warm verification is a header parse, one
|
|
860
|
+
* map lookup, and one WebCrypto verify — no network, well under the 5ms p95
|
|
861
|
+
* budget in the acceptance criteria.
|
|
862
|
+
*/
|
|
863
|
+
|
|
864
|
+
declare class AgentVerifier {
|
|
865
|
+
private readonly cache;
|
|
866
|
+
private readonly toleranceSec;
|
|
867
|
+
constructor(options?: AgentVerifierOptions);
|
|
868
|
+
/** Pre-fetch trusted directories so the first request verifies warm. */
|
|
869
|
+
warmup(): void;
|
|
870
|
+
/** Verify a request's Web Bot Auth signature (if any) locally. */
|
|
871
|
+
verify(request: AgentRequestInput): Promise<AgentVerdict>;
|
|
872
|
+
/** Cached-key count (diagnostics/tests). */
|
|
873
|
+
get cachedKeyCount(): number;
|
|
874
|
+
}
|
|
875
|
+
/** Convenience factory mirroring the SDK's other `create*` helpers. */
|
|
876
|
+
declare function createAgentVerifier(options?: AgentVerifierOptions): AgentVerifier;
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* RFC 9421 HTTP Message Signatures — the Web Bot Auth verification core.
|
|
880
|
+
*
|
|
881
|
+
* Verifies signatures tagged `web-bot-auth`: parse `Signature-Input` /
|
|
882
|
+
* `Signature`, rebuild the signature base for each covered-component set, and
|
|
883
|
+
* check the raw signature with WebCrypto against a key resolved by its JWK
|
|
884
|
+
* thumbprint keyid. Adapted from the WebDecoy edge validator
|
|
885
|
+
* (`edge/clearance-worker/src/web-bot-auth.ts`), generalized to resolve keys
|
|
886
|
+
* from a directory cache instead of a pushed key list.
|
|
887
|
+
*
|
|
888
|
+
* Zero dependencies, Edge-runtime safe: only `crypto.subtle`, `TextEncoder`,
|
|
889
|
+
* `atob`, and `URL` are used.
|
|
890
|
+
*/
|
|
891
|
+
/** A verification key resolved from a trusted directory, ready for WebCrypto. */
|
|
892
|
+
interface VerificationKey {
|
|
893
|
+
cryptoKey: CryptoKey;
|
|
894
|
+
/** WebCrypto verify params (e.g. `{ name: 'Ed25519' }`). */
|
|
895
|
+
verifyParams: AlgorithmIdentifier | RsaPssParams;
|
|
896
|
+
/** Human-readable algorithm label, e.g. "ed25519". */
|
|
897
|
+
algorithm: string;
|
|
898
|
+
/** Display name of the owning agent. */
|
|
899
|
+
name: string;
|
|
900
|
+
/** Category of the owning agent. */
|
|
901
|
+
category: string;
|
|
902
|
+
/** Key validity bounds in Unix seconds, if the directory published them. */
|
|
903
|
+
nbf?: number;
|
|
904
|
+
exp?: number;
|
|
905
|
+
}
|
|
906
|
+
/** Resolves a JWK-thumbprint keyid to a verification key, or undefined if unknown. */
|
|
907
|
+
type KeyResolver = (keyId: string) => Promise<VerificationKey | undefined>;
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* Cached Web Bot Auth directory client.
|
|
911
|
+
*
|
|
912
|
+
* Fetches the JWK sets of a **curated** set of trusted agent directories,
|
|
913
|
+
* imports their keys into WebCrypto, and indexes them by JWK-thumbprint keyid
|
|
914
|
+
* so signatures resolve in O(1) with zero network on the warm path.
|
|
915
|
+
*
|
|
916
|
+
* Security posture — the reason this is curated-only:
|
|
917
|
+
* a request's own `Signature-Agent` header is **never** used to choose a fetch
|
|
918
|
+
* target, so an attacker cannot make the middleware fetch an arbitrary URL
|
|
919
|
+
* (no SSRF). Only the origins in {@link AgentVerifierOptions.directories} are
|
|
920
|
+
* ever contacted. This mirrors the backend curation
|
|
921
|
+
* (`backend/internal/services/signed_agents.go`).
|
|
922
|
+
*
|
|
923
|
+
* Freshness — stale-while-revalidate: once populated, an expired cache keeps
|
|
924
|
+
* serving its keys while a background refresh runs, so verification latency is
|
|
925
|
+
* never coupled to a directory fetch. A cold cache (never populated) blocks
|
|
926
|
+
* once to fetch, then backs off briefly if every directory is unreachable so a
|
|
927
|
+
* degraded network can't be hammered per request.
|
|
928
|
+
*/
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* The default curated allowlist. These are the agents that sign production
|
|
932
|
+
* traffic today; kept in lock-step with the backend's curated list.
|
|
933
|
+
*/
|
|
934
|
+
declare const DEFAULT_SIGNED_AGENT_DIRECTORIES: SignedAgentDirectory[];
|
|
935
|
+
interface DirectoryCacheOptions {
|
|
936
|
+
directories: SignedAgentDirectory[];
|
|
937
|
+
cacheTtlMs: number;
|
|
938
|
+
fetchTimeoutMs: number;
|
|
939
|
+
debug: boolean;
|
|
940
|
+
fetchImpl: typeof fetch;
|
|
941
|
+
}
|
|
942
|
+
declare class DirectoryCache {
|
|
943
|
+
private readonly opts;
|
|
944
|
+
private keys;
|
|
945
|
+
private refreshedAt;
|
|
946
|
+
private nextColdRetryAt;
|
|
947
|
+
private inflight;
|
|
948
|
+
constructor(opts: DirectoryCacheOptions);
|
|
949
|
+
/** Resolve a keyid to a verification key, fetching/refreshing as needed. */
|
|
950
|
+
resolveKey: KeyResolver;
|
|
951
|
+
/** Kick off a fetch without blocking — call at startup to warm the cache. */
|
|
952
|
+
prime(): void;
|
|
953
|
+
/** Number of keys currently cached (diagnostics/tests). */
|
|
954
|
+
get size(): number;
|
|
955
|
+
private ensureFresh;
|
|
956
|
+
/** Re-fetch every directory. De-duplicated: concurrent callers share one run. */
|
|
957
|
+
refresh(): Promise<void>;
|
|
958
|
+
private doRefresh;
|
|
959
|
+
private fetchDirectory;
|
|
960
|
+
private debug;
|
|
961
|
+
}
|
|
962
|
+
|
|
594
963
|
/**
|
|
595
964
|
* Detection engine types.
|
|
596
965
|
*
|
|
@@ -1134,9 +1503,9 @@ declare class PoWManager {
|
|
|
1134
1503
|
/** Difficulty scaled by IP reputation and request rate (4..6). */
|
|
1135
1504
|
scaleDifficulty(siteKey: string, ip: string): number;
|
|
1136
1505
|
/** Generate and store a signed challenge. */
|
|
1137
|
-
generate(siteKey: string, ip: string, difficulty?: number): ChallengeData
|
|
1506
|
+
generate(siteKey: string, ip: string, difficulty?: number): Promise<ChallengeData>;
|
|
1138
1507
|
/** Verify a submitted solution. `signalsHash` binds it to the signals. */
|
|
1139
|
-
verify(solution: PoWSolution, siteKey: string, signalsHash?: string | null): PoWVerification
|
|
1508
|
+
verify(solution: PoWSolution, siteKey: string, signalsHash?: string | null): Promise<PoWVerification>;
|
|
1140
1509
|
}
|
|
1141
1510
|
|
|
1142
1511
|
/**
|
|
@@ -1167,9 +1536,9 @@ declare class TokenManager {
|
|
|
1167
1536
|
private readonly store;
|
|
1168
1537
|
constructor(options: TokenManagerOptions);
|
|
1169
1538
|
/** Issue a signed, IP-bound token for a passing request. */
|
|
1170
|
-
issue(ip: string, siteKey: string, score: number): string
|
|
1539
|
+
issue(ip: string, siteKey: string, score: number): Promise<string>;
|
|
1171
1540
|
/** Verify a token: signature, expiry, replay, and optional IP binding. */
|
|
1172
|
-
verify(token: string, ip?: string | null): TokenVerification
|
|
1541
|
+
verify(token: string, ip?: string | null): Promise<TokenVerification>;
|
|
1173
1542
|
}
|
|
1174
1543
|
|
|
1175
1544
|
/**
|
|
@@ -1202,18 +1571,18 @@ declare class Captcha {
|
|
|
1202
1571
|
private readonly trustedJA4Headers;
|
|
1203
1572
|
constructor(options?: CaptchaOptions);
|
|
1204
1573
|
/** Issue a PoW challenge for the client to solve (difficulty auto-scaled). */
|
|
1205
|
-
issueChallenge(siteKey: string, ip: string, difficulty?: number): ChallengeData
|
|
1574
|
+
issueChallenge(siteKey: string, ip: string, difficulty?: number): Promise<ChallengeData>;
|
|
1206
1575
|
/**
|
|
1207
1576
|
* Verify a submission: checks the signals commitment, verifies PoW, scores the
|
|
1208
1577
|
* signals, and issues a session token on success. Mirrors `runVerification`.
|
|
1209
1578
|
*/
|
|
1210
|
-
verify(input: VerifyInput): VerifyResult
|
|
1579
|
+
verify(input: VerifyInput): Promise<VerifyResult>;
|
|
1211
1580
|
/** Invisible-mode scoring — same pipeline, returns a compact result + action. */
|
|
1212
1581
|
score(input: VerifyInput & {
|
|
1213
1582
|
action?: string;
|
|
1214
|
-
}): ScoreResult
|
|
1583
|
+
}): Promise<ScoreResult>;
|
|
1215
1584
|
/** Verify a previously issued token (single-use, optionally IP-bound). */
|
|
1216
|
-
verifyToken(token: string, ip?: string | null): TokenVerification
|
|
1585
|
+
verifyToken(token: string, ip?: string | null): Promise<TokenVerification>;
|
|
1217
1586
|
}
|
|
1218
1587
|
|
|
1219
1588
|
/**
|
|
@@ -1272,4 +1641,4 @@ declare function createCaptchaEndpoints(options?: CaptchaEndpointsOptions): {
|
|
|
1272
1641
|
};
|
|
1273
1642
|
type CaptchaEndpoints = ReturnType<typeof createCaptchaEndpoints>;
|
|
1274
1643
|
|
|
1275
|
-
export { type BehavioralSignals, Captcha, type CaptchaEndpoints, type CaptchaEndpointsOptions, type CaptchaHttpResponse, type CaptchaOptions, type CaptchaRequest, type CategoryScores, type ChallengeData, type ChallengeStore, DEFAULT_TRIPWIRE_PATHS, DEFAULT_WEIGHTS, type Detection, type DetectionContext, DetectionEngine, type DetectionEngineOptions, type EnvironmentalSignals, type FilterConfig, FilterRule, type FingerprintStore, type FormAnalysisSignals, type Honeytoken, type HoneytokenOptions, type IPEnrichmentData, InMemoryChallengeStore, InMemoryFingerprintStore, InMemoryRateLimiter, InMemoryTokenStore, type LocalAnalysis, PoWManager, type PoWManagerOptions, type PoWOutcome, type PoWSolution, type PoWVerification, type ProtectOptions, type ProtectResult, type RateLimitConfig, RateLimitRule, type RateLimiter, type Recommendation, type RequestMetadata, type Rule, type RuleContext, RuleEngine, type RuleEngineResult, type RuleResult, type SDKDetectionRequest, type SDKDetectionResponse, type ScoreResult, type Signals, type StoredChallenge, type TLSInfo, type TemporalSignals, type TextareaKeyboardStats, TokenManager, type TokenManagerOptions, type TokenStore, type TokenVerification, type TripwireConfig, TripwireRule, type Verdict, type VerifyInput, type VerifyResult, type ViolationEvent, WebDecoy, type WebDecoyConfig, calculateCategoryScores, calculateFinalScore, createCaptchaEndpoints, filter, honeytoken, isDatacenterIP, isMobileUA, parseUserAgent, rateLimit, recommend, resolveSecret, tripwire };
|
|
1644
|
+
export { type AgentCategory, type AgentRequestInput, type AgentStatus, type AgentVerdict, AgentVerifier, type AgentVerifierOptions, type BehavioralSignals, Captcha, type CaptchaEndpoints, type CaptchaEndpointsOptions, type CaptchaHttpResponse, type CaptchaOptions, type CaptchaRequest, type CategoryScores, type ChallengeData, type ChallengeStore, DEFAULT_SIGNED_AGENT_DIRECTORIES, DEFAULT_TRIPWIRE_PATHS, DEFAULT_WEIGHTS, type Detection, type DetectionContext, DetectionEngine, type DetectionEngineOptions, DirectoryCache, type EnvironmentalSignals, type FilterConfig, FilterRule, type FingerprintStore, type FormAnalysisSignals, type Honeytoken, type HoneytokenOptions, type IPEnrichmentData, InMemoryChallengeStore, InMemoryFingerprintStore, InMemoryRateLimiter, InMemoryTokenStore, type LocalAnalysis, PoWManager, type PoWManagerOptions, type PoWOutcome, type PoWSolution, type PoWVerification, type ProtectOptions, type ProtectResult, type RateLimitConfig, RateLimitRule, type RateLimiter, type Recommendation, type RequestMetadata, type Rule, type RuleContext, RuleEngine, type RuleEngineResult, type RuleResult, type SDKDetectionRequest, type SDKDetectionResponse, type ScoreResult, type Signals, type SignedAgentDirectory, type StoredChallenge, type TLSInfo, type TemporalSignals, type TextareaKeyboardStats, TokenManager, type TokenManagerOptions, type TokenStore, type TokenVerification, type TripwireConfig, TripwireRule, type Verdict, type VerifyInput, type VerifyResult, type ViolationEvent, type WebBotAuthConfig, WebBotAuthRule, WebDecoy, type WebDecoyConfig, calculateCategoryScores, calculateFinalScore, createAgentVerifier, createCaptchaEndpoints, filter, honeytoken, isDatacenterIP, isMobileUA, parseUserAgent, rateLimit, recommend, resolveSecret, tripwire, webBotAuth };
|