@webdecoy/node 0.25.2 → 0.27.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 +43 -1
- package/dist/{chunk-AUHVIVMA.mjs → chunk-32TEUD5K.mjs} +233 -40
- package/dist/{chunk-G5WMRJSQ.mjs → chunk-P6IWJ7K5.mjs} +3 -2
- package/dist/{detect-and-gate-B1HMK-Sd.d.mts → detect-and-gate-BNq26N9d.d.mts} +1 -1
- package/dist/{detect-and-gate-B4KDPdyP.d.ts → detect-and-gate-Dnfo2t3B.d.ts} +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +236 -41
- package/dist/index.mjs +4 -2
- package/dist/{sdk-UlKzxL3L.d.mts → sdk-CJ6pmQGy.d.mts} +145 -11
- package/dist/{sdk-UlKzxL3L.d.ts → sdk-CJ6pmQGy.d.ts} +145 -11
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +236 -40
- package/dist/testing.mjs +1 -1
- package/dist/vercel.d.mts +2 -2
- package/dist/vercel.d.ts +2 -2
- package/dist/vercel.js +238 -41
- package/dist/vercel.mjs +2 -2
- package/package.json +1 -1
package/dist/testing.js
CHANGED
|
@@ -181,7 +181,11 @@ var WebDecoyClient = class {
|
|
|
181
181
|
}
|
|
182
182
|
throw new Error(`API request failed: HTTP ${response.status}`);
|
|
183
183
|
}
|
|
184
|
-
|
|
184
|
+
const detection = response.data;
|
|
185
|
+
if (request2.decision_mode === "unified_v1" && (detection?.decision_mode !== "unified_v1" || !(typeof detection.unified_score === "number" && Number.isInteger(detection.unified_score) && detection.unified_score >= 0 && detection.unified_score <= 100) || !(Number.isInteger(detection.confidence) && detection.confidence >= 0 && detection.confidence <= 100) || !["allow", "challenge", "block"].includes(detection.decision) || typeof detection.detection_id !== "string" || !detection.detection_id)) {
|
|
186
|
+
throw new Error("WebDecoy did not return a valid unified decision");
|
|
187
|
+
}
|
|
188
|
+
return detection;
|
|
185
189
|
}
|
|
186
190
|
async createSSRFCanary(options) {
|
|
187
191
|
const response = await this.request("POST", "/api/v1/sdk/ssrf/markers", {
|
|
@@ -268,13 +272,22 @@ var WebDecoyClient = class {
|
|
|
268
272
|
* Send violation events to the ingest service
|
|
269
273
|
*/
|
|
270
274
|
async sendViolations(events) {
|
|
275
|
+
await this.sendViolationBatch(events);
|
|
276
|
+
}
|
|
277
|
+
/** Acknowledgment from ingest for one batch. Transport failures resolve false. */
|
|
278
|
+
async sendViolationBatch(events) {
|
|
271
279
|
try {
|
|
272
|
-
await this.request("POST", "/api/v1/sdk/violations/batch", { events });
|
|
280
|
+
const { status } = await this.request("POST", "/api/v1/sdk/violations/batch", { events });
|
|
281
|
+
if (status >= 200 && status < 300) return true;
|
|
282
|
+
if (this.config.debug) {
|
|
283
|
+
console.warn(`[WebDecoy] Violation batch returned HTTP ${status}`);
|
|
284
|
+
}
|
|
273
285
|
} catch (error) {
|
|
274
286
|
if (this.config.debug) {
|
|
275
287
|
console.error("[WebDecoy] Failed to send violations:", error);
|
|
276
288
|
}
|
|
277
289
|
}
|
|
290
|
+
return false;
|
|
278
291
|
}
|
|
279
292
|
/**
|
|
280
293
|
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
@@ -1032,6 +1045,10 @@ function toHex(bytes) {
|
|
|
1032
1045
|
for (let i = 0; i < bytes.length; i++) hex += bytes[i].toString(16).padStart(2, "0");
|
|
1033
1046
|
return hex;
|
|
1034
1047
|
}
|
|
1048
|
+
async function sha256Hex(data) {
|
|
1049
|
+
const digest2 = await crypto.subtle.digest("SHA-256", encoder.encode(data));
|
|
1050
|
+
return toHex(new Uint8Array(digest2));
|
|
1051
|
+
}
|
|
1035
1052
|
async function hmacSha256Hex(secret, data) {
|
|
1036
1053
|
const key = await crypto.subtle.importKey(
|
|
1037
1054
|
"raw",
|
|
@@ -1065,7 +1082,9 @@ var MAX_BUFFERED_VIOLATIONS = 1e3;
|
|
|
1065
1082
|
var ViolationReporter = class {
|
|
1066
1083
|
constructor(client, config = {}) {
|
|
1067
1084
|
this.buffer = [];
|
|
1068
|
-
this.
|
|
1085
|
+
this.acknowledgedEvents = 0;
|
|
1086
|
+
this.failedBatches = 0;
|
|
1087
|
+
this.droppedEvents = 0;
|
|
1069
1088
|
this.client = client;
|
|
1070
1089
|
this.maxBufferSize = config.maxBufferSize ?? 50;
|
|
1071
1090
|
this.debug = config.debug ?? false;
|
|
@@ -1081,42 +1100,63 @@ var ViolationReporter = class {
|
|
|
1081
1100
|
report(violations) {
|
|
1082
1101
|
this.buffer.push(...violations);
|
|
1083
1102
|
if (this.buffer.length > MAX_BUFFERED_VIOLATIONS) {
|
|
1084
|
-
|
|
1103
|
+
const overflow = this.buffer.length - MAX_BUFFERED_VIOLATIONS;
|
|
1104
|
+
this.buffer.splice(0, overflow);
|
|
1105
|
+
this.droppedEvents += overflow;
|
|
1085
1106
|
}
|
|
1086
1107
|
if (this.buffer.length >= this.maxBufferSize) {
|
|
1087
1108
|
this.flush().catch(() => {
|
|
1088
1109
|
});
|
|
1089
1110
|
}
|
|
1090
1111
|
}
|
|
1091
|
-
/**
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1112
|
+
/** Flush the buffer, coalescing requests that arrive during an active send. */
|
|
1113
|
+
flush() {
|
|
1114
|
+
if (this.queuedFlush) return this.queuedFlush;
|
|
1115
|
+
if (this.flushPromise) {
|
|
1116
|
+
if (this.buffer.length === 0 || !this.client.isAvailable()) return this.flushPromise;
|
|
1117
|
+
this.queuedFlush = this.flushPromise.then(() => {
|
|
1118
|
+
this.queuedFlush = void 0;
|
|
1119
|
+
return this.flush();
|
|
1120
|
+
});
|
|
1121
|
+
return this.queuedFlush;
|
|
1122
|
+
}
|
|
1123
|
+
if (this.buffer.length === 0 || !this.client.isAvailable()) return Promise.resolve();
|
|
1124
|
+
const size = this.buffer.length;
|
|
1125
|
+
this.flushPromise = Promise.resolve().then(() => this.flushBatches(size)).finally(() => {
|
|
1126
|
+
this.flushPromise = void 0;
|
|
1127
|
+
});
|
|
1128
|
+
return this.flushPromise;
|
|
1129
|
+
}
|
|
1130
|
+
async flushBatches(remaining) {
|
|
1131
|
+
while (remaining > 0 && this.buffer.length > 0 && this.client.isAvailable()) {
|
|
1132
|
+
const batch = this.buffer.splice(0, Math.min(100, remaining));
|
|
1133
|
+
remaining -= batch.length;
|
|
1134
|
+
if (await this.client.sendViolationBatch(batch)) {
|
|
1135
|
+
this.acknowledgedEvents += batch.length;
|
|
1102
1136
|
if (this.debug) {
|
|
1103
1137
|
console.log(`[WebDecoy] Flushed ${batch.length} violation events`);
|
|
1104
1138
|
}
|
|
1139
|
+
} else {
|
|
1140
|
+
this.failedBatches++;
|
|
1141
|
+
this.droppedEvents += batch.length;
|
|
1105
1142
|
}
|
|
1106
|
-
} catch (error) {
|
|
1107
|
-
if (this.debug) {
|
|
1108
|
-
console.error("[WebDecoy] Failed to flush violations:", error);
|
|
1109
|
-
}
|
|
1110
|
-
} finally {
|
|
1111
|
-
this.flushing = false;
|
|
1112
1143
|
}
|
|
1113
1144
|
}
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1145
|
+
getDeliveryStats() {
|
|
1146
|
+
return {
|
|
1147
|
+
acknowledgedEvents: this.acknowledgedEvents,
|
|
1148
|
+
failedBatches: this.failedBatches,
|
|
1149
|
+
droppedEvents: this.droppedEvents,
|
|
1150
|
+
bufferedEvents: this.buffer.length
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
/** Stop the timer and give remaining events one final flush. */
|
|
1117
1154
|
async destroy() {
|
|
1118
1155
|
clearInterval(this.flushTimer);
|
|
1156
|
+
if (this.flushPromise) await this.flushPromise;
|
|
1119
1157
|
await this.flush();
|
|
1158
|
+
this.droppedEvents += this.buffer.length;
|
|
1159
|
+
this.buffer.length = 0;
|
|
1120
1160
|
}
|
|
1121
1161
|
};
|
|
1122
1162
|
|
|
@@ -2232,6 +2272,100 @@ function isTestTriggerUserAgent(userAgent) {
|
|
|
2232
2272
|
return userAgent.trimStart().toLowerCase().startsWith(TEST_TRIGGER_UA_PREFIX.toLowerCase());
|
|
2233
2273
|
}
|
|
2234
2274
|
|
|
2275
|
+
// src/offensive-toolchain.ts
|
|
2276
|
+
var TOOLCHAIN_REGISTRY_REVISION = 1;
|
|
2277
|
+
var FRAMEWORK_REGISTRY_REVISION = 5;
|
|
2278
|
+
var reviewedTools = Object.freeze({
|
|
2279
|
+
nmap_scan: "network_reconnaissance",
|
|
2280
|
+
nmap_advanced_scan: "network_reconnaissance",
|
|
2281
|
+
masscan_scan: "network_reconnaissance",
|
|
2282
|
+
nuclei_scan: "vulnerability_scanning",
|
|
2283
|
+
sqlmap_scan: "injection_testing",
|
|
2284
|
+
metasploit_run: "exploitation"
|
|
2285
|
+
});
|
|
2286
|
+
async function createOffensiveToolchainEvidence(input) {
|
|
2287
|
+
const sensor = input.sensor.trim();
|
|
2288
|
+
if (!/^[a-z0-9][a-z0-9_.-]{0,127}$/i.test(sensor)) {
|
|
2289
|
+
throw new Error("sensor must be a 1-128 character stable identifier");
|
|
2290
|
+
}
|
|
2291
|
+
if (!input.runId || input.runId.length > 1024) {
|
|
2292
|
+
throw new Error("runId must be 1-1024 characters");
|
|
2293
|
+
}
|
|
2294
|
+
if (input.correlationSecret.length < 32 || input.correlationSecret.length > 4096) {
|
|
2295
|
+
throw new Error("correlationSecret must be 32-4096 characters");
|
|
2296
|
+
}
|
|
2297
|
+
if (!Array.isArray(input.invocations) || input.invocations.length === 0 || input.invocations.length > 256) {
|
|
2298
|
+
throw new Error("invocations must contain 1-256 entries");
|
|
2299
|
+
}
|
|
2300
|
+
const sequence = [];
|
|
2301
|
+
let redactedArgumentCount = 0;
|
|
2302
|
+
let droppedToolCount = 0;
|
|
2303
|
+
for (const invocation of input.invocations) {
|
|
2304
|
+
if (!invocation.tool || invocation.tool.length > 128) {
|
|
2305
|
+
throw new Error("tool must be 1-128 characters");
|
|
2306
|
+
}
|
|
2307
|
+
const redacted = invocation.redactedArgumentCount ?? 0;
|
|
2308
|
+
if (!Number.isInteger(redacted) || redacted < 0 || redacted > 1024) {
|
|
2309
|
+
throw new Error("redactedArgumentCount must be an integer from 0 through 1024");
|
|
2310
|
+
}
|
|
2311
|
+
const family = reviewedTools[invocation.tool.trim().toLowerCase()];
|
|
2312
|
+
if (!family) {
|
|
2313
|
+
droppedToolCount++;
|
|
2314
|
+
continue;
|
|
2315
|
+
}
|
|
2316
|
+
sequence.push(family);
|
|
2317
|
+
redactedArgumentCount += redacted;
|
|
2318
|
+
if (redactedArgumentCount > 1024) throw new Error("redacted argument count exceeds 1024");
|
|
2319
|
+
}
|
|
2320
|
+
if (sequence.length === 0) throw new Error("no reviewed offensive tools were observed");
|
|
2321
|
+
const families = [...new Set(sequence)].sort();
|
|
2322
|
+
const offensive_toolchain = {
|
|
2323
|
+
schema_version: 1,
|
|
2324
|
+
registry_revision: TOOLCHAIN_REGISTRY_REVISION,
|
|
2325
|
+
plane: "model_api",
|
|
2326
|
+
sensor,
|
|
2327
|
+
run_correlation_id: await hmacSha256Hex(input.correlationSecret, input.runId),
|
|
2328
|
+
tool_families: families,
|
|
2329
|
+
invocation_count: sequence.length,
|
|
2330
|
+
family_set_sha256: await fingerprintIDs(families),
|
|
2331
|
+
sequence_sha256: await sha256Hex(sequence.join("\n")),
|
|
2332
|
+
redacted_argument_count: redactedArgumentCount,
|
|
2333
|
+
dropped_tool_count: droppedToolCount
|
|
2334
|
+
};
|
|
2335
|
+
const evidence = { offensive_toolchain };
|
|
2336
|
+
if (input.orchestrator === "hexstrike_ai") {
|
|
2337
|
+
evidence.framework_evidence = await hexStrikeEvidence();
|
|
2338
|
+
}
|
|
2339
|
+
return evidence;
|
|
2340
|
+
}
|
|
2341
|
+
async function hexStrikeEvidence() {
|
|
2342
|
+
const family = {
|
|
2343
|
+
family_id: "orchestrator_identity",
|
|
2344
|
+
count: 1,
|
|
2345
|
+
sha256: await fingerprintIDs(["hexstrike-ai-mcp"])
|
|
2346
|
+
};
|
|
2347
|
+
return {
|
|
2348
|
+
schema_version: 1,
|
|
2349
|
+
registry_revision: FRAMEWORK_REGISTRY_REVISION,
|
|
2350
|
+
framework: "hexstrike_ai",
|
|
2351
|
+
plane: "model_api",
|
|
2352
|
+
evidence: [family],
|
|
2353
|
+
observation_sha256: await fingerprintEvidence([family])
|
|
2354
|
+
};
|
|
2355
|
+
}
|
|
2356
|
+
async function fingerprintIDs(values) {
|
|
2357
|
+
const canonical = [
|
|
2358
|
+
...new Set(values.map((value) => value.trim().toLowerCase()).filter(Boolean))
|
|
2359
|
+
].sort();
|
|
2360
|
+
return sha256Hex(canonical.join("\n"));
|
|
2361
|
+
}
|
|
2362
|
+
async function fingerprintEvidence(evidence) {
|
|
2363
|
+
const canonical = evidence.map(
|
|
2364
|
+
(value) => `${value.family_id.trim().toLowerCase()}\0${value.count}\0${value.sha256.trim().toLowerCase()}`
|
|
2365
|
+
);
|
|
2366
|
+
return fingerprintIDs(canonical);
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2235
2369
|
// src/sdk.ts
|
|
2236
2370
|
var WebDecoy = class {
|
|
2237
2371
|
constructor(config = {}) {
|
|
@@ -2254,7 +2388,8 @@ var WebDecoy = class {
|
|
|
2254
2388
|
apiKey: config.apiKey,
|
|
2255
2389
|
apiUrl: config.apiUrl || "https://in.webdecoy.com",
|
|
2256
2390
|
enableTLSFingerprinting: config.enableTLSFingerprinting ?? true,
|
|
2257
|
-
|
|
2391
|
+
decisionMode: config.decisionMode ?? "legacy",
|
|
2392
|
+
threatScoreThreshold: config.threatScoreThreshold,
|
|
2258
2393
|
timeout: config.timeout ?? 5e3,
|
|
2259
2394
|
debug: config.debug ?? false,
|
|
2260
2395
|
tlsRejectUnauthorized: config.tlsRejectUnauthorized ?? true,
|
|
@@ -2276,7 +2411,7 @@ var WebDecoy = class {
|
|
|
2276
2411
|
}
|
|
2277
2412
|
this.webBotAuthOptions = config.webBotAuth;
|
|
2278
2413
|
this.characteristics = config.characteristics ?? DEFAULT_CHARACTERISTICS;
|
|
2279
|
-
this.decisionCache = config.decisionCache === false ? null : new DecisionCache(config.decisionCache ?? {});
|
|
2414
|
+
this.decisionCache = config.decisionCache === false || this.config.decisionMode === "unified_v1" ? null : new DecisionCache(config.decisionCache ?? {});
|
|
2280
2415
|
const rules = config.rules ?? [tripwire()];
|
|
2281
2416
|
if (rules.length > 0) {
|
|
2282
2417
|
this.ruleEngine = new RuleEngine(rules);
|
|
@@ -2390,7 +2525,7 @@ var WebDecoy = class {
|
|
|
2390
2525
|
return context;
|
|
2391
2526
|
}
|
|
2392
2527
|
/** Evaluate rules against a prepared context and report any violations. */
|
|
2393
|
-
runRules(context) {
|
|
2528
|
+
runRules(context, reporting) {
|
|
2394
2529
|
if (!this.ruleEngine) return null;
|
|
2395
2530
|
const span = startSpan(this.tracer, "webdecoy.rules");
|
|
2396
2531
|
const result = this.ruleEngine.evaluate(context);
|
|
@@ -2399,8 +2534,17 @@ var WebDecoy = class {
|
|
|
2399
2534
|
setAttribute(span, "webdecoy.rules.violations", result.violations.length);
|
|
2400
2535
|
if (result.rule) setAttribute(span, "webdecoy.rules.deciding", result.rule);
|
|
2401
2536
|
endSpan(span);
|
|
2402
|
-
|
|
2403
|
-
|
|
2537
|
+
const reporter = this.violationReporter;
|
|
2538
|
+
if (reporter && result.violations.length > 0) {
|
|
2539
|
+
const violations = reporting?.mode === "monitor" ? result.violations.map((event) => ({ ...event, dryRun: true, clearance: void 0 })) : result.violations;
|
|
2540
|
+
reporter.report(violations);
|
|
2541
|
+
if (reporting?.waitUntil) {
|
|
2542
|
+
const delivery = Promise.resolve().then(() => reporter.flush()).catch(() => void 0);
|
|
2543
|
+
try {
|
|
2544
|
+
reporting.waitUntil(delivery);
|
|
2545
|
+
} catch {
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2404
2548
|
}
|
|
2405
2549
|
return result;
|
|
2406
2550
|
}
|
|
@@ -2499,6 +2643,38 @@ var WebDecoy = class {
|
|
|
2499
2643
|
honeyCredentialFingerprint(tokenId, bearer) {
|
|
2500
2644
|
return hmacSha256Hex(this.config.apiKey, `webdecoy/honey-credential/v1\0${tokenId}\0${bearer}`);
|
|
2501
2645
|
}
|
|
2646
|
+
/**
|
|
2647
|
+
* Report a privacy-bounded model-plane tool run. The helper sends only
|
|
2648
|
+
* reviewed generic families, counts, and digests; it never sends prompts,
|
|
2649
|
+
* arguments, results, credentials, targets, or the raw run ID.
|
|
2650
|
+
*/
|
|
2651
|
+
async reportOffensiveToolchain(input) {
|
|
2652
|
+
if (!this.client) {
|
|
2653
|
+
throw new Error("An apiKey is required to report an offensive toolchain");
|
|
2654
|
+
}
|
|
2655
|
+
const evidence = await createOffensiveToolchainEvidence(input);
|
|
2656
|
+
return this.client.detect({
|
|
2657
|
+
request_metadata: {
|
|
2658
|
+
method: "MODEL",
|
|
2659
|
+
path: "/model-toolchain",
|
|
2660
|
+
// The existing SDK route requires an address. Model-plane evidence has
|
|
2661
|
+
// no target client IP, so use the unspecified address rather than
|
|
2662
|
+
// inventing an identity that could enter actor correlation.
|
|
2663
|
+
ip: "0.0.0.0",
|
|
2664
|
+
headers: {},
|
|
2665
|
+
timestamp: Date.now()
|
|
2666
|
+
},
|
|
2667
|
+
local_analysis: {
|
|
2668
|
+
suspicious_headers: false,
|
|
2669
|
+
missing_sec_ch_ua: false,
|
|
2670
|
+
datacenter_ip: false,
|
|
2671
|
+
local_score: 0,
|
|
2672
|
+
needs_verification: true,
|
|
2673
|
+
flags: ["model_plane_toolchain"]
|
|
2674
|
+
},
|
|
2675
|
+
...evidence
|
|
2676
|
+
});
|
|
2677
|
+
}
|
|
2502
2678
|
/**
|
|
2503
2679
|
* Whether this SDK instance has filter rules that need async enrichment
|
|
2504
2680
|
*/
|
|
@@ -2525,7 +2701,8 @@ var WebDecoy = class {
|
|
|
2525
2701
|
this.referralCounter?.observe(metadata);
|
|
2526
2702
|
const span = startSpan(this.tracer, "webdecoy.protect");
|
|
2527
2703
|
try {
|
|
2528
|
-
|
|
2704
|
+
setAttribute(span, "webdecoy.cloud.decision_mode", this.config.decisionMode);
|
|
2705
|
+
const decision = (await this.decide(metadata, options, span)).withEdge(edge);
|
|
2529
2706
|
setAttribute(span, "webdecoy.decision.id", decision.id);
|
|
2530
2707
|
setAttribute(span, "webdecoy.decision.conclusion", decision.conclusion);
|
|
2531
2708
|
setAttribute(span, "webdecoy.decision.allowed", decision.allowed);
|
|
@@ -2549,7 +2726,7 @@ var WebDecoy = class {
|
|
|
2549
2726
|
endSpan(span);
|
|
2550
2727
|
}
|
|
2551
2728
|
}
|
|
2552
|
-
async decide(metadata, options
|
|
2729
|
+
async decide(metadata, options, span) {
|
|
2553
2730
|
const id = newDecisionId();
|
|
2554
2731
|
let key = metadata.ip || "unknown";
|
|
2555
2732
|
try {
|
|
@@ -2560,14 +2737,16 @@ var WebDecoy = class {
|
|
|
2560
2737
|
metadata.timestamp = Date.now();
|
|
2561
2738
|
}
|
|
2562
2739
|
if (isTestTriggerUserAgent(metadata.user_agent)) {
|
|
2740
|
+
setAttribute(span, "webdecoy.cloud.admission", "test_trigger");
|
|
2563
2741
|
return this.reportTestTrigger(metadata, id);
|
|
2564
2742
|
}
|
|
2565
2743
|
const needsAsync = this._hasFilterRules || this._hasAgentRules || this._preparingRules.length > 0;
|
|
2566
2744
|
const context = needsAsync ? await this.buildAsyncContext(metadata) : this.buildContext(metadata);
|
|
2567
2745
|
key = context.key ?? key;
|
|
2568
2746
|
const agentVerdict = context.agent;
|
|
2569
|
-
const ruleResult = this.ruleEngine ? this.runRules(context) : null;
|
|
2747
|
+
const ruleResult = this.ruleEngine ? this.runRules(context, options.violationReporting) : null;
|
|
2570
2748
|
if (ruleResult && ruleResult.action !== "ALLOW") {
|
|
2749
|
+
setAttribute(span, "webdecoy.cloud.admission", "local_rule");
|
|
2571
2750
|
const throttled = ruleResult.action === "THROTTLE";
|
|
2572
2751
|
return new Decision({
|
|
2573
2752
|
conclusion: "DENY",
|
|
@@ -2588,6 +2767,7 @@ var WebDecoy = class {
|
|
|
2588
2767
|
});
|
|
2589
2768
|
}
|
|
2590
2769
|
if (!this.client) {
|
|
2770
|
+
setAttribute(span, "webdecoy.cloud.admission", "no_api_key");
|
|
2591
2771
|
return new Decision({
|
|
2592
2772
|
conclusion: "ALLOW",
|
|
2593
2773
|
detection: {
|
|
@@ -2606,7 +2786,10 @@ var WebDecoy = class {
|
|
|
2606
2786
|
});
|
|
2607
2787
|
}
|
|
2608
2788
|
const cached = this.decisionCache?.get(key);
|
|
2609
|
-
if (cached)
|
|
2789
|
+
if (cached) {
|
|
2790
|
+
setAttribute(span, "webdecoy.cloud.admission", "cached");
|
|
2791
|
+
return cached.asCached();
|
|
2792
|
+
}
|
|
2610
2793
|
const localAnalysis = options.skipLocalAnalysis ? {
|
|
2611
2794
|
suspicious_headers: false,
|
|
2612
2795
|
missing_sec_ch_ua: false,
|
|
@@ -2616,12 +2799,11 @@ var WebDecoy = class {
|
|
|
2616
2799
|
flags: ["local_analysis_skipped"]
|
|
2617
2800
|
} : analyzeRequest(metadata);
|
|
2618
2801
|
this.log.debug("Local analysis", { ...localAnalysis });
|
|
2619
|
-
const detectionRequest = {
|
|
2620
|
-
request_metadata: metadata,
|
|
2621
|
-
local_analysis: localAnalysis
|
|
2622
|
-
};
|
|
2623
2802
|
const shouldCallServer = localAnalysis.needs_verification || this.config.enableTLSFingerprinting && metadata.tls_info;
|
|
2624
2803
|
if (!shouldCallServer) {
|
|
2804
|
+
setAttribute(span, "webdecoy.cloud.admission", "local_gate");
|
|
2805
|
+
setAttribute(span, "webdecoy.cloud.gate_datacenter_ip", localAnalysis.datacenter_ip);
|
|
2806
|
+
setAttribute(span, "webdecoy.cloud.gate_missing_sec_ch_ua", localAnalysis.missing_sec_ch_ua);
|
|
2625
2807
|
return new Decision({
|
|
2626
2808
|
conclusion: "ALLOW",
|
|
2627
2809
|
detection: {
|
|
@@ -2639,8 +2821,14 @@ var WebDecoy = class {
|
|
|
2639
2821
|
key
|
|
2640
2822
|
});
|
|
2641
2823
|
}
|
|
2642
|
-
const
|
|
2643
|
-
|
|
2824
|
+
const unified = this.config.decisionMode === "unified_v1";
|
|
2825
|
+
setAttribute(span, "webdecoy.cloud.admission", "cloud");
|
|
2826
|
+
const detection = await this.client.detect({
|
|
2827
|
+
request_metadata: metadata,
|
|
2828
|
+
local_analysis: localAnalysis,
|
|
2829
|
+
...unified && { decision_mode: "unified_v1" }
|
|
2830
|
+
});
|
|
2831
|
+
const threshold = options.threshold ?? this.config.threatScoreThreshold ?? (unified ? 0 : 80);
|
|
2644
2832
|
const allowed = detection.decision === "allow" || detection.confidence < threshold;
|
|
2645
2833
|
this.log.debug("Server detection", {
|
|
2646
2834
|
decision: detection.decision,
|
|
@@ -2650,7 +2838,7 @@ var WebDecoy = class {
|
|
|
2650
2838
|
const conclusion = allowed ? "ALLOW" : detection.decision === "challenge" ? "CHALLENGE" : "DENY";
|
|
2651
2839
|
const decision = new Decision({
|
|
2652
2840
|
conclusion,
|
|
2653
|
-
reason: allowed ? void 0 : `Threat score ${detection.confidence} (threshold ${threshold})`,
|
|
2841
|
+
reason: allowed ? void 0 : unified ? `Unified verdict ${detection.decision} (score ${detection.unified_score}, confidence ${detection.confidence})` : `Threat score ${detection.confidence} (threshold ${threshold})`,
|
|
2654
2842
|
detection,
|
|
2655
2843
|
id,
|
|
2656
2844
|
results: ruleResult?.results ?? [],
|
|
@@ -2662,6 +2850,9 @@ var WebDecoy = class {
|
|
|
2662
2850
|
if (this.decisionCache) this.decisionCache.set(key, decision);
|
|
2663
2851
|
return decision;
|
|
2664
2852
|
} catch (error) {
|
|
2853
|
+
if (error instanceof WebDecoyUnavailableError) {
|
|
2854
|
+
setAttribute(span, "webdecoy.cloud.admission", "backoff");
|
|
2855
|
+
}
|
|
2665
2856
|
const log = error instanceof WebDecoyUnavailableError ? this.log.debug.bind(this.log) : this.log.error.bind(this.log);
|
|
2666
2857
|
log("Protection error", {
|
|
2667
2858
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -2715,6 +2906,7 @@ var WebDecoy = class {
|
|
|
2715
2906
|
try {
|
|
2716
2907
|
const detection = await this.client.detect({
|
|
2717
2908
|
request_metadata: metadata,
|
|
2909
|
+
...this.config.decisionMode === "unified_v1" && { decision_mode: "unified_v1" },
|
|
2718
2910
|
local_analysis: {
|
|
2719
2911
|
suspicious_headers: false,
|
|
2720
2912
|
missing_sec_ch_ua: false,
|
|
@@ -2765,6 +2957,10 @@ var WebDecoy = class {
|
|
|
2765
2957
|
setViolationReporter(reporter) {
|
|
2766
2958
|
this.violationReporter = reporter;
|
|
2767
2959
|
}
|
|
2960
|
+
/** Snapshot of this instance's violation delivery, when reporting is enabled. */
|
|
2961
|
+
getViolationDeliveryStats() {
|
|
2962
|
+
return this.violationReporter?.getDeliveryStats?.();
|
|
2963
|
+
}
|
|
2768
2964
|
/**
|
|
2769
2965
|
* Get the API client (for use by violation reporter, enrichment, etc.)
|
|
2770
2966
|
*/
|
package/dist/testing.mjs
CHANGED
package/dist/vercel.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ClearanceGateOptions, C as ClearanceContext, D as DetectAndGateOptions, d as GateOutcome } from './detect-and-gate-
|
|
2
|
-
import './sdk-
|
|
1
|
+
import { a as ClearanceGateOptions, C as ClearanceContext, D as DetectAndGateOptions, d as GateOutcome } from './detect-and-gate-BNq26N9d.mjs';
|
|
2
|
+
import './sdk-CJ6pmQGy.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* WebDecoy for Vercel Routing Middleware, any framework.
|
package/dist/vercel.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ClearanceGateOptions, C as ClearanceContext, D as DetectAndGateOptions, d as GateOutcome } from './detect-and-gate-
|
|
2
|
-
import './sdk-
|
|
1
|
+
import { a as ClearanceGateOptions, C as ClearanceContext, D as DetectAndGateOptions, d as GateOutcome } from './detect-and-gate-Dnfo2t3B.js';
|
|
2
|
+
import './sdk-CJ6pmQGy.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* WebDecoy for Vercel Routing Middleware, any framework.
|