@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/vercel.js
CHANGED
|
@@ -1543,7 +1543,11 @@ var WebDecoyClient = class {
|
|
|
1543
1543
|
}
|
|
1544
1544
|
throw new Error(`API request failed: HTTP ${response.status}`);
|
|
1545
1545
|
}
|
|
1546
|
-
|
|
1546
|
+
const detection = response.data;
|
|
1547
|
+
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)) {
|
|
1548
|
+
throw new Error("WebDecoy did not return a valid unified decision");
|
|
1549
|
+
}
|
|
1550
|
+
return detection;
|
|
1547
1551
|
}
|
|
1548
1552
|
async createSSRFCanary(options) {
|
|
1549
1553
|
const response = await this.request("POST", "/api/v1/sdk/ssrf/markers", {
|
|
@@ -1630,13 +1634,22 @@ var WebDecoyClient = class {
|
|
|
1630
1634
|
* Send violation events to the ingest service
|
|
1631
1635
|
*/
|
|
1632
1636
|
async sendViolations(events) {
|
|
1637
|
+
await this.sendViolationBatch(events);
|
|
1638
|
+
}
|
|
1639
|
+
/** Acknowledgment from ingest for one batch. Transport failures resolve false. */
|
|
1640
|
+
async sendViolationBatch(events) {
|
|
1633
1641
|
try {
|
|
1634
|
-
await this.request("POST", "/api/v1/sdk/violations/batch", { events });
|
|
1642
|
+
const { status } = await this.request("POST", "/api/v1/sdk/violations/batch", { events });
|
|
1643
|
+
if (status >= 200 && status < 300) return true;
|
|
1644
|
+
if (this.config.debug) {
|
|
1645
|
+
console.warn(`[WebDecoy] Violation batch returned HTTP ${status}`);
|
|
1646
|
+
}
|
|
1635
1647
|
} catch (error) {
|
|
1636
1648
|
if (this.config.debug) {
|
|
1637
1649
|
console.error("[WebDecoy] Failed to send violations:", error);
|
|
1638
1650
|
}
|
|
1639
1651
|
}
|
|
1652
|
+
return false;
|
|
1640
1653
|
}
|
|
1641
1654
|
/**
|
|
1642
1655
|
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
@@ -2394,6 +2407,10 @@ function toHex(bytes) {
|
|
|
2394
2407
|
for (let i = 0; i < bytes.length; i++) hex += bytes[i].toString(16).padStart(2, "0");
|
|
2395
2408
|
return hex;
|
|
2396
2409
|
}
|
|
2410
|
+
async function sha256Hex(data) {
|
|
2411
|
+
const digest2 = await crypto.subtle.digest("SHA-256", encoder.encode(data));
|
|
2412
|
+
return toHex(new Uint8Array(digest2));
|
|
2413
|
+
}
|
|
2397
2414
|
async function hmacSha256Hex(secret, data) {
|
|
2398
2415
|
const key = await crypto.subtle.importKey(
|
|
2399
2416
|
"raw",
|
|
@@ -2499,7 +2516,9 @@ var MAX_BUFFERED_VIOLATIONS = 1e3;
|
|
|
2499
2516
|
var ViolationReporter = class {
|
|
2500
2517
|
constructor(client, config = {}) {
|
|
2501
2518
|
this.buffer = [];
|
|
2502
|
-
this.
|
|
2519
|
+
this.acknowledgedEvents = 0;
|
|
2520
|
+
this.failedBatches = 0;
|
|
2521
|
+
this.droppedEvents = 0;
|
|
2503
2522
|
this.client = client;
|
|
2504
2523
|
this.maxBufferSize = config.maxBufferSize ?? 50;
|
|
2505
2524
|
this.debug = config.debug ?? false;
|
|
@@ -2515,42 +2534,63 @@ var ViolationReporter = class {
|
|
|
2515
2534
|
report(violations) {
|
|
2516
2535
|
this.buffer.push(...violations);
|
|
2517
2536
|
if (this.buffer.length > MAX_BUFFERED_VIOLATIONS) {
|
|
2518
|
-
|
|
2537
|
+
const overflow = this.buffer.length - MAX_BUFFERED_VIOLATIONS;
|
|
2538
|
+
this.buffer.splice(0, overflow);
|
|
2539
|
+
this.droppedEvents += overflow;
|
|
2519
2540
|
}
|
|
2520
2541
|
if (this.buffer.length >= this.maxBufferSize) {
|
|
2521
2542
|
this.flush().catch(() => {
|
|
2522
2543
|
});
|
|
2523
2544
|
}
|
|
2524
2545
|
}
|
|
2525
|
-
/**
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2546
|
+
/** Flush the buffer, coalescing requests that arrive during an active send. */
|
|
2547
|
+
flush() {
|
|
2548
|
+
if (this.queuedFlush) return this.queuedFlush;
|
|
2549
|
+
if (this.flushPromise) {
|
|
2550
|
+
if (this.buffer.length === 0 || !this.client.isAvailable()) return this.flushPromise;
|
|
2551
|
+
this.queuedFlush = this.flushPromise.then(() => {
|
|
2552
|
+
this.queuedFlush = void 0;
|
|
2553
|
+
return this.flush();
|
|
2554
|
+
});
|
|
2555
|
+
return this.queuedFlush;
|
|
2556
|
+
}
|
|
2557
|
+
if (this.buffer.length === 0 || !this.client.isAvailable()) return Promise.resolve();
|
|
2558
|
+
const size = this.buffer.length;
|
|
2559
|
+
this.flushPromise = Promise.resolve().then(() => this.flushBatches(size)).finally(() => {
|
|
2560
|
+
this.flushPromise = void 0;
|
|
2561
|
+
});
|
|
2562
|
+
return this.flushPromise;
|
|
2563
|
+
}
|
|
2564
|
+
async flushBatches(remaining) {
|
|
2565
|
+
while (remaining > 0 && this.buffer.length > 0 && this.client.isAvailable()) {
|
|
2566
|
+
const batch = this.buffer.splice(0, Math.min(100, remaining));
|
|
2567
|
+
remaining -= batch.length;
|
|
2568
|
+
if (await this.client.sendViolationBatch(batch)) {
|
|
2569
|
+
this.acknowledgedEvents += batch.length;
|
|
2536
2570
|
if (this.debug) {
|
|
2537
2571
|
console.log(`[WebDecoy] Flushed ${batch.length} violation events`);
|
|
2538
2572
|
}
|
|
2573
|
+
} else {
|
|
2574
|
+
this.failedBatches++;
|
|
2575
|
+
this.droppedEvents += batch.length;
|
|
2539
2576
|
}
|
|
2540
|
-
} catch (error) {
|
|
2541
|
-
if (this.debug) {
|
|
2542
|
-
console.error("[WebDecoy] Failed to flush violations:", error);
|
|
2543
|
-
}
|
|
2544
|
-
} finally {
|
|
2545
|
-
this.flushing = false;
|
|
2546
2577
|
}
|
|
2547
2578
|
}
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2579
|
+
getDeliveryStats() {
|
|
2580
|
+
return {
|
|
2581
|
+
acknowledgedEvents: this.acknowledgedEvents,
|
|
2582
|
+
failedBatches: this.failedBatches,
|
|
2583
|
+
droppedEvents: this.droppedEvents,
|
|
2584
|
+
bufferedEvents: this.buffer.length
|
|
2585
|
+
};
|
|
2586
|
+
}
|
|
2587
|
+
/** Stop the timer and give remaining events one final flush. */
|
|
2551
2588
|
async destroy() {
|
|
2552
2589
|
clearInterval(this.flushTimer);
|
|
2590
|
+
if (this.flushPromise) await this.flushPromise;
|
|
2553
2591
|
await this.flush();
|
|
2592
|
+
this.droppedEvents += this.buffer.length;
|
|
2593
|
+
this.buffer.length = 0;
|
|
2554
2594
|
}
|
|
2555
2595
|
};
|
|
2556
2596
|
|
|
@@ -3656,6 +3696,100 @@ function isTestTriggerUserAgent(userAgent) {
|
|
|
3656
3696
|
return userAgent.trimStart().toLowerCase().startsWith(TEST_TRIGGER_UA_PREFIX.toLowerCase());
|
|
3657
3697
|
}
|
|
3658
3698
|
|
|
3699
|
+
// src/offensive-toolchain.ts
|
|
3700
|
+
var TOOLCHAIN_REGISTRY_REVISION = 1;
|
|
3701
|
+
var FRAMEWORK_REGISTRY_REVISION = 5;
|
|
3702
|
+
var reviewedTools = Object.freeze({
|
|
3703
|
+
nmap_scan: "network_reconnaissance",
|
|
3704
|
+
nmap_advanced_scan: "network_reconnaissance",
|
|
3705
|
+
masscan_scan: "network_reconnaissance",
|
|
3706
|
+
nuclei_scan: "vulnerability_scanning",
|
|
3707
|
+
sqlmap_scan: "injection_testing",
|
|
3708
|
+
metasploit_run: "exploitation"
|
|
3709
|
+
});
|
|
3710
|
+
async function createOffensiveToolchainEvidence(input) {
|
|
3711
|
+
const sensor = input.sensor.trim();
|
|
3712
|
+
if (!/^[a-z0-9][a-z0-9_.-]{0,127}$/i.test(sensor)) {
|
|
3713
|
+
throw new Error("sensor must be a 1-128 character stable identifier");
|
|
3714
|
+
}
|
|
3715
|
+
if (!input.runId || input.runId.length > 1024) {
|
|
3716
|
+
throw new Error("runId must be 1-1024 characters");
|
|
3717
|
+
}
|
|
3718
|
+
if (input.correlationSecret.length < 32 || input.correlationSecret.length > 4096) {
|
|
3719
|
+
throw new Error("correlationSecret must be 32-4096 characters");
|
|
3720
|
+
}
|
|
3721
|
+
if (!Array.isArray(input.invocations) || input.invocations.length === 0 || input.invocations.length > 256) {
|
|
3722
|
+
throw new Error("invocations must contain 1-256 entries");
|
|
3723
|
+
}
|
|
3724
|
+
const sequence = [];
|
|
3725
|
+
let redactedArgumentCount = 0;
|
|
3726
|
+
let droppedToolCount = 0;
|
|
3727
|
+
for (const invocation of input.invocations) {
|
|
3728
|
+
if (!invocation.tool || invocation.tool.length > 128) {
|
|
3729
|
+
throw new Error("tool must be 1-128 characters");
|
|
3730
|
+
}
|
|
3731
|
+
const redacted = invocation.redactedArgumentCount ?? 0;
|
|
3732
|
+
if (!Number.isInteger(redacted) || redacted < 0 || redacted > 1024) {
|
|
3733
|
+
throw new Error("redactedArgumentCount must be an integer from 0 through 1024");
|
|
3734
|
+
}
|
|
3735
|
+
const family = reviewedTools[invocation.tool.trim().toLowerCase()];
|
|
3736
|
+
if (!family) {
|
|
3737
|
+
droppedToolCount++;
|
|
3738
|
+
continue;
|
|
3739
|
+
}
|
|
3740
|
+
sequence.push(family);
|
|
3741
|
+
redactedArgumentCount += redacted;
|
|
3742
|
+
if (redactedArgumentCount > 1024) throw new Error("redacted argument count exceeds 1024");
|
|
3743
|
+
}
|
|
3744
|
+
if (sequence.length === 0) throw new Error("no reviewed offensive tools were observed");
|
|
3745
|
+
const families = [...new Set(sequence)].sort();
|
|
3746
|
+
const offensive_toolchain = {
|
|
3747
|
+
schema_version: 1,
|
|
3748
|
+
registry_revision: TOOLCHAIN_REGISTRY_REVISION,
|
|
3749
|
+
plane: "model_api",
|
|
3750
|
+
sensor,
|
|
3751
|
+
run_correlation_id: await hmacSha256Hex(input.correlationSecret, input.runId),
|
|
3752
|
+
tool_families: families,
|
|
3753
|
+
invocation_count: sequence.length,
|
|
3754
|
+
family_set_sha256: await fingerprintIDs(families),
|
|
3755
|
+
sequence_sha256: await sha256Hex(sequence.join("\n")),
|
|
3756
|
+
redacted_argument_count: redactedArgumentCount,
|
|
3757
|
+
dropped_tool_count: droppedToolCount
|
|
3758
|
+
};
|
|
3759
|
+
const evidence = { offensive_toolchain };
|
|
3760
|
+
if (input.orchestrator === "hexstrike_ai") {
|
|
3761
|
+
evidence.framework_evidence = await hexStrikeEvidence();
|
|
3762
|
+
}
|
|
3763
|
+
return evidence;
|
|
3764
|
+
}
|
|
3765
|
+
async function hexStrikeEvidence() {
|
|
3766
|
+
const family = {
|
|
3767
|
+
family_id: "orchestrator_identity",
|
|
3768
|
+
count: 1,
|
|
3769
|
+
sha256: await fingerprintIDs(["hexstrike-ai-mcp"])
|
|
3770
|
+
};
|
|
3771
|
+
return {
|
|
3772
|
+
schema_version: 1,
|
|
3773
|
+
registry_revision: FRAMEWORK_REGISTRY_REVISION,
|
|
3774
|
+
framework: "hexstrike_ai",
|
|
3775
|
+
plane: "model_api",
|
|
3776
|
+
evidence: [family],
|
|
3777
|
+
observation_sha256: await fingerprintEvidence([family])
|
|
3778
|
+
};
|
|
3779
|
+
}
|
|
3780
|
+
async function fingerprintIDs(values) {
|
|
3781
|
+
const canonical = [
|
|
3782
|
+
...new Set(values.map((value) => value.trim().toLowerCase()).filter(Boolean))
|
|
3783
|
+
].sort();
|
|
3784
|
+
return sha256Hex(canonical.join("\n"));
|
|
3785
|
+
}
|
|
3786
|
+
async function fingerprintEvidence(evidence) {
|
|
3787
|
+
const canonical = evidence.map(
|
|
3788
|
+
(value) => `${value.family_id.trim().toLowerCase()}\0${value.count}\0${value.sha256.trim().toLowerCase()}`
|
|
3789
|
+
);
|
|
3790
|
+
return fingerprintIDs(canonical);
|
|
3791
|
+
}
|
|
3792
|
+
|
|
3659
3793
|
// src/sdk.ts
|
|
3660
3794
|
var WebDecoy = class {
|
|
3661
3795
|
constructor(config = {}) {
|
|
@@ -3678,7 +3812,8 @@ var WebDecoy = class {
|
|
|
3678
3812
|
apiKey: config.apiKey,
|
|
3679
3813
|
apiUrl: config.apiUrl || "https://in.webdecoy.com",
|
|
3680
3814
|
enableTLSFingerprinting: config.enableTLSFingerprinting ?? true,
|
|
3681
|
-
|
|
3815
|
+
decisionMode: config.decisionMode ?? "legacy",
|
|
3816
|
+
threatScoreThreshold: config.threatScoreThreshold,
|
|
3682
3817
|
timeout: config.timeout ?? 5e3,
|
|
3683
3818
|
debug: config.debug ?? false,
|
|
3684
3819
|
tlsRejectUnauthorized: config.tlsRejectUnauthorized ?? true,
|
|
@@ -3700,7 +3835,7 @@ var WebDecoy = class {
|
|
|
3700
3835
|
}
|
|
3701
3836
|
this.webBotAuthOptions = config.webBotAuth;
|
|
3702
3837
|
this.characteristics = config.characteristics ?? DEFAULT_CHARACTERISTICS;
|
|
3703
|
-
this.decisionCache = config.decisionCache === false ? null : new DecisionCache(config.decisionCache ?? {});
|
|
3838
|
+
this.decisionCache = config.decisionCache === false || this.config.decisionMode === "unified_v1" ? null : new DecisionCache(config.decisionCache ?? {});
|
|
3704
3839
|
const rules = config.rules ?? [tripwire()];
|
|
3705
3840
|
if (rules.length > 0) {
|
|
3706
3841
|
this.ruleEngine = new RuleEngine(rules);
|
|
@@ -3814,7 +3949,7 @@ var WebDecoy = class {
|
|
|
3814
3949
|
return context;
|
|
3815
3950
|
}
|
|
3816
3951
|
/** Evaluate rules against a prepared context and report any violations. */
|
|
3817
|
-
runRules(context) {
|
|
3952
|
+
runRules(context, reporting) {
|
|
3818
3953
|
if (!this.ruleEngine) return null;
|
|
3819
3954
|
const span = startSpan(this.tracer, "webdecoy.rules");
|
|
3820
3955
|
const result = this.ruleEngine.evaluate(context);
|
|
@@ -3823,8 +3958,17 @@ var WebDecoy = class {
|
|
|
3823
3958
|
setAttribute(span, "webdecoy.rules.violations", result.violations.length);
|
|
3824
3959
|
if (result.rule) setAttribute(span, "webdecoy.rules.deciding", result.rule);
|
|
3825
3960
|
endSpan(span);
|
|
3826
|
-
|
|
3827
|
-
|
|
3961
|
+
const reporter = this.violationReporter;
|
|
3962
|
+
if (reporter && result.violations.length > 0) {
|
|
3963
|
+
const violations = reporting?.mode === "monitor" ? result.violations.map((event) => ({ ...event, dryRun: true, clearance: void 0 })) : result.violations;
|
|
3964
|
+
reporter.report(violations);
|
|
3965
|
+
if (reporting?.waitUntil) {
|
|
3966
|
+
const delivery = Promise.resolve().then(() => reporter.flush()).catch(() => void 0);
|
|
3967
|
+
try {
|
|
3968
|
+
reporting.waitUntil(delivery);
|
|
3969
|
+
} catch {
|
|
3970
|
+
}
|
|
3971
|
+
}
|
|
3828
3972
|
}
|
|
3829
3973
|
return result;
|
|
3830
3974
|
}
|
|
@@ -3923,6 +4067,38 @@ var WebDecoy = class {
|
|
|
3923
4067
|
honeyCredentialFingerprint(tokenId, bearer) {
|
|
3924
4068
|
return hmacSha256Hex(this.config.apiKey, `webdecoy/honey-credential/v1\0${tokenId}\0${bearer}`);
|
|
3925
4069
|
}
|
|
4070
|
+
/**
|
|
4071
|
+
* Report a privacy-bounded model-plane tool run. The helper sends only
|
|
4072
|
+
* reviewed generic families, counts, and digests; it never sends prompts,
|
|
4073
|
+
* arguments, results, credentials, targets, or the raw run ID.
|
|
4074
|
+
*/
|
|
4075
|
+
async reportOffensiveToolchain(input) {
|
|
4076
|
+
if (!this.client) {
|
|
4077
|
+
throw new Error("An apiKey is required to report an offensive toolchain");
|
|
4078
|
+
}
|
|
4079
|
+
const evidence = await createOffensiveToolchainEvidence(input);
|
|
4080
|
+
return this.client.detect({
|
|
4081
|
+
request_metadata: {
|
|
4082
|
+
method: "MODEL",
|
|
4083
|
+
path: "/model-toolchain",
|
|
4084
|
+
// The existing SDK route requires an address. Model-plane evidence has
|
|
4085
|
+
// no target client IP, so use the unspecified address rather than
|
|
4086
|
+
// inventing an identity that could enter actor correlation.
|
|
4087
|
+
ip: "0.0.0.0",
|
|
4088
|
+
headers: {},
|
|
4089
|
+
timestamp: Date.now()
|
|
4090
|
+
},
|
|
4091
|
+
local_analysis: {
|
|
4092
|
+
suspicious_headers: false,
|
|
4093
|
+
missing_sec_ch_ua: false,
|
|
4094
|
+
datacenter_ip: false,
|
|
4095
|
+
local_score: 0,
|
|
4096
|
+
needs_verification: true,
|
|
4097
|
+
flags: ["model_plane_toolchain"]
|
|
4098
|
+
},
|
|
4099
|
+
...evidence
|
|
4100
|
+
});
|
|
4101
|
+
}
|
|
3926
4102
|
/**
|
|
3927
4103
|
* Whether this SDK instance has filter rules that need async enrichment
|
|
3928
4104
|
*/
|
|
@@ -3949,7 +4125,8 @@ var WebDecoy = class {
|
|
|
3949
4125
|
this.referralCounter?.observe(metadata);
|
|
3950
4126
|
const span = startSpan(this.tracer, "webdecoy.protect");
|
|
3951
4127
|
try {
|
|
3952
|
-
|
|
4128
|
+
setAttribute(span, "webdecoy.cloud.decision_mode", this.config.decisionMode);
|
|
4129
|
+
const decision = (await this.decide(metadata, options, span)).withEdge(edge);
|
|
3953
4130
|
setAttribute(span, "webdecoy.decision.id", decision.id);
|
|
3954
4131
|
setAttribute(span, "webdecoy.decision.conclusion", decision.conclusion);
|
|
3955
4132
|
setAttribute(span, "webdecoy.decision.allowed", decision.allowed);
|
|
@@ -3973,7 +4150,7 @@ var WebDecoy = class {
|
|
|
3973
4150
|
endSpan(span);
|
|
3974
4151
|
}
|
|
3975
4152
|
}
|
|
3976
|
-
async decide(metadata, options
|
|
4153
|
+
async decide(metadata, options, span) {
|
|
3977
4154
|
const id = newDecisionId();
|
|
3978
4155
|
let key = metadata.ip || "unknown";
|
|
3979
4156
|
try {
|
|
@@ -3984,14 +4161,16 @@ var WebDecoy = class {
|
|
|
3984
4161
|
metadata.timestamp = Date.now();
|
|
3985
4162
|
}
|
|
3986
4163
|
if (isTestTriggerUserAgent(metadata.user_agent)) {
|
|
4164
|
+
setAttribute(span, "webdecoy.cloud.admission", "test_trigger");
|
|
3987
4165
|
return this.reportTestTrigger(metadata, id);
|
|
3988
4166
|
}
|
|
3989
4167
|
const needsAsync = this._hasFilterRules || this._hasAgentRules || this._preparingRules.length > 0;
|
|
3990
4168
|
const context = needsAsync ? await this.buildAsyncContext(metadata) : this.buildContext(metadata);
|
|
3991
4169
|
key = context.key ?? key;
|
|
3992
4170
|
const agentVerdict = context.agent;
|
|
3993
|
-
const ruleResult = this.ruleEngine ? this.runRules(context) : null;
|
|
4171
|
+
const ruleResult = this.ruleEngine ? this.runRules(context, options.violationReporting) : null;
|
|
3994
4172
|
if (ruleResult && ruleResult.action !== "ALLOW") {
|
|
4173
|
+
setAttribute(span, "webdecoy.cloud.admission", "local_rule");
|
|
3995
4174
|
const throttled = ruleResult.action === "THROTTLE";
|
|
3996
4175
|
return new Decision({
|
|
3997
4176
|
conclusion: "DENY",
|
|
@@ -4012,6 +4191,7 @@ var WebDecoy = class {
|
|
|
4012
4191
|
});
|
|
4013
4192
|
}
|
|
4014
4193
|
if (!this.client) {
|
|
4194
|
+
setAttribute(span, "webdecoy.cloud.admission", "no_api_key");
|
|
4015
4195
|
return new Decision({
|
|
4016
4196
|
conclusion: "ALLOW",
|
|
4017
4197
|
detection: {
|
|
@@ -4030,7 +4210,10 @@ var WebDecoy = class {
|
|
|
4030
4210
|
});
|
|
4031
4211
|
}
|
|
4032
4212
|
const cached = this.decisionCache?.get(key);
|
|
4033
|
-
if (cached)
|
|
4213
|
+
if (cached) {
|
|
4214
|
+
setAttribute(span, "webdecoy.cloud.admission", "cached");
|
|
4215
|
+
return cached.asCached();
|
|
4216
|
+
}
|
|
4034
4217
|
const localAnalysis = options.skipLocalAnalysis ? {
|
|
4035
4218
|
suspicious_headers: false,
|
|
4036
4219
|
missing_sec_ch_ua: false,
|
|
@@ -4040,12 +4223,11 @@ var WebDecoy = class {
|
|
|
4040
4223
|
flags: ["local_analysis_skipped"]
|
|
4041
4224
|
} : analyzeRequest(metadata);
|
|
4042
4225
|
this.log.debug("Local analysis", { ...localAnalysis });
|
|
4043
|
-
const detectionRequest = {
|
|
4044
|
-
request_metadata: metadata,
|
|
4045
|
-
local_analysis: localAnalysis
|
|
4046
|
-
};
|
|
4047
4226
|
const shouldCallServer = localAnalysis.needs_verification || this.config.enableTLSFingerprinting && metadata.tls_info;
|
|
4048
4227
|
if (!shouldCallServer) {
|
|
4228
|
+
setAttribute(span, "webdecoy.cloud.admission", "local_gate");
|
|
4229
|
+
setAttribute(span, "webdecoy.cloud.gate_datacenter_ip", localAnalysis.datacenter_ip);
|
|
4230
|
+
setAttribute(span, "webdecoy.cloud.gate_missing_sec_ch_ua", localAnalysis.missing_sec_ch_ua);
|
|
4049
4231
|
return new Decision({
|
|
4050
4232
|
conclusion: "ALLOW",
|
|
4051
4233
|
detection: {
|
|
@@ -4063,8 +4245,14 @@ var WebDecoy = class {
|
|
|
4063
4245
|
key
|
|
4064
4246
|
});
|
|
4065
4247
|
}
|
|
4066
|
-
const
|
|
4067
|
-
|
|
4248
|
+
const unified = this.config.decisionMode === "unified_v1";
|
|
4249
|
+
setAttribute(span, "webdecoy.cloud.admission", "cloud");
|
|
4250
|
+
const detection = await this.client.detect({
|
|
4251
|
+
request_metadata: metadata,
|
|
4252
|
+
local_analysis: localAnalysis,
|
|
4253
|
+
...unified && { decision_mode: "unified_v1" }
|
|
4254
|
+
});
|
|
4255
|
+
const threshold = options.threshold ?? this.config.threatScoreThreshold ?? (unified ? 0 : 80);
|
|
4068
4256
|
const allowed = detection.decision === "allow" || detection.confidence < threshold;
|
|
4069
4257
|
this.log.debug("Server detection", {
|
|
4070
4258
|
decision: detection.decision,
|
|
@@ -4074,7 +4262,7 @@ var WebDecoy = class {
|
|
|
4074
4262
|
const conclusion = allowed ? "ALLOW" : detection.decision === "challenge" ? "CHALLENGE" : "DENY";
|
|
4075
4263
|
const decision = new Decision({
|
|
4076
4264
|
conclusion,
|
|
4077
|
-
reason: allowed ? void 0 : `Threat score ${detection.confidence} (threshold ${threshold})`,
|
|
4265
|
+
reason: allowed ? void 0 : unified ? `Unified verdict ${detection.decision} (score ${detection.unified_score}, confidence ${detection.confidence})` : `Threat score ${detection.confidence} (threshold ${threshold})`,
|
|
4078
4266
|
detection,
|
|
4079
4267
|
id,
|
|
4080
4268
|
results: ruleResult?.results ?? [],
|
|
@@ -4086,6 +4274,9 @@ var WebDecoy = class {
|
|
|
4086
4274
|
if (this.decisionCache) this.decisionCache.set(key, decision);
|
|
4087
4275
|
return decision;
|
|
4088
4276
|
} catch (error) {
|
|
4277
|
+
if (error instanceof WebDecoyUnavailableError) {
|
|
4278
|
+
setAttribute(span, "webdecoy.cloud.admission", "backoff");
|
|
4279
|
+
}
|
|
4089
4280
|
const log = error instanceof WebDecoyUnavailableError ? this.log.debug.bind(this.log) : this.log.error.bind(this.log);
|
|
4090
4281
|
log("Protection error", {
|
|
4091
4282
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -4139,6 +4330,7 @@ var WebDecoy = class {
|
|
|
4139
4330
|
try {
|
|
4140
4331
|
const detection = await this.client.detect({
|
|
4141
4332
|
request_metadata: metadata,
|
|
4333
|
+
...this.config.decisionMode === "unified_v1" && { decision_mode: "unified_v1" },
|
|
4142
4334
|
local_analysis: {
|
|
4143
4335
|
suspicious_headers: false,
|
|
4144
4336
|
missing_sec_ch_ua: false,
|
|
@@ -4189,6 +4381,10 @@ var WebDecoy = class {
|
|
|
4189
4381
|
setViolationReporter(reporter) {
|
|
4190
4382
|
this.violationReporter = reporter;
|
|
4191
4383
|
}
|
|
4384
|
+
/** Snapshot of this instance's violation delivery, when reporting is enabled. */
|
|
4385
|
+
getViolationDeliveryStats() {
|
|
4386
|
+
return this.violationReporter?.getDeliveryStats?.();
|
|
4387
|
+
}
|
|
4192
4388
|
/**
|
|
4193
4389
|
* Get the API client (for use by violation reporter, enrichment, etc.)
|
|
4194
4390
|
*/
|
|
@@ -4340,7 +4536,8 @@ function createFetchGuard(options = {}) {
|
|
|
4340
4536
|
const decision = await sdk.protect(metadata, {
|
|
4341
4537
|
threshold: options.threshold,
|
|
4342
4538
|
skipLocalAnalysis: options.skipLocalAnalysis,
|
|
4343
|
-
metadata: options.metadata
|
|
4539
|
+
metadata: options.metadata,
|
|
4540
|
+
violationReporting: { mode }
|
|
4344
4541
|
});
|
|
4345
4542
|
if (decision.allowed || mode !== "enforce") return { decision };
|
|
4346
4543
|
return { decision, response: await onBlocked(request, decision) };
|
package/dist/vercel.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdecoy/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Bot detection and AI agent verification for Node.js and edge runtimes. Local honeypot tripwires, rate limiting and AI crawler policies, with optional WebDecoy dashboard reporting.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|