@webdecoy/node 0.13.0 → 0.15.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 +1 -1
- package/dist/{chunk-CIRFOOMU.mjs → chunk-T6MX62T5.mjs} +80 -9
- package/dist/index.d.mts +162 -89
- package/dist/index.d.ts +162 -89
- package/dist/index.js +160 -53
- package/dist/index.mjs +77 -45
- package/dist/{sdk-DjeCBrHu.d.mts → sdk-qUjMf8ZX.d.mts} +61 -4
- package/dist/{sdk-DjeCBrHu.d.ts → sdk-qUjMf8ZX.d.ts} +61 -4
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +80 -9
- package/dist/testing.mjs +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -54,7 +54,7 @@ import {
|
|
|
54
54
|
tripwire,
|
|
55
55
|
upstashRateLimitStore,
|
|
56
56
|
webBotAuth
|
|
57
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-T6MX62T5.mjs";
|
|
58
58
|
|
|
59
59
|
// src/client-ip.ts
|
|
60
60
|
var IPV4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
|
|
@@ -184,11 +184,12 @@ function resolveClientIp(options) {
|
|
|
184
184
|
return normalizeIp(readHeader(headers, "cf-connecting-ip")) ?? peer;
|
|
185
185
|
}
|
|
186
186
|
const chain = forwardedChain(headers);
|
|
187
|
+
const singleHeaderFallback = () => normalizeIp(readHeader(headers, "x-real-ip")) ?? normalizeIp(readHeader(headers, "x-vercel-forwarded-for")?.split(",").pop()) ?? void 0;
|
|
187
188
|
if (typeof trustProxy === "number") {
|
|
188
189
|
if (!Number.isInteger(trustProxy) || trustProxy < 0) return peer;
|
|
189
190
|
const index = chain.length - trustProxy;
|
|
190
|
-
if (index < 0 || index >= chain.length) return peer;
|
|
191
|
-
return chain[index] ?? peer;
|
|
191
|
+
if (index < 0 || index >= chain.length) return singleHeaderFallback() ?? peer;
|
|
192
|
+
return chain[index] ?? singleHeaderFallback() ?? peer;
|
|
192
193
|
}
|
|
193
194
|
const full = peer ? [...chain, peer] : [...chain];
|
|
194
195
|
for (let i = full.length - 1; i >= 0; i--) {
|
|
@@ -196,7 +197,7 @@ function resolveClientIp(options) {
|
|
|
196
197
|
if (candidate === null) return peer;
|
|
197
198
|
if (!trustProxy.some((range) => ipInCidr(candidate, range))) return candidate;
|
|
198
199
|
}
|
|
199
|
-
return full[0] ?? void 0 ?? peer;
|
|
200
|
+
return full[0] ?? void 0 ?? singleHeaderFallback() ?? peer;
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
// src/client-signals.ts
|
|
@@ -308,41 +309,72 @@ function clientSignals(config) {
|
|
|
308
309
|
return new ClientSignalRule(config);
|
|
309
310
|
}
|
|
310
311
|
|
|
311
|
-
// src/
|
|
312
|
-
function
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
312
|
+
// src/adapter-core.ts
|
|
313
|
+
function shouldSkipPath(path, patterns) {
|
|
314
|
+
if (!patterns || patterns.length === 0) return false;
|
|
315
|
+
return patterns.some(
|
|
316
|
+
(pattern) => typeof pattern === "string" ? path === pattern || path.startsWith(pattern) : pattern.test(path)
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
function ruleBlockResponse(decision) {
|
|
320
|
+
const rr = decision.ruleResult;
|
|
321
|
+
if (decision.allowed || !rr) return null;
|
|
322
|
+
if (rr.action === "THROTTLE") {
|
|
323
|
+
const retryAfter = Number(rr.metadata?.retryAfter ?? 60);
|
|
324
|
+
return {
|
|
325
|
+
status: 429,
|
|
326
|
+
headers: { "Retry-After": String(retryAfter) },
|
|
327
|
+
body: {
|
|
318
328
|
error: "Too Many Requests",
|
|
319
|
-
message:
|
|
320
|
-
retry_after: retryAfter
|
|
321
|
-
detection_id: decision.id
|
|
322
|
-
}),
|
|
323
|
-
{
|
|
324
|
-
status: 429,
|
|
325
|
-
headers: {
|
|
326
|
-
"content-type": "application/json",
|
|
327
|
-
"retry-after": String(retryAfter)
|
|
328
|
-
}
|
|
329
|
+
message: rr.reason || "Rate limit exceeded",
|
|
330
|
+
retry_after: retryAfter
|
|
329
331
|
}
|
|
330
|
-
|
|
332
|
+
};
|
|
331
333
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
334
|
+
if (rr.action === "DENY") {
|
|
335
|
+
return {
|
|
336
|
+
status: 403,
|
|
337
|
+
headers: {},
|
|
338
|
+
body: {
|
|
339
|
+
error: "Forbidden",
|
|
340
|
+
message: rr.reason || "Access denied by rule",
|
|
341
|
+
rule: rr.rule
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
return null;
|
|
340
346
|
}
|
|
341
|
-
function
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
);
|
|
347
|
+
function armSiteHoneytoken(sdk, options) {
|
|
348
|
+
let token = null;
|
|
349
|
+
void deriveAndArm(sdk, options).then((t) => {
|
|
350
|
+
token = t;
|
|
351
|
+
});
|
|
352
|
+
return () => token;
|
|
353
|
+
}
|
|
354
|
+
async function deriveAndArm(sdk, options) {
|
|
355
|
+
const enabled = (options.enabled ?? true) && Boolean(options.apiKey);
|
|
356
|
+
if (!enabled) return null;
|
|
357
|
+
try {
|
|
358
|
+
const token = await siteHoneytoken({ secret: options.apiKey });
|
|
359
|
+
sdk.addRule(tripwire({ paths: token.activePaths, includeDefaults: false }));
|
|
360
|
+
return token;
|
|
361
|
+
} catch (error) {
|
|
362
|
+
options.onError?.(error);
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/fetch-guard.ts
|
|
368
|
+
function defaultBlocked(_request, decision) {
|
|
369
|
+
const block = ruleBlockResponse(decision) ?? {
|
|
370
|
+
status: 403,
|
|
371
|
+
headers: {},
|
|
372
|
+
body: { error: "Forbidden", message: "Access denied by Web Decoy protection" }
|
|
373
|
+
};
|
|
374
|
+
return new Response(JSON.stringify({ ...block.body, detection_id: decision.id }), {
|
|
375
|
+
status: block.status,
|
|
376
|
+
headers: { "content-type": "application/json", ...block.headers }
|
|
377
|
+
});
|
|
346
378
|
}
|
|
347
379
|
function headerRecord(headers) {
|
|
348
380
|
const out = {};
|
|
@@ -355,14 +387,10 @@ function createFetchGuard(options = {}) {
|
|
|
355
387
|
const sdk = new WebDecoy(options);
|
|
356
388
|
const mode = options.mode ?? "monitor";
|
|
357
389
|
const onBlocked = options.onBlocked ?? defaultBlocked;
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
sdk.addRule(tripwire({ paths: t.activePaths, includeDefaults: false }));
|
|
363
|
-
}).catch(() => {
|
|
364
|
-
});
|
|
365
|
-
}
|
|
390
|
+
const getToken = armSiteHoneytoken(sdk, {
|
|
391
|
+
apiKey: options.apiKey,
|
|
392
|
+
enabled: options.honeytoken
|
|
393
|
+
});
|
|
366
394
|
function resolveIP(request, peer) {
|
|
367
395
|
if (options.getIP) return options.getIP(request);
|
|
368
396
|
return resolveClientIp({
|
|
@@ -374,7 +402,7 @@ function createFetchGuard(options = {}) {
|
|
|
374
402
|
return {
|
|
375
403
|
sdk,
|
|
376
404
|
skips(pathname) {
|
|
377
|
-
return
|
|
405
|
+
return shouldSkipPath(pathname, options.skipPaths);
|
|
378
406
|
},
|
|
379
407
|
async check(request, peer) {
|
|
380
408
|
const url = new URL(request.url);
|
|
@@ -396,7 +424,7 @@ function createFetchGuard(options = {}) {
|
|
|
396
424
|
return { decision, response: await onBlocked(request, decision) };
|
|
397
425
|
},
|
|
398
426
|
async decorate(response) {
|
|
399
|
-
const current =
|
|
427
|
+
const current = getToken();
|
|
400
428
|
if (!current) return response;
|
|
401
429
|
if (!isInjectableHtml(response.headers.get("content-type"))) return response;
|
|
402
430
|
if (response.bodyUsed) return response;
|
|
@@ -2428,6 +2456,7 @@ export {
|
|
|
2428
2456
|
UpstashRateLimitStore,
|
|
2429
2457
|
WebBotAuthRule,
|
|
2430
2458
|
WebDecoy,
|
|
2459
|
+
armSiteHoneytoken,
|
|
2431
2460
|
attackSignatures,
|
|
2432
2461
|
botPolicy,
|
|
2433
2462
|
bots,
|
|
@@ -2439,6 +2468,7 @@ export {
|
|
|
2439
2468
|
createAgentVerifier,
|
|
2440
2469
|
createCaptchaEndpoints,
|
|
2441
2470
|
createFetchGuard,
|
|
2471
|
+
deriveAndArm,
|
|
2442
2472
|
deriveKey,
|
|
2443
2473
|
filter,
|
|
2444
2474
|
fromPino,
|
|
@@ -2459,6 +2489,8 @@ export {
|
|
|
2459
2489
|
recommend,
|
|
2460
2490
|
resolveClientIp,
|
|
2461
2491
|
resolveSecret,
|
|
2492
|
+
ruleBlockResponse,
|
|
2493
|
+
shouldSkipPath,
|
|
2462
2494
|
silentLogger,
|
|
2463
2495
|
siteHoneytoken,
|
|
2464
2496
|
tripwire,
|
|
@@ -310,7 +310,7 @@ declare function readEdgeVerdict(headers: Record<string, string> | undefined): E
|
|
|
310
310
|
* agents share User-Agent substrings, so sorting this array changes how real
|
|
311
311
|
* traffic is classified.
|
|
312
312
|
*
|
|
313
|
-
*
|
|
313
|
+
* 175 agents across 15 categories.
|
|
314
314
|
*/
|
|
315
315
|
/**
|
|
316
316
|
* Classification categories, mirroring `agents.Category` in Go.
|
|
@@ -551,6 +551,45 @@ declare function fromPino(pino: {
|
|
|
551
551
|
error(fields: LogFields, message: string): void;
|
|
552
552
|
}): Logger;
|
|
553
553
|
|
|
554
|
+
/**
|
|
555
|
+
* OpenTelemetry spans, without depending on OpenTelemetry.
|
|
556
|
+
*
|
|
557
|
+
* WHY INJECTED RATHER THAN IMPORTED
|
|
558
|
+
*
|
|
559
|
+
* An optional peer dependency was the obvious route and the wrong one. This
|
|
560
|
+
* package is dependency-free and passes an edge-compatibility gate, and most of
|
|
561
|
+
* the runtimes it targets — Workers, Vercel Edge — are exactly where a stray
|
|
562
|
+
* transitive import hurts. A conditional `import('@opentelemetry/api')` also
|
|
563
|
+
* bundles badly: the bundler either resolves it, adding weight for the majority
|
|
564
|
+
* who do not use it, or fails on a module that is legitimately absent.
|
|
565
|
+
*
|
|
566
|
+
* So the tracer is passed in. The interface below is a structural subset of
|
|
567
|
+
* OpenTelemetry's, which means `trace.getTracer('webdecoy')` satisfies it
|
|
568
|
+
* directly with no adapter:
|
|
569
|
+
*
|
|
570
|
+
* ```ts
|
|
571
|
+
* import { trace } from '@opentelemetry/api';
|
|
572
|
+
* new WebDecoy({ tracer: trace.getTracer('webdecoy') });
|
|
573
|
+
* ```
|
|
574
|
+
*
|
|
575
|
+
* An app that passes nothing gets no spans, no dependency, and no behaviour
|
|
576
|
+
* change — which is the majority, and they should not pay for this.
|
|
577
|
+
*/
|
|
578
|
+
/** A span, structurally compatible with OpenTelemetry's. */
|
|
579
|
+
interface Span {
|
|
580
|
+
setAttribute(key: string, value: string | number | boolean): unknown;
|
|
581
|
+
recordException?(error: unknown): unknown;
|
|
582
|
+
setStatus?(status: {
|
|
583
|
+
code: number;
|
|
584
|
+
message?: string;
|
|
585
|
+
}): unknown;
|
|
586
|
+
end(): unknown;
|
|
587
|
+
}
|
|
588
|
+
/** A tracer, structurally compatible with OpenTelemetry's. */
|
|
589
|
+
interface Tracer {
|
|
590
|
+
startSpan(name: string): Span;
|
|
591
|
+
}
|
|
592
|
+
|
|
554
593
|
/**
|
|
555
594
|
* Web Decoy SDK Types
|
|
556
595
|
* Based on the ingest service API contract
|
|
@@ -567,8 +606,10 @@ interface WebDecoyConfig {
|
|
|
567
606
|
*/
|
|
568
607
|
apiKey?: string;
|
|
569
608
|
/**
|
|
570
|
-
* API URL for the Web Decoy ingest service
|
|
571
|
-
*
|
|
609
|
+
* API URL for the Web Decoy ingest service. Server-to-server traffic
|
|
610
|
+
* fronts through Cloudflare at in.webdecoy.com; only the browser tag
|
|
611
|
+
* stays on the direct hostname.
|
|
612
|
+
* @default 'https://in.webdecoy.com'
|
|
572
613
|
*/
|
|
573
614
|
apiUrl?: string;
|
|
574
615
|
/**
|
|
@@ -643,6 +684,20 @@ interface WebDecoyConfig {
|
|
|
643
684
|
* silently drops every structured field.
|
|
644
685
|
*/
|
|
645
686
|
logger?: Logger;
|
|
687
|
+
/**
|
|
688
|
+
* An OpenTelemetry tracer, if you run one.
|
|
689
|
+
*
|
|
690
|
+
* Injected rather than imported so this package stays dependency-free and
|
|
691
|
+
* edge-safe. The interface is a structural subset of OpenTelemetry's, so
|
|
692
|
+
* `trace.getTracer('webdecoy')` works directly:
|
|
693
|
+
*
|
|
694
|
+
* ```ts
|
|
695
|
+
* new WebDecoy({ tracer: trace.getTracer('webdecoy') });
|
|
696
|
+
* ```
|
|
697
|
+
*
|
|
698
|
+
* Omit it and there are no spans, no dependency and no behaviour change.
|
|
699
|
+
*/
|
|
700
|
+
tracer?: Tracer;
|
|
646
701
|
}
|
|
647
702
|
/**
|
|
648
703
|
* TLS connection information from the request
|
|
@@ -1226,6 +1281,8 @@ declare class WebDecoy {
|
|
|
1226
1281
|
private readonly characteristics;
|
|
1227
1282
|
/** Where diagnostics go. Never console directly — see logger.ts. */
|
|
1228
1283
|
readonly log: Logger;
|
|
1284
|
+
/** Optional OpenTelemetry tracer. Absent means no spans and no cost. */
|
|
1285
|
+
private readonly tracer?;
|
|
1229
1286
|
private readonly decisionCache;
|
|
1230
1287
|
constructor(config: WebDecoyConfig);
|
|
1231
1288
|
/**
|
|
@@ -1344,4 +1401,4 @@ declare class WebDecoy {
|
|
|
1344
1401
|
destroy(): Promise<void>;
|
|
1345
1402
|
}
|
|
1346
1403
|
|
|
1347
|
-
export {
|
|
1404
|
+
export { consoleLogger as $, type AgentCategory as A, type BotRuleConfig as B, type Characteristic as C, Decision as D, EDGE_CLASS_HEADER as E, type FilterConfig as F, type LogFields as G, type Logger as H, type IPEnrichmentData as I, type RequestMetadata as J, type RuleOutcome as K, type LocalAnalysis as L, MemoryRateLimitStore as M, type RuleState as N, type SDKDetectionRequest as O, type ProtectResult as P, type SDKDetectionResponse as Q, type Rule as R, type SignedAgentDirectory as S, type TripwireConfig as T, type Span as U, type SyncRateLimitStore as V, WebDecoy as W, type TLSInfo as X, type Tracer as Y, type ViolationEvent as Z, classifyUserAgent as _, type RuleContext as a, deriveKey as a0, fromPino as a1, matchUserAgent as a2, newDecisionId as a3, readEdgeVerdict as a4, silentLogger as a5, type RuleResult as b, type RuleEngineResult as c, type RateLimitConfig as d, type BotAgent as e, type BotCategory as f, type RateLimitStore as g, type RateLimitConsume as h, type RateLimitOutcome as i, type WebDecoyConfig as j, type ProtectOptions as k, type AgentVerifierOptions as l, type AgentRequestInput as m, type AgentVerdict as n, type AgentStatus as o, BOT_CATEGORIES as p, BOT_REGISTRY as q, type BotVerdict as r, type Conclusion as s, DEFAULT_CHARACTERISTICS as t, DecisionCache as u, type DecisionCacheOptions as v, type DecisionInit as w, EDGE_CLEARANCE_HEADER as x, type EdgeClass as y, type EdgeVerdict as z };
|
|
@@ -310,7 +310,7 @@ declare function readEdgeVerdict(headers: Record<string, string> | undefined): E
|
|
|
310
310
|
* agents share User-Agent substrings, so sorting this array changes how real
|
|
311
311
|
* traffic is classified.
|
|
312
312
|
*
|
|
313
|
-
*
|
|
313
|
+
* 175 agents across 15 categories.
|
|
314
314
|
*/
|
|
315
315
|
/**
|
|
316
316
|
* Classification categories, mirroring `agents.Category` in Go.
|
|
@@ -551,6 +551,45 @@ declare function fromPino(pino: {
|
|
|
551
551
|
error(fields: LogFields, message: string): void;
|
|
552
552
|
}): Logger;
|
|
553
553
|
|
|
554
|
+
/**
|
|
555
|
+
* OpenTelemetry spans, without depending on OpenTelemetry.
|
|
556
|
+
*
|
|
557
|
+
* WHY INJECTED RATHER THAN IMPORTED
|
|
558
|
+
*
|
|
559
|
+
* An optional peer dependency was the obvious route and the wrong one. This
|
|
560
|
+
* package is dependency-free and passes an edge-compatibility gate, and most of
|
|
561
|
+
* the runtimes it targets — Workers, Vercel Edge — are exactly where a stray
|
|
562
|
+
* transitive import hurts. A conditional `import('@opentelemetry/api')` also
|
|
563
|
+
* bundles badly: the bundler either resolves it, adding weight for the majority
|
|
564
|
+
* who do not use it, or fails on a module that is legitimately absent.
|
|
565
|
+
*
|
|
566
|
+
* So the tracer is passed in. The interface below is a structural subset of
|
|
567
|
+
* OpenTelemetry's, which means `trace.getTracer('webdecoy')` satisfies it
|
|
568
|
+
* directly with no adapter:
|
|
569
|
+
*
|
|
570
|
+
* ```ts
|
|
571
|
+
* import { trace } from '@opentelemetry/api';
|
|
572
|
+
* new WebDecoy({ tracer: trace.getTracer('webdecoy') });
|
|
573
|
+
* ```
|
|
574
|
+
*
|
|
575
|
+
* An app that passes nothing gets no spans, no dependency, and no behaviour
|
|
576
|
+
* change — which is the majority, and they should not pay for this.
|
|
577
|
+
*/
|
|
578
|
+
/** A span, structurally compatible with OpenTelemetry's. */
|
|
579
|
+
interface Span {
|
|
580
|
+
setAttribute(key: string, value: string | number | boolean): unknown;
|
|
581
|
+
recordException?(error: unknown): unknown;
|
|
582
|
+
setStatus?(status: {
|
|
583
|
+
code: number;
|
|
584
|
+
message?: string;
|
|
585
|
+
}): unknown;
|
|
586
|
+
end(): unknown;
|
|
587
|
+
}
|
|
588
|
+
/** A tracer, structurally compatible with OpenTelemetry's. */
|
|
589
|
+
interface Tracer {
|
|
590
|
+
startSpan(name: string): Span;
|
|
591
|
+
}
|
|
592
|
+
|
|
554
593
|
/**
|
|
555
594
|
* Web Decoy SDK Types
|
|
556
595
|
* Based on the ingest service API contract
|
|
@@ -567,8 +606,10 @@ interface WebDecoyConfig {
|
|
|
567
606
|
*/
|
|
568
607
|
apiKey?: string;
|
|
569
608
|
/**
|
|
570
|
-
* API URL for the Web Decoy ingest service
|
|
571
|
-
*
|
|
609
|
+
* API URL for the Web Decoy ingest service. Server-to-server traffic
|
|
610
|
+
* fronts through Cloudflare at in.webdecoy.com; only the browser tag
|
|
611
|
+
* stays on the direct hostname.
|
|
612
|
+
* @default 'https://in.webdecoy.com'
|
|
572
613
|
*/
|
|
573
614
|
apiUrl?: string;
|
|
574
615
|
/**
|
|
@@ -643,6 +684,20 @@ interface WebDecoyConfig {
|
|
|
643
684
|
* silently drops every structured field.
|
|
644
685
|
*/
|
|
645
686
|
logger?: Logger;
|
|
687
|
+
/**
|
|
688
|
+
* An OpenTelemetry tracer, if you run one.
|
|
689
|
+
*
|
|
690
|
+
* Injected rather than imported so this package stays dependency-free and
|
|
691
|
+
* edge-safe. The interface is a structural subset of OpenTelemetry's, so
|
|
692
|
+
* `trace.getTracer('webdecoy')` works directly:
|
|
693
|
+
*
|
|
694
|
+
* ```ts
|
|
695
|
+
* new WebDecoy({ tracer: trace.getTracer('webdecoy') });
|
|
696
|
+
* ```
|
|
697
|
+
*
|
|
698
|
+
* Omit it and there are no spans, no dependency and no behaviour change.
|
|
699
|
+
*/
|
|
700
|
+
tracer?: Tracer;
|
|
646
701
|
}
|
|
647
702
|
/**
|
|
648
703
|
* TLS connection information from the request
|
|
@@ -1226,6 +1281,8 @@ declare class WebDecoy {
|
|
|
1226
1281
|
private readonly characteristics;
|
|
1227
1282
|
/** Where diagnostics go. Never console directly — see logger.ts. */
|
|
1228
1283
|
readonly log: Logger;
|
|
1284
|
+
/** Optional OpenTelemetry tracer. Absent means no spans and no cost. */
|
|
1285
|
+
private readonly tracer?;
|
|
1229
1286
|
private readonly decisionCache;
|
|
1230
1287
|
constructor(config: WebDecoyConfig);
|
|
1231
1288
|
/**
|
|
@@ -1344,4 +1401,4 @@ declare class WebDecoy {
|
|
|
1344
1401
|
destroy(): Promise<void>;
|
|
1345
1402
|
}
|
|
1346
1403
|
|
|
1347
|
-
export {
|
|
1404
|
+
export { consoleLogger as $, type AgentCategory as A, type BotRuleConfig as B, type Characteristic as C, Decision as D, EDGE_CLASS_HEADER as E, type FilterConfig as F, type LogFields as G, type Logger as H, type IPEnrichmentData as I, type RequestMetadata as J, type RuleOutcome as K, type LocalAnalysis as L, MemoryRateLimitStore as M, type RuleState as N, type SDKDetectionRequest as O, type ProtectResult as P, type SDKDetectionResponse as Q, type Rule as R, type SignedAgentDirectory as S, type TripwireConfig as T, type Span as U, type SyncRateLimitStore as V, WebDecoy as W, type TLSInfo as X, type Tracer as Y, type ViolationEvent as Z, classifyUserAgent as _, type RuleContext as a, deriveKey as a0, fromPino as a1, matchUserAgent as a2, newDecisionId as a3, readEdgeVerdict as a4, silentLogger as a5, type RuleResult as b, type RuleEngineResult as c, type RateLimitConfig as d, type BotAgent as e, type BotCategory as f, type RateLimitStore as g, type RateLimitConsume as h, type RateLimitOutcome as i, type WebDecoyConfig as j, type ProtectOptions as k, type AgentVerifierOptions as l, type AgentRequestInput as m, type AgentVerdict as n, type AgentStatus as o, BOT_CATEGORIES as p, BOT_REGISTRY as q, type BotVerdict as r, type Conclusion as s, DEFAULT_CHARACTERISTICS as t, DecisionCache as u, type DecisionCacheOptions as v, type DecisionInit as w, EDGE_CLEARANCE_HEADER as x, type EdgeClass as y, type EdgeVerdict as z };
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { j as WebDecoyConfig, J as RequestMetadata, W as WebDecoy, P as ProtectResult, N as RuleState } from './sdk-qUjMf8ZX.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Testing utilities, for the application's test suite rather than ours.
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { j as WebDecoyConfig, J as RequestMetadata, W as WebDecoy, P as ProtectResult, N as RuleState } from './sdk-qUjMf8ZX.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Testing utilities, for the application's test suite rather than ours.
|
package/dist/testing.js
CHANGED
|
@@ -263,11 +263,8 @@ function calculateLocalScore(suspiciousHeaders, missingSecCHUA, datacenterIP) {
|
|
|
263
263
|
if (datacenterIP) score += 40;
|
|
264
264
|
return Math.min(score, 100);
|
|
265
265
|
}
|
|
266
|
-
function needsVerification(
|
|
267
|
-
|
|
268
|
-
return true;
|
|
269
|
-
}
|
|
270
|
-
return localScore >= 30;
|
|
266
|
+
function needsVerification(suspiciousHeaders, hasTLSInfo) {
|
|
267
|
+
return hasTLSInfo || suspiciousHeaders;
|
|
271
268
|
}
|
|
272
269
|
function buildFlags(suspiciousHeaders, missingSecCHUA, datacenterIP, metadata) {
|
|
273
270
|
const flags = [];
|
|
@@ -295,7 +292,7 @@ function analyzeRequest(metadata) {
|
|
|
295
292
|
const datacenterIP = isDatacenterIP(metadata.ip);
|
|
296
293
|
const localScore = calculateLocalScore(suspiciousHeaders, missingSecCHUA, datacenterIP);
|
|
297
294
|
const hasTLSInfo = Boolean(metadata.tls_info);
|
|
298
|
-
const needsVerify = needsVerification(
|
|
295
|
+
const needsVerify = needsVerification(suspiciousHeaders, hasTLSInfo);
|
|
299
296
|
const flags = buildFlags(suspiciousHeaders, missingSecCHUA, datacenterIP, metadata);
|
|
300
297
|
return {
|
|
301
298
|
suspicious_headers: suspiciousHeaders,
|
|
@@ -450,6 +447,7 @@ var TripwireRule = class {
|
|
|
450
447
|
|
|
451
448
|
// src/bots/registry.generated.ts
|
|
452
449
|
var BOT_REGISTRY = [
|
|
450
|
+
{ id: "reflectionbot", name: "Reflectionbot", category: "training_crawler", organization: "Reflection AI", baseScore: 70, respectsRobots: true, uaPatterns: ["reflectionbot"] },
|
|
453
451
|
{ id: "gptbot", name: "GPTBot", category: "training_crawler", organization: "OpenAI", baseScore: 85, respectsRobots: true, uaPatterns: ["gptbot"] },
|
|
454
452
|
{ id: "chatgpt-user", name: "ChatGPT-User", category: "training_crawler", organization: "OpenAI", baseScore: 85, respectsRobots: true, uaPatterns: ["chatgpt-user", "chatgpt"] },
|
|
455
453
|
{ id: "oai-searchbot", name: "OAI-SearchBot", category: "training_crawler", organization: "OpenAI", baseScore: 80, respectsRobots: true, uaPatterns: ["oai-searchbot"] },
|
|
@@ -478,6 +476,10 @@ var BOT_REGISTRY = [
|
|
|
478
476
|
{ id: "velenpublicwebcrawler", name: "VelenPublicWebCrawler", category: "training_crawler", organization: "Velen", baseScore: 70, respectsRobots: false, uaPatterns: ["velenpublicwebcrawler"] },
|
|
479
477
|
{ id: "isscyberriskcrawler", name: "ISSCyberRiskCrawler", category: "training_crawler", organization: "ISS", baseScore: 65, respectsRobots: false, uaPatterns: ["isscyberriskcrawler"] },
|
|
480
478
|
{ id: "friendlycrawler", name: "FriendlyCrawler", category: "training_crawler", organization: "Unknown", baseScore: 65, respectsRobots: true, uaPatterns: ["friendlycrawler"] },
|
|
479
|
+
{ id: "duckassistbot", name: "DuckAssistBot", category: "ai_search_crawler", organization: "DuckDuckGo", baseScore: 65, respectsRobots: true, uaPatterns: ["duckassistbot"] },
|
|
480
|
+
{ id: "sofyabot", name: "SofyaBot", category: "ai_search_crawler", organization: "Sofya", baseScore: 65, respectsRobots: true, uaPatterns: ["sofyabot"] },
|
|
481
|
+
{ id: "xai-searchbot", name: "xAI-SearchBot", category: "ai_search_crawler", organization: "xAI", baseScore: 70, respectsRobots: true, uaPatterns: ["xai-searchbot"] },
|
|
482
|
+
{ id: "linkupbot", name: "LinkupBot", category: "ai_search_crawler", organization: "Linkup", baseScore: 65, respectsRobots: true, uaPatterns: ["linkupbot"] },
|
|
481
483
|
{ id: "searchgpt", name: "SearchGPT", category: "ai_search_crawler", organization: "OpenAI", baseScore: 75, respectsRobots: true, uaPatterns: ["searchgpt"] },
|
|
482
484
|
{ id: "phind", name: "Phind", category: "ai_search_crawler", organization: "Phind", baseScore: 70, respectsRobots: true, uaPatterns: ["phind"] },
|
|
483
485
|
{ id: "kagi", name: "Kagi", category: "ai_search_crawler", organization: "Kagi", baseScore: 65, respectsRobots: true, uaPatterns: ["kagi"] },
|
|
@@ -494,6 +496,7 @@ var BOT_REGISTRY = [
|
|
|
494
496
|
{ id: "browser-use", name: "Browser-Use", category: "ai_agent", organization: "Open Source", baseScore: 70, respectsRobots: false, uaPatterns: ["browser-use"] },
|
|
495
497
|
{ id: "stagehand", name: "Stagehand", category: "ai_agent", organization: "Browserbase", baseScore: 70, respectsRobots: false, uaPatterns: ["stagehand"] },
|
|
496
498
|
{ id: "multion", name: "MultiOn", category: "ai_agent", organization: "MultiOn", baseScore: 70, respectsRobots: false, uaPatterns: ["multion"] },
|
|
499
|
+
{ id: "iboubot", name: "IbouBot", category: "search_crawler", organization: "Ibou", baseScore: 30, respectsRobots: true, uaPatterns: ["iboubot"] },
|
|
497
500
|
{ id: "googlebot", name: "Googlebot", category: "search_crawler", organization: "Google", baseScore: 30, respectsRobots: true, uaPatterns: ["googlebot"] },
|
|
498
501
|
{ id: "bingbot", name: "Bingbot", category: "search_crawler", organization: "Microsoft", baseScore: 30, respectsRobots: true, uaPatterns: ["bingbot"] },
|
|
499
502
|
{ id: "yandexbot", name: "YandexBot", category: "search_crawler", organization: "Yandex", baseScore: 35, respectsRobots: true, uaPatterns: ["yandexbot"] },
|
|
@@ -1507,6 +1510,43 @@ function resolveLogger(provided, debug) {
|
|
|
1507
1510
|
return provided ?? consoleLogger(debug);
|
|
1508
1511
|
}
|
|
1509
1512
|
|
|
1513
|
+
// src/tracing.ts
|
|
1514
|
+
var STATUS_ERROR = 2;
|
|
1515
|
+
var NOOP_SPAN = {
|
|
1516
|
+
setAttribute: () => void 0,
|
|
1517
|
+
end: () => void 0
|
|
1518
|
+
};
|
|
1519
|
+
function startSpan(tracer, name) {
|
|
1520
|
+
if (!tracer) return NOOP_SPAN;
|
|
1521
|
+
try {
|
|
1522
|
+
return tracer.startSpan(name) ?? NOOP_SPAN;
|
|
1523
|
+
} catch {
|
|
1524
|
+
return NOOP_SPAN;
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
function setAttribute(span, key, value) {
|
|
1528
|
+
try {
|
|
1529
|
+
span.setAttribute(key, value);
|
|
1530
|
+
} catch {
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
function recordError(span, error) {
|
|
1534
|
+
try {
|
|
1535
|
+
span.recordException?.(error);
|
|
1536
|
+
span.setStatus?.({
|
|
1537
|
+
code: STATUS_ERROR,
|
|
1538
|
+
message: error instanceof Error ? error.message : String(error)
|
|
1539
|
+
});
|
|
1540
|
+
} catch {
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
function endSpan(span) {
|
|
1544
|
+
try {
|
|
1545
|
+
span.end();
|
|
1546
|
+
} catch {
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1510
1550
|
// src/decision.ts
|
|
1511
1551
|
function newDecisionId() {
|
|
1512
1552
|
return `dec_${randomHex(12)}`;
|
|
@@ -1678,7 +1718,7 @@ var WebDecoy = class {
|
|
|
1678
1718
|
}
|
|
1679
1719
|
this.config = {
|
|
1680
1720
|
apiKey: config.apiKey,
|
|
1681
|
-
apiUrl: config.apiUrl || "https://
|
|
1721
|
+
apiUrl: config.apiUrl || "https://in.webdecoy.com",
|
|
1682
1722
|
enableTLSFingerprinting: config.enableTLSFingerprinting ?? true,
|
|
1683
1723
|
threatScoreThreshold: config.threatScoreThreshold ?? 80,
|
|
1684
1724
|
timeout: config.timeout ?? 5e3,
|
|
@@ -1686,6 +1726,7 @@ var WebDecoy = class {
|
|
|
1686
1726
|
tlsRejectUnauthorized: config.tlsRejectUnauthorized ?? true
|
|
1687
1727
|
};
|
|
1688
1728
|
this.log = resolveLogger(config.logger, this.config.debug);
|
|
1729
|
+
this.tracer = config.tracer;
|
|
1689
1730
|
if (hasApiKey) {
|
|
1690
1731
|
this.client = new WebDecoyClient({
|
|
1691
1732
|
apiKey: config.apiKey,
|
|
@@ -1813,7 +1854,13 @@ var WebDecoy = class {
|
|
|
1813
1854
|
/** Evaluate rules against a prepared context and report any violations. */
|
|
1814
1855
|
runRules(context) {
|
|
1815
1856
|
if (!this.ruleEngine) return null;
|
|
1857
|
+
const span = startSpan(this.tracer, "webdecoy.rules");
|
|
1816
1858
|
const result = this.ruleEngine.evaluate(context);
|
|
1859
|
+
setAttribute(span, "webdecoy.rules.action", result.action);
|
|
1860
|
+
setAttribute(span, "webdecoy.rules.evaluated", result.results.length);
|
|
1861
|
+
setAttribute(span, "webdecoy.rules.violations", result.violations.length);
|
|
1862
|
+
if (result.rule) setAttribute(span, "webdecoy.rules.deciding", result.rule);
|
|
1863
|
+
endSpan(span);
|
|
1817
1864
|
if (result.violations.length > 0 && this.violationReporter) {
|
|
1818
1865
|
this.violationReporter.report(result.violations);
|
|
1819
1866
|
}
|
|
@@ -1881,7 +1928,31 @@ var WebDecoy = class {
|
|
|
1881
1928
|
*/
|
|
1882
1929
|
async protect(metadata, options = {}) {
|
|
1883
1930
|
const edge = readEdgeVerdict(metadata.headers);
|
|
1884
|
-
|
|
1931
|
+
const span = startSpan(this.tracer, "webdecoy.protect");
|
|
1932
|
+
try {
|
|
1933
|
+
const decision = (await this.decide(metadata, options)).withEdge(edge);
|
|
1934
|
+
setAttribute(span, "webdecoy.decision.id", decision.id);
|
|
1935
|
+
setAttribute(span, "webdecoy.decision.conclusion", decision.conclusion);
|
|
1936
|
+
setAttribute(span, "webdecoy.decision.allowed", decision.allowed);
|
|
1937
|
+
setAttribute(span, "webdecoy.rules.evaluated", decision.results.length);
|
|
1938
|
+
if (decision.ruleResult?.rule) {
|
|
1939
|
+
setAttribute(span, "webdecoy.decision.rule", decision.ruleResult.rule);
|
|
1940
|
+
}
|
|
1941
|
+
setAttribute(
|
|
1942
|
+
span,
|
|
1943
|
+
"webdecoy.remote",
|
|
1944
|
+
decision.detection.detection_id !== decision.id
|
|
1945
|
+
);
|
|
1946
|
+
if (decision.error) {
|
|
1947
|
+
setAttribute(span, "webdecoy.error", decision.error);
|
|
1948
|
+
}
|
|
1949
|
+
return decision;
|
|
1950
|
+
} catch (error) {
|
|
1951
|
+
recordError(span, error);
|
|
1952
|
+
throw error;
|
|
1953
|
+
} finally {
|
|
1954
|
+
endSpan(span);
|
|
1955
|
+
}
|
|
1885
1956
|
}
|
|
1886
1957
|
async decide(metadata, options = {}) {
|
|
1887
1958
|
const id = newDecisionId();
|
|
@@ -1955,7 +2026,7 @@ var WebDecoy = class {
|
|
|
1955
2026
|
local_analysis: localAnalysis
|
|
1956
2027
|
};
|
|
1957
2028
|
const shouldCallServer = localAnalysis.needs_verification || this.config.enableTLSFingerprinting && metadata.tls_info;
|
|
1958
|
-
if (!shouldCallServer
|
|
2029
|
+
if (!shouldCallServer) {
|
|
1959
2030
|
return new Decision({
|
|
1960
2031
|
conclusion: "ALLOW",
|
|
1961
2032
|
detection: {
|
package/dist/testing.mjs
CHANGED