@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/index.js
CHANGED
|
@@ -74,6 +74,7 @@ __export(index_exports, {
|
|
|
74
74
|
createClearanceGate: () => createClearanceGate,
|
|
75
75
|
createDetectAndGate: () => createDetectAndGate,
|
|
76
76
|
createFetchGuard: () => createFetchGuard,
|
|
77
|
+
createOffensiveToolchainEvidence: () => createOffensiveToolchainEvidence,
|
|
77
78
|
deriveAndArm: () => deriveAndArm,
|
|
78
79
|
deriveKey: () => deriveKey,
|
|
79
80
|
filter: () => filter,
|
|
@@ -255,7 +256,11 @@ var WebDecoyClient = class {
|
|
|
255
256
|
}
|
|
256
257
|
throw new Error(`API request failed: HTTP ${response.status}`);
|
|
257
258
|
}
|
|
258
|
-
|
|
259
|
+
const detection = response.data;
|
|
260
|
+
if (request.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)) {
|
|
261
|
+
throw new Error("WebDecoy did not return a valid unified decision");
|
|
262
|
+
}
|
|
263
|
+
return detection;
|
|
259
264
|
}
|
|
260
265
|
async createSSRFCanary(options) {
|
|
261
266
|
const response = await this.request("POST", "/api/v1/sdk/ssrf/markers", {
|
|
@@ -342,13 +347,22 @@ var WebDecoyClient = class {
|
|
|
342
347
|
* Send violation events to the ingest service
|
|
343
348
|
*/
|
|
344
349
|
async sendViolations(events) {
|
|
350
|
+
await this.sendViolationBatch(events);
|
|
351
|
+
}
|
|
352
|
+
/** Acknowledgment from ingest for one batch. Transport failures resolve false. */
|
|
353
|
+
async sendViolationBatch(events) {
|
|
345
354
|
try {
|
|
346
|
-
await this.request("POST", "/api/v1/sdk/violations/batch", { events });
|
|
355
|
+
const { status } = await this.request("POST", "/api/v1/sdk/violations/batch", { events });
|
|
356
|
+
if (status >= 200 && status < 300) return true;
|
|
357
|
+
if (this.config.debug) {
|
|
358
|
+
console.warn(`[WebDecoy] Violation batch returned HTTP ${status}`);
|
|
359
|
+
}
|
|
347
360
|
} catch (error) {
|
|
348
361
|
if (this.config.debug) {
|
|
349
362
|
console.error("[WebDecoy] Failed to send violations:", error);
|
|
350
363
|
}
|
|
351
364
|
}
|
|
365
|
+
return false;
|
|
352
366
|
}
|
|
353
367
|
/**
|
|
354
368
|
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
@@ -2297,7 +2311,9 @@ var MAX_BUFFERED_VIOLATIONS = 1e3;
|
|
|
2297
2311
|
var ViolationReporter = class {
|
|
2298
2312
|
constructor(client, config = {}) {
|
|
2299
2313
|
this.buffer = [];
|
|
2300
|
-
this.
|
|
2314
|
+
this.acknowledgedEvents = 0;
|
|
2315
|
+
this.failedBatches = 0;
|
|
2316
|
+
this.droppedEvents = 0;
|
|
2301
2317
|
this.client = client;
|
|
2302
2318
|
this.maxBufferSize = config.maxBufferSize ?? 50;
|
|
2303
2319
|
this.debug = config.debug ?? false;
|
|
@@ -2313,42 +2329,63 @@ var ViolationReporter = class {
|
|
|
2313
2329
|
report(violations) {
|
|
2314
2330
|
this.buffer.push(...violations);
|
|
2315
2331
|
if (this.buffer.length > MAX_BUFFERED_VIOLATIONS) {
|
|
2316
|
-
|
|
2332
|
+
const overflow = this.buffer.length - MAX_BUFFERED_VIOLATIONS;
|
|
2333
|
+
this.buffer.splice(0, overflow);
|
|
2334
|
+
this.droppedEvents += overflow;
|
|
2317
2335
|
}
|
|
2318
2336
|
if (this.buffer.length >= this.maxBufferSize) {
|
|
2319
2337
|
this.flush().catch(() => {
|
|
2320
2338
|
});
|
|
2321
2339
|
}
|
|
2322
2340
|
}
|
|
2323
|
-
/**
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2341
|
+
/** Flush the buffer, coalescing requests that arrive during an active send. */
|
|
2342
|
+
flush() {
|
|
2343
|
+
if (this.queuedFlush) return this.queuedFlush;
|
|
2344
|
+
if (this.flushPromise) {
|
|
2345
|
+
if (this.buffer.length === 0 || !this.client.isAvailable()) return this.flushPromise;
|
|
2346
|
+
this.queuedFlush = this.flushPromise.then(() => {
|
|
2347
|
+
this.queuedFlush = void 0;
|
|
2348
|
+
return this.flush();
|
|
2349
|
+
});
|
|
2350
|
+
return this.queuedFlush;
|
|
2351
|
+
}
|
|
2352
|
+
if (this.buffer.length === 0 || !this.client.isAvailable()) return Promise.resolve();
|
|
2353
|
+
const size = this.buffer.length;
|
|
2354
|
+
this.flushPromise = Promise.resolve().then(() => this.flushBatches(size)).finally(() => {
|
|
2355
|
+
this.flushPromise = void 0;
|
|
2356
|
+
});
|
|
2357
|
+
return this.flushPromise;
|
|
2358
|
+
}
|
|
2359
|
+
async flushBatches(remaining) {
|
|
2360
|
+
while (remaining > 0 && this.buffer.length > 0 && this.client.isAvailable()) {
|
|
2361
|
+
const batch = this.buffer.splice(0, Math.min(100, remaining));
|
|
2362
|
+
remaining -= batch.length;
|
|
2363
|
+
if (await this.client.sendViolationBatch(batch)) {
|
|
2364
|
+
this.acknowledgedEvents += batch.length;
|
|
2334
2365
|
if (this.debug) {
|
|
2335
2366
|
console.log(`[WebDecoy] Flushed ${batch.length} violation events`);
|
|
2336
2367
|
}
|
|
2368
|
+
} else {
|
|
2369
|
+
this.failedBatches++;
|
|
2370
|
+
this.droppedEvents += batch.length;
|
|
2337
2371
|
}
|
|
2338
|
-
} catch (error) {
|
|
2339
|
-
if (this.debug) {
|
|
2340
|
-
console.error("[WebDecoy] Failed to flush violations:", error);
|
|
2341
|
-
}
|
|
2342
|
-
} finally {
|
|
2343
|
-
this.flushing = false;
|
|
2344
2372
|
}
|
|
2345
2373
|
}
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2374
|
+
getDeliveryStats() {
|
|
2375
|
+
return {
|
|
2376
|
+
acknowledgedEvents: this.acknowledgedEvents,
|
|
2377
|
+
failedBatches: this.failedBatches,
|
|
2378
|
+
droppedEvents: this.droppedEvents,
|
|
2379
|
+
bufferedEvents: this.buffer.length
|
|
2380
|
+
};
|
|
2381
|
+
}
|
|
2382
|
+
/** Stop the timer and give remaining events one final flush. */
|
|
2349
2383
|
async destroy() {
|
|
2350
2384
|
clearInterval(this.flushTimer);
|
|
2385
|
+
if (this.flushPromise) await this.flushPromise;
|
|
2351
2386
|
await this.flush();
|
|
2387
|
+
this.droppedEvents += this.buffer.length;
|
|
2388
|
+
this.buffer.length = 0;
|
|
2352
2389
|
}
|
|
2353
2390
|
};
|
|
2354
2391
|
|
|
@@ -3476,6 +3513,100 @@ function isTestTriggerUserAgent(userAgent) {
|
|
|
3476
3513
|
return userAgent.trimStart().toLowerCase().startsWith(TEST_TRIGGER_UA_PREFIX.toLowerCase());
|
|
3477
3514
|
}
|
|
3478
3515
|
|
|
3516
|
+
// src/offensive-toolchain.ts
|
|
3517
|
+
var TOOLCHAIN_REGISTRY_REVISION = 1;
|
|
3518
|
+
var FRAMEWORK_REGISTRY_REVISION = 5;
|
|
3519
|
+
var reviewedTools = Object.freeze({
|
|
3520
|
+
nmap_scan: "network_reconnaissance",
|
|
3521
|
+
nmap_advanced_scan: "network_reconnaissance",
|
|
3522
|
+
masscan_scan: "network_reconnaissance",
|
|
3523
|
+
nuclei_scan: "vulnerability_scanning",
|
|
3524
|
+
sqlmap_scan: "injection_testing",
|
|
3525
|
+
metasploit_run: "exploitation"
|
|
3526
|
+
});
|
|
3527
|
+
async function createOffensiveToolchainEvidence(input) {
|
|
3528
|
+
const sensor = input.sensor.trim();
|
|
3529
|
+
if (!/^[a-z0-9][a-z0-9_.-]{0,127}$/i.test(sensor)) {
|
|
3530
|
+
throw new Error("sensor must be a 1-128 character stable identifier");
|
|
3531
|
+
}
|
|
3532
|
+
if (!input.runId || input.runId.length > 1024) {
|
|
3533
|
+
throw new Error("runId must be 1-1024 characters");
|
|
3534
|
+
}
|
|
3535
|
+
if (input.correlationSecret.length < 32 || input.correlationSecret.length > 4096) {
|
|
3536
|
+
throw new Error("correlationSecret must be 32-4096 characters");
|
|
3537
|
+
}
|
|
3538
|
+
if (!Array.isArray(input.invocations) || input.invocations.length === 0 || input.invocations.length > 256) {
|
|
3539
|
+
throw new Error("invocations must contain 1-256 entries");
|
|
3540
|
+
}
|
|
3541
|
+
const sequence = [];
|
|
3542
|
+
let redactedArgumentCount = 0;
|
|
3543
|
+
let droppedToolCount = 0;
|
|
3544
|
+
for (const invocation of input.invocations) {
|
|
3545
|
+
if (!invocation.tool || invocation.tool.length > 128) {
|
|
3546
|
+
throw new Error("tool must be 1-128 characters");
|
|
3547
|
+
}
|
|
3548
|
+
const redacted = invocation.redactedArgumentCount ?? 0;
|
|
3549
|
+
if (!Number.isInteger(redacted) || redacted < 0 || redacted > 1024) {
|
|
3550
|
+
throw new Error("redactedArgumentCount must be an integer from 0 through 1024");
|
|
3551
|
+
}
|
|
3552
|
+
const family = reviewedTools[invocation.tool.trim().toLowerCase()];
|
|
3553
|
+
if (!family) {
|
|
3554
|
+
droppedToolCount++;
|
|
3555
|
+
continue;
|
|
3556
|
+
}
|
|
3557
|
+
sequence.push(family);
|
|
3558
|
+
redactedArgumentCount += redacted;
|
|
3559
|
+
if (redactedArgumentCount > 1024) throw new Error("redacted argument count exceeds 1024");
|
|
3560
|
+
}
|
|
3561
|
+
if (sequence.length === 0) throw new Error("no reviewed offensive tools were observed");
|
|
3562
|
+
const families = [...new Set(sequence)].sort();
|
|
3563
|
+
const offensive_toolchain = {
|
|
3564
|
+
schema_version: 1,
|
|
3565
|
+
registry_revision: TOOLCHAIN_REGISTRY_REVISION,
|
|
3566
|
+
plane: "model_api",
|
|
3567
|
+
sensor,
|
|
3568
|
+
run_correlation_id: await hmacSha256Hex(input.correlationSecret, input.runId),
|
|
3569
|
+
tool_families: families,
|
|
3570
|
+
invocation_count: sequence.length,
|
|
3571
|
+
family_set_sha256: await fingerprintIDs(families),
|
|
3572
|
+
sequence_sha256: await sha256Hex(sequence.join("\n")),
|
|
3573
|
+
redacted_argument_count: redactedArgumentCount,
|
|
3574
|
+
dropped_tool_count: droppedToolCount
|
|
3575
|
+
};
|
|
3576
|
+
const evidence = { offensive_toolchain };
|
|
3577
|
+
if (input.orchestrator === "hexstrike_ai") {
|
|
3578
|
+
evidence.framework_evidence = await hexStrikeEvidence();
|
|
3579
|
+
}
|
|
3580
|
+
return evidence;
|
|
3581
|
+
}
|
|
3582
|
+
async function hexStrikeEvidence() {
|
|
3583
|
+
const family = {
|
|
3584
|
+
family_id: "orchestrator_identity",
|
|
3585
|
+
count: 1,
|
|
3586
|
+
sha256: await fingerprintIDs(["hexstrike-ai-mcp"])
|
|
3587
|
+
};
|
|
3588
|
+
return {
|
|
3589
|
+
schema_version: 1,
|
|
3590
|
+
registry_revision: FRAMEWORK_REGISTRY_REVISION,
|
|
3591
|
+
framework: "hexstrike_ai",
|
|
3592
|
+
plane: "model_api",
|
|
3593
|
+
evidence: [family],
|
|
3594
|
+
observation_sha256: await fingerprintEvidence([family])
|
|
3595
|
+
};
|
|
3596
|
+
}
|
|
3597
|
+
async function fingerprintIDs(values) {
|
|
3598
|
+
const canonical = [
|
|
3599
|
+
...new Set(values.map((value) => value.trim().toLowerCase()).filter(Boolean))
|
|
3600
|
+
].sort();
|
|
3601
|
+
return sha256Hex(canonical.join("\n"));
|
|
3602
|
+
}
|
|
3603
|
+
async function fingerprintEvidence(evidence) {
|
|
3604
|
+
const canonical = evidence.map(
|
|
3605
|
+
(value) => `${value.family_id.trim().toLowerCase()}\0${value.count}\0${value.sha256.trim().toLowerCase()}`
|
|
3606
|
+
);
|
|
3607
|
+
return fingerprintIDs(canonical);
|
|
3608
|
+
}
|
|
3609
|
+
|
|
3479
3610
|
// src/sdk.ts
|
|
3480
3611
|
var WebDecoy = class {
|
|
3481
3612
|
constructor(config = {}) {
|
|
@@ -3498,7 +3629,8 @@ var WebDecoy = class {
|
|
|
3498
3629
|
apiKey: config.apiKey,
|
|
3499
3630
|
apiUrl: config.apiUrl || "https://in.webdecoy.com",
|
|
3500
3631
|
enableTLSFingerprinting: config.enableTLSFingerprinting ?? true,
|
|
3501
|
-
|
|
3632
|
+
decisionMode: config.decisionMode ?? "legacy",
|
|
3633
|
+
threatScoreThreshold: config.threatScoreThreshold,
|
|
3502
3634
|
timeout: config.timeout ?? 5e3,
|
|
3503
3635
|
debug: config.debug ?? false,
|
|
3504
3636
|
tlsRejectUnauthorized: config.tlsRejectUnauthorized ?? true,
|
|
@@ -3520,7 +3652,7 @@ var WebDecoy = class {
|
|
|
3520
3652
|
}
|
|
3521
3653
|
this.webBotAuthOptions = config.webBotAuth;
|
|
3522
3654
|
this.characteristics = config.characteristics ?? DEFAULT_CHARACTERISTICS;
|
|
3523
|
-
this.decisionCache = config.decisionCache === false ? null : new DecisionCache(config.decisionCache ?? {});
|
|
3655
|
+
this.decisionCache = config.decisionCache === false || this.config.decisionMode === "unified_v1" ? null : new DecisionCache(config.decisionCache ?? {});
|
|
3524
3656
|
const rules = config.rules ?? [tripwire()];
|
|
3525
3657
|
if (rules.length > 0) {
|
|
3526
3658
|
this.ruleEngine = new RuleEngine(rules);
|
|
@@ -3634,7 +3766,7 @@ var WebDecoy = class {
|
|
|
3634
3766
|
return context;
|
|
3635
3767
|
}
|
|
3636
3768
|
/** Evaluate rules against a prepared context and report any violations. */
|
|
3637
|
-
runRules(context) {
|
|
3769
|
+
runRules(context, reporting) {
|
|
3638
3770
|
if (!this.ruleEngine) return null;
|
|
3639
3771
|
const span = startSpan(this.tracer, "webdecoy.rules");
|
|
3640
3772
|
const result = this.ruleEngine.evaluate(context);
|
|
@@ -3643,8 +3775,17 @@ var WebDecoy = class {
|
|
|
3643
3775
|
setAttribute(span, "webdecoy.rules.violations", result.violations.length);
|
|
3644
3776
|
if (result.rule) setAttribute(span, "webdecoy.rules.deciding", result.rule);
|
|
3645
3777
|
endSpan(span);
|
|
3646
|
-
|
|
3647
|
-
|
|
3778
|
+
const reporter = this.violationReporter;
|
|
3779
|
+
if (reporter && result.violations.length > 0) {
|
|
3780
|
+
const violations = reporting?.mode === "monitor" ? result.violations.map((event) => ({ ...event, dryRun: true, clearance: void 0 })) : result.violations;
|
|
3781
|
+
reporter.report(violations);
|
|
3782
|
+
if (reporting?.waitUntil) {
|
|
3783
|
+
const delivery = Promise.resolve().then(() => reporter.flush()).catch(() => void 0);
|
|
3784
|
+
try {
|
|
3785
|
+
reporting.waitUntil(delivery);
|
|
3786
|
+
} catch {
|
|
3787
|
+
}
|
|
3788
|
+
}
|
|
3648
3789
|
}
|
|
3649
3790
|
return result;
|
|
3650
3791
|
}
|
|
@@ -3743,6 +3884,38 @@ var WebDecoy = class {
|
|
|
3743
3884
|
honeyCredentialFingerprint(tokenId, bearer) {
|
|
3744
3885
|
return hmacSha256Hex(this.config.apiKey, `webdecoy/honey-credential/v1\0${tokenId}\0${bearer}`);
|
|
3745
3886
|
}
|
|
3887
|
+
/**
|
|
3888
|
+
* Report a privacy-bounded model-plane tool run. The helper sends only
|
|
3889
|
+
* reviewed generic families, counts, and digests; it never sends prompts,
|
|
3890
|
+
* arguments, results, credentials, targets, or the raw run ID.
|
|
3891
|
+
*/
|
|
3892
|
+
async reportOffensiveToolchain(input) {
|
|
3893
|
+
if (!this.client) {
|
|
3894
|
+
throw new Error("An apiKey is required to report an offensive toolchain");
|
|
3895
|
+
}
|
|
3896
|
+
const evidence = await createOffensiveToolchainEvidence(input);
|
|
3897
|
+
return this.client.detect({
|
|
3898
|
+
request_metadata: {
|
|
3899
|
+
method: "MODEL",
|
|
3900
|
+
path: "/model-toolchain",
|
|
3901
|
+
// The existing SDK route requires an address. Model-plane evidence has
|
|
3902
|
+
// no target client IP, so use the unspecified address rather than
|
|
3903
|
+
// inventing an identity that could enter actor correlation.
|
|
3904
|
+
ip: "0.0.0.0",
|
|
3905
|
+
headers: {},
|
|
3906
|
+
timestamp: Date.now()
|
|
3907
|
+
},
|
|
3908
|
+
local_analysis: {
|
|
3909
|
+
suspicious_headers: false,
|
|
3910
|
+
missing_sec_ch_ua: false,
|
|
3911
|
+
datacenter_ip: false,
|
|
3912
|
+
local_score: 0,
|
|
3913
|
+
needs_verification: true,
|
|
3914
|
+
flags: ["model_plane_toolchain"]
|
|
3915
|
+
},
|
|
3916
|
+
...evidence
|
|
3917
|
+
});
|
|
3918
|
+
}
|
|
3746
3919
|
/**
|
|
3747
3920
|
* Whether this SDK instance has filter rules that need async enrichment
|
|
3748
3921
|
*/
|
|
@@ -3769,7 +3942,8 @@ var WebDecoy = class {
|
|
|
3769
3942
|
this.referralCounter?.observe(metadata);
|
|
3770
3943
|
const span = startSpan(this.tracer, "webdecoy.protect");
|
|
3771
3944
|
try {
|
|
3772
|
-
|
|
3945
|
+
setAttribute(span, "webdecoy.cloud.decision_mode", this.config.decisionMode);
|
|
3946
|
+
const decision = (await this.decide(metadata, options, span)).withEdge(edge);
|
|
3773
3947
|
setAttribute(span, "webdecoy.decision.id", decision.id);
|
|
3774
3948
|
setAttribute(span, "webdecoy.decision.conclusion", decision.conclusion);
|
|
3775
3949
|
setAttribute(span, "webdecoy.decision.allowed", decision.allowed);
|
|
@@ -3793,7 +3967,7 @@ var WebDecoy = class {
|
|
|
3793
3967
|
endSpan(span);
|
|
3794
3968
|
}
|
|
3795
3969
|
}
|
|
3796
|
-
async decide(metadata, options
|
|
3970
|
+
async decide(metadata, options, span) {
|
|
3797
3971
|
const id = newDecisionId();
|
|
3798
3972
|
let key = metadata.ip || "unknown";
|
|
3799
3973
|
try {
|
|
@@ -3804,14 +3978,16 @@ var WebDecoy = class {
|
|
|
3804
3978
|
metadata.timestamp = Date.now();
|
|
3805
3979
|
}
|
|
3806
3980
|
if (isTestTriggerUserAgent(metadata.user_agent)) {
|
|
3981
|
+
setAttribute(span, "webdecoy.cloud.admission", "test_trigger");
|
|
3807
3982
|
return this.reportTestTrigger(metadata, id);
|
|
3808
3983
|
}
|
|
3809
3984
|
const needsAsync = this._hasFilterRules || this._hasAgentRules || this._preparingRules.length > 0;
|
|
3810
3985
|
const context = needsAsync ? await this.buildAsyncContext(metadata) : this.buildContext(metadata);
|
|
3811
3986
|
key = context.key ?? key;
|
|
3812
3987
|
const agentVerdict = context.agent;
|
|
3813
|
-
const ruleResult = this.ruleEngine ? this.runRules(context) : null;
|
|
3988
|
+
const ruleResult = this.ruleEngine ? this.runRules(context, options.violationReporting) : null;
|
|
3814
3989
|
if (ruleResult && ruleResult.action !== "ALLOW") {
|
|
3990
|
+
setAttribute(span, "webdecoy.cloud.admission", "local_rule");
|
|
3815
3991
|
const throttled = ruleResult.action === "THROTTLE";
|
|
3816
3992
|
return new Decision({
|
|
3817
3993
|
conclusion: "DENY",
|
|
@@ -3832,6 +4008,7 @@ var WebDecoy = class {
|
|
|
3832
4008
|
});
|
|
3833
4009
|
}
|
|
3834
4010
|
if (!this.client) {
|
|
4011
|
+
setAttribute(span, "webdecoy.cloud.admission", "no_api_key");
|
|
3835
4012
|
return new Decision({
|
|
3836
4013
|
conclusion: "ALLOW",
|
|
3837
4014
|
detection: {
|
|
@@ -3850,7 +4027,10 @@ var WebDecoy = class {
|
|
|
3850
4027
|
});
|
|
3851
4028
|
}
|
|
3852
4029
|
const cached = this.decisionCache?.get(key);
|
|
3853
|
-
if (cached)
|
|
4030
|
+
if (cached) {
|
|
4031
|
+
setAttribute(span, "webdecoy.cloud.admission", "cached");
|
|
4032
|
+
return cached.asCached();
|
|
4033
|
+
}
|
|
3854
4034
|
const localAnalysis = options.skipLocalAnalysis ? {
|
|
3855
4035
|
suspicious_headers: false,
|
|
3856
4036
|
missing_sec_ch_ua: false,
|
|
@@ -3860,12 +4040,11 @@ var WebDecoy = class {
|
|
|
3860
4040
|
flags: ["local_analysis_skipped"]
|
|
3861
4041
|
} : analyzeRequest(metadata);
|
|
3862
4042
|
this.log.debug("Local analysis", { ...localAnalysis });
|
|
3863
|
-
const detectionRequest = {
|
|
3864
|
-
request_metadata: metadata,
|
|
3865
|
-
local_analysis: localAnalysis
|
|
3866
|
-
};
|
|
3867
4043
|
const shouldCallServer = localAnalysis.needs_verification || this.config.enableTLSFingerprinting && metadata.tls_info;
|
|
3868
4044
|
if (!shouldCallServer) {
|
|
4045
|
+
setAttribute(span, "webdecoy.cloud.admission", "local_gate");
|
|
4046
|
+
setAttribute(span, "webdecoy.cloud.gate_datacenter_ip", localAnalysis.datacenter_ip);
|
|
4047
|
+
setAttribute(span, "webdecoy.cloud.gate_missing_sec_ch_ua", localAnalysis.missing_sec_ch_ua);
|
|
3869
4048
|
return new Decision({
|
|
3870
4049
|
conclusion: "ALLOW",
|
|
3871
4050
|
detection: {
|
|
@@ -3883,8 +4062,14 @@ var WebDecoy = class {
|
|
|
3883
4062
|
key
|
|
3884
4063
|
});
|
|
3885
4064
|
}
|
|
3886
|
-
const
|
|
3887
|
-
|
|
4065
|
+
const unified = this.config.decisionMode === "unified_v1";
|
|
4066
|
+
setAttribute(span, "webdecoy.cloud.admission", "cloud");
|
|
4067
|
+
const detection = await this.client.detect({
|
|
4068
|
+
request_metadata: metadata,
|
|
4069
|
+
local_analysis: localAnalysis,
|
|
4070
|
+
...unified && { decision_mode: "unified_v1" }
|
|
4071
|
+
});
|
|
4072
|
+
const threshold = options.threshold ?? this.config.threatScoreThreshold ?? (unified ? 0 : 80);
|
|
3888
4073
|
const allowed = detection.decision === "allow" || detection.confidence < threshold;
|
|
3889
4074
|
this.log.debug("Server detection", {
|
|
3890
4075
|
decision: detection.decision,
|
|
@@ -3894,7 +4079,7 @@ var WebDecoy = class {
|
|
|
3894
4079
|
const conclusion = allowed ? "ALLOW" : detection.decision === "challenge" ? "CHALLENGE" : "DENY";
|
|
3895
4080
|
const decision = new Decision({
|
|
3896
4081
|
conclusion,
|
|
3897
|
-
reason: allowed ? void 0 : `Threat score ${detection.confidence} (threshold ${threshold})`,
|
|
4082
|
+
reason: allowed ? void 0 : unified ? `Unified verdict ${detection.decision} (score ${detection.unified_score}, confidence ${detection.confidence})` : `Threat score ${detection.confidence} (threshold ${threshold})`,
|
|
3898
4083
|
detection,
|
|
3899
4084
|
id,
|
|
3900
4085
|
results: ruleResult?.results ?? [],
|
|
@@ -3906,6 +4091,9 @@ var WebDecoy = class {
|
|
|
3906
4091
|
if (this.decisionCache) this.decisionCache.set(key, decision);
|
|
3907
4092
|
return decision;
|
|
3908
4093
|
} catch (error) {
|
|
4094
|
+
if (error instanceof WebDecoyUnavailableError) {
|
|
4095
|
+
setAttribute(span, "webdecoy.cloud.admission", "backoff");
|
|
4096
|
+
}
|
|
3909
4097
|
const log = error instanceof WebDecoyUnavailableError ? this.log.debug.bind(this.log) : this.log.error.bind(this.log);
|
|
3910
4098
|
log("Protection error", {
|
|
3911
4099
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -3959,6 +4147,7 @@ var WebDecoy = class {
|
|
|
3959
4147
|
try {
|
|
3960
4148
|
const detection = await this.client.detect({
|
|
3961
4149
|
request_metadata: metadata,
|
|
4150
|
+
...this.config.decisionMode === "unified_v1" && { decision_mode: "unified_v1" },
|
|
3962
4151
|
local_analysis: {
|
|
3963
4152
|
suspicious_headers: false,
|
|
3964
4153
|
missing_sec_ch_ua: false,
|
|
@@ -4009,6 +4198,10 @@ var WebDecoy = class {
|
|
|
4009
4198
|
setViolationReporter(reporter) {
|
|
4010
4199
|
this.violationReporter = reporter;
|
|
4011
4200
|
}
|
|
4201
|
+
/** Snapshot of this instance's violation delivery, when reporting is enabled. */
|
|
4202
|
+
getViolationDeliveryStats() {
|
|
4203
|
+
return this.violationReporter?.getDeliveryStats?.();
|
|
4204
|
+
}
|
|
4012
4205
|
/**
|
|
4013
4206
|
* Get the API client (for use by violation reporter, enrichment, etc.)
|
|
4014
4207
|
*/
|
|
@@ -5527,7 +5720,8 @@ function createFetchGuard(options = {}) {
|
|
|
5527
5720
|
const decision = await sdk.protect(metadata, {
|
|
5528
5721
|
threshold: options.threshold,
|
|
5529
5722
|
skipLocalAnalysis: options.skipLocalAnalysis,
|
|
5530
|
-
metadata: options.metadata
|
|
5723
|
+
metadata: options.metadata,
|
|
5724
|
+
violationReporting: { mode }
|
|
5531
5725
|
});
|
|
5532
5726
|
if (decision.allowed || mode !== "enforce") return { decision };
|
|
5533
5727
|
return { decision, response: await onBlocked(request, decision) };
|
|
@@ -7759,6 +7953,7 @@ function createCaptchaEndpoints(options = {}) {
|
|
|
7759
7953
|
createClearanceGate,
|
|
7760
7954
|
createDetectAndGate,
|
|
7761
7955
|
createFetchGuard,
|
|
7956
|
+
createOffensiveToolchainEvidence,
|
|
7762
7957
|
deriveAndArm,
|
|
7763
7958
|
deriveKey,
|
|
7764
7959
|
filter,
|
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
resolveGateEnv,
|
|
12
12
|
ruleBlockResponse,
|
|
13
13
|
shouldSkipPath
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-P6IWJ7K5.mjs";
|
|
15
15
|
import {
|
|
16
16
|
ATTACK_SIGNATURE_IDS,
|
|
17
17
|
AgentVerifier,
|
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
classifyUserAgent,
|
|
48
48
|
consoleLogger,
|
|
49
49
|
createAgentVerifier,
|
|
50
|
+
createOffensiveToolchainEvidence,
|
|
50
51
|
deriveKey,
|
|
51
52
|
filter,
|
|
52
53
|
fnv1a64Hex,
|
|
@@ -68,7 +69,7 @@ import {
|
|
|
68
69
|
tripwire,
|
|
69
70
|
upstashRateLimitStore,
|
|
70
71
|
webBotAuth
|
|
71
|
-
} from "./chunk-
|
|
72
|
+
} from "./chunk-32TEUD5K.mjs";
|
|
72
73
|
|
|
73
74
|
// src/client-signals.ts
|
|
74
75
|
var MemoryClientSignalStore = class {
|
|
@@ -2204,6 +2205,7 @@ export {
|
|
|
2204
2205
|
createClearanceGate,
|
|
2205
2206
|
createDetectAndGate,
|
|
2206
2207
|
createFetchGuard,
|
|
2208
|
+
createOffensiveToolchainEvidence,
|
|
2207
2209
|
deriveAndArm,
|
|
2208
2210
|
deriveKey,
|
|
2209
2211
|
filter,
|