@webdecoy/node 0.21.3 → 0.22.1

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/index.mjs CHANGED
@@ -1,3 +1,17 @@
1
+ import {
2
+ armSiteHoneytoken,
3
+ createClearanceGate,
4
+ createDetectAndGate,
5
+ createFetchGuard,
6
+ deriveAndArm,
7
+ ipInCidr,
8
+ ne,
9
+ normalizeIp,
10
+ resolveClientIp,
11
+ resolveGateEnv,
12
+ ruleBlockResponse,
13
+ shouldSkipPath
14
+ } from "./chunk-YHXMGL23.mjs";
1
15
  import {
2
16
  ATTACK_SIGNATURE_IDS,
3
17
  AgentVerifier,
@@ -54,15 +68,7 @@ import {
54
68
  tripwire,
55
69
  upstashRateLimitStore,
56
70
  webBotAuth
57
- } from "./chunk-7SOUHH7Z.mjs";
58
- import {
59
- createClearanceGate,
60
- ipInCidr,
61
- ne,
62
- normalizeIp,
63
- resolveClientIp,
64
- resolveGateEnv
65
- } from "./chunk-NM4QG3XD.mjs";
71
+ } from "./chunk-OAPCW4BA.mjs";
66
72
 
67
73
  // src/client-signals.ts
68
74
  var MemoryClientSignalStore = class {
@@ -173,143 +179,6 @@ function clientSignals(config) {
173
179
  return new ClientSignalRule(config);
174
180
  }
175
181
 
176
- // src/adapter-core.ts
177
- function shouldSkipPath(path, patterns) {
178
- if (!patterns || patterns.length === 0) return false;
179
- return patterns.some(
180
- (pattern) => typeof pattern === "string" ? path === pattern || path.startsWith(pattern) : pattern.test(path)
181
- );
182
- }
183
- function ruleBlockResponse(decision) {
184
- const rr = decision.ruleResult;
185
- if (decision.allowed || !rr) return null;
186
- if (rr.action === "THROTTLE") {
187
- const retryAfter = Number(rr.metadata?.retryAfter ?? 60);
188
- return {
189
- status: 429,
190
- headers: { "Retry-After": String(retryAfter) },
191
- body: {
192
- error: "Too Many Requests",
193
- message: rr.reason || "Rate limit exceeded",
194
- retry_after: retryAfter
195
- }
196
- };
197
- }
198
- if (rr.action === "DENY") {
199
- return {
200
- status: 403,
201
- headers: {},
202
- body: {
203
- error: "Forbidden",
204
- message: rr.reason || "Access denied by rule",
205
- rule: rr.rule
206
- }
207
- };
208
- }
209
- return null;
210
- }
211
- function armSiteHoneytoken(sdk, options) {
212
- let token = null;
213
- void deriveAndArm(sdk, options).then((t) => {
214
- token = t;
215
- });
216
- return () => token;
217
- }
218
- async function deriveAndArm(sdk, options) {
219
- const enabled = (options.enabled ?? true) && Boolean(options.apiKey);
220
- if (!enabled) return null;
221
- try {
222
- const token = await siteHoneytoken({ secret: options.apiKey });
223
- sdk.addRule(tripwire({ paths: token.activePaths, includeDefaults: false }));
224
- return token;
225
- } catch (error) {
226
- options.onError?.(error);
227
- return null;
228
- }
229
- }
230
-
231
- // src/fetch-guard.ts
232
- function defaultBlocked(_request, decision) {
233
- const block = ruleBlockResponse(decision) ?? {
234
- status: 403,
235
- headers: {},
236
- body: { error: "Forbidden", message: "Access denied by Web Decoy protection" }
237
- };
238
- return new Response(JSON.stringify({ ...block.body, detection_id: decision.id }), {
239
- status: block.status,
240
- headers: { "content-type": "application/json", ...block.headers }
241
- });
242
- }
243
- function headerRecord(headers) {
244
- const out = {};
245
- headers.forEach((value, key) => {
246
- out[key.toLowerCase()] = value;
247
- });
248
- return out;
249
- }
250
- function createFetchGuard(options = {}) {
251
- const sdk = new WebDecoy(options);
252
- const mode = options.mode ?? "monitor";
253
- const onBlocked = options.onBlocked ?? defaultBlocked;
254
- const getToken = armSiteHoneytoken(sdk, {
255
- apiKey: options.apiKey,
256
- enabled: options.honeytoken
257
- });
258
- function resolveIP(request, peer) {
259
- if (options.getIP) return options.getIP(request);
260
- return resolveClientIp({
261
- headers: request.headers,
262
- peer,
263
- trustProxy: options.trustProxy ?? 1
264
- }) ?? normalizeIp(peer) ?? "127.0.0.1";
265
- }
266
- return {
267
- sdk,
268
- skips(pathname) {
269
- return shouldSkipPath(pathname, options.skipPaths);
270
- },
271
- async check(request, peer) {
272
- const url = new URL(request.url);
273
- const metadata = {
274
- method: request.method,
275
- path: url.pathname,
276
- ip: resolveIP(request, peer),
277
- user_agent: request.headers.get("user-agent") ?? void 0,
278
- headers: headerRecord(request.headers),
279
- query: url.search ? url.search.slice(1) : void 0,
280
- timestamp: Date.now()
281
- };
282
- const decision = await sdk.protect(metadata, {
283
- threshold: options.threshold,
284
- skipLocalAnalysis: options.skipLocalAnalysis,
285
- metadata: options.metadata
286
- });
287
- if (decision.allowed || mode !== "enforce") return { decision };
288
- return { decision, response: await onBlocked(request, decision) };
289
- },
290
- async decorate(response) {
291
- const current = getToken();
292
- if (!current) return response;
293
- if (!isInjectableHtml(response.headers.get("content-type"))) return response;
294
- if (response.bodyUsed) return response;
295
- try {
296
- const html = await response.text();
297
- const injected = injectHoneytokenLink(html, current.linkHtml);
298
- if (injected === html) return new Response(html, response);
299
- const headers = new Headers(response.headers);
300
- headers.delete("content-length");
301
- return new Response(injected, {
302
- status: response.status,
303
- statusText: response.statusText,
304
- headers
305
- });
306
- } catch {
307
- return response;
308
- }
309
- }
310
- };
311
- }
312
-
313
182
  // src/detection/weights.ts
314
183
  var DEFAULT_WEIGHTS = {
315
184
  vision_ai: 0.15,
@@ -2333,6 +2202,7 @@ export {
2333
2202
  createAgentVerifier,
2334
2203
  createCaptchaEndpoints,
2335
2204
  createClearanceGate,
2205
+ createDetectAndGate,
2336
2206
  createFetchGuard,
2337
2207
  deriveAndArm,
2338
2208
  deriveKey,
@@ -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
- * 191 agents across 15 categories.
313
+ * 192 agents across 15 categories.
314
314
  */
315
315
  /**
316
316
  * Classification categories, mirroring `agents.Category` in Go.
@@ -1465,4 +1465,4 @@ declare class WebDecoy {
1465
1465
  destroy(): Promise<void>;
1466
1466
  }
1467
1467
 
1468
- 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 };
1468
+ export { consoleLogger as $, type AgentCategory as A, type BotRuleConfig as B, type Characteristic as C, DEFAULT_CHARACTERISTICS as D, EDGE_CLASS_HEADER as E, type FilterConfig as F, type ProtectOptions as G, type RequestMetadata as H, type IPEnrichmentData as I, type RuleOutcome as J, type RuleState as K, type LocalAnalysis as L, MemoryRateLimitStore as M, type SDKDetectionRequest as N, type SDKDetectionResponse as O, type ProtectResult as P, type Span as Q, type Rule as R, type SignedAgentDirectory as S, type TripwireConfig as T, type SyncRateLimitStore as U, type TLSInfo as V, WebDecoy as W, type Tracer as X, type ViolationEvent as Y, type WebDecoyConfig 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 AgentVerifierOptions as j, type AgentRequestInput as k, type AgentVerdict as l, type AgentStatus as m, BOT_CATEGORIES as n, BOT_REGISTRY as o, type BotVerdict as p, type Conclusion as q, Decision as r, DecisionCache as s, type DecisionCacheOptions as t, type DecisionInit as u, EDGE_CLEARANCE_HEADER as v, type EdgeClass as w, type EdgeVerdict as x, type LogFields as y, type Logger 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
- * 191 agents across 15 categories.
313
+ * 192 agents across 15 categories.
314
314
  */
315
315
  /**
316
316
  * Classification categories, mirroring `agents.Category` in Go.
@@ -1465,4 +1465,4 @@ declare class WebDecoy {
1465
1465
  destroy(): Promise<void>;
1466
1466
  }
1467
1467
 
1468
- 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 };
1468
+ export { consoleLogger as $, type AgentCategory as A, type BotRuleConfig as B, type Characteristic as C, DEFAULT_CHARACTERISTICS as D, EDGE_CLASS_HEADER as E, type FilterConfig as F, type ProtectOptions as G, type RequestMetadata as H, type IPEnrichmentData as I, type RuleOutcome as J, type RuleState as K, type LocalAnalysis as L, MemoryRateLimitStore as M, type SDKDetectionRequest as N, type SDKDetectionResponse as O, type ProtectResult as P, type Span as Q, type Rule as R, type SignedAgentDirectory as S, type TripwireConfig as T, type SyncRateLimitStore as U, type TLSInfo as V, WebDecoy as W, type Tracer as X, type ViolationEvent as Y, type WebDecoyConfig 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 AgentVerifierOptions as j, type AgentRequestInput as k, type AgentVerdict as l, type AgentStatus as m, BOT_CATEGORIES as n, BOT_REGISTRY as o, type BotVerdict as p, type Conclusion as q, Decision as r, DecisionCache as s, type DecisionCacheOptions as t, type DecisionInit as u, EDGE_CLEARANCE_HEADER as v, type EdgeClass as w, type EdgeVerdict as x, type LogFields as y, type Logger as z };
@@ -1,4 +1,4 @@
1
- import { j as WebDecoyConfig, J as RequestMetadata, W as WebDecoy, P as ProtectResult, N as RuleState } from './sdk-C-gaFOT_.mjs';
1
+ import { Z as WebDecoyConfig, H as RequestMetadata, W as WebDecoy, P as ProtectResult, K as RuleState } from './sdk-CLrhCMK0.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 { j as WebDecoyConfig, J as RequestMetadata, W as WebDecoy, P as ProtectResult, N as RuleState } from './sdk-C-gaFOT_.js';
1
+ import { Z as WebDecoyConfig, H as RequestMetadata, W as WebDecoy, P as ProtectResult, K as RuleState } from './sdk-CLrhCMK0.js';
2
2
 
3
3
  /**
4
4
  * Testing utilities, for the application's test suite rather than ours.