@webdecoy/node 0.21.2 → 0.22.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 +203 -155
- package/dist/{chunk-HSG6RWOQ.mjs → chunk-FL7FXNYV.mjs} +483 -483
- package/dist/{chunk-NM4QG3XD.mjs → chunk-P7Z7XFK6.mjs} +221 -1
- package/dist/{index-GXXXr_mb.d.ts → detect-and-gate-BES1jZ8P.d.mts} +146 -1
- package/dist/{index-GXXXr_mb.d.mts → detect-and-gate-C7Uw14OR.d.ts} +146 -1
- package/dist/index.d.mts +4 -91
- package/dist/index.d.ts +4 -91
- package/dist/index.js +684 -613
- package/dist/index.mjs +16 -146
- package/dist/{sdk-FCU-Ce-1.d.mts → sdk-B8M-WYTc.d.mts} +2 -2
- package/dist/{sdk-FCU-Ce-1.d.ts → sdk-B8M-WYTc.d.ts} +2 -2
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +246 -246
- package/dist/testing.mjs +1 -1
- package/dist/vercel.d.mts +42 -9
- package/dist/vercel.d.ts +42 -9
- package/dist/vercel.js +2784 -1
- package/dist/vercel.mjs +16 -3
- package/package.json +11 -1
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-P7Z7XFK6.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-
|
|
58
|
-
import {
|
|
59
|
-
createClearanceGate,
|
|
60
|
-
ipInCidr,
|
|
61
|
-
ne,
|
|
62
|
-
normalizeIp,
|
|
63
|
-
resolveClientIp,
|
|
64
|
-
resolveGateEnv
|
|
65
|
-
} from "./chunk-NM4QG3XD.mjs";
|
|
71
|
+
} from "./chunk-FL7FXNYV.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,
|
|
@@ -1348,7 +1348,7 @@ declare class WebDecoy {
|
|
|
1348
1348
|
/** Optional OpenTelemetry tracer. Absent means no spans and no cost. */
|
|
1349
1349
|
private readonly tracer?;
|
|
1350
1350
|
private readonly decisionCache;
|
|
1351
|
-
constructor(config
|
|
1351
|
+
constructor(config?: WebDecoyConfig);
|
|
1352
1352
|
/**
|
|
1353
1353
|
* Evaluate rules against request metadata (synchronous).
|
|
1354
1354
|
* Returns null if no rules are configured.
|
|
@@ -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,
|
|
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 };
|
|
@@ -1348,7 +1348,7 @@ declare class WebDecoy {
|
|
|
1348
1348
|
/** Optional OpenTelemetry tracer. Absent means no spans and no cost. */
|
|
1349
1349
|
private readonly tracer?;
|
|
1350
1350
|
private readonly decisionCache;
|
|
1351
|
-
constructor(config
|
|
1351
|
+
constructor(config?: WebDecoyConfig);
|
|
1352
1352
|
/**
|
|
1353
1353
|
* Evaluate rules against request metadata (synchronous).
|
|
1354
1354
|
* Returns null if no rules are configured.
|
|
@@ -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,
|
|
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 };
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Z as WebDecoyConfig, H as RequestMetadata, W as WebDecoy, P as ProtectResult, K as RuleState } from './sdk-B8M-WYTc.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 { Z as WebDecoyConfig, H as RequestMetadata, W as WebDecoy, P as ProtectResult, K as RuleState } from './sdk-B8M-WYTc.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Testing utilities, for the application's test suite rather than ours.
|