@webdecoy/node 0.25.2 → 0.26.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/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
- return response.data;
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", {
@@ -1032,6 +1036,10 @@ function toHex(bytes) {
1032
1036
  for (let i = 0; i < bytes.length; i++) hex += bytes[i].toString(16).padStart(2, "0");
1033
1037
  return hex;
1034
1038
  }
1039
+ async function sha256Hex(data) {
1040
+ const digest2 = await crypto.subtle.digest("SHA-256", encoder.encode(data));
1041
+ return toHex(new Uint8Array(digest2));
1042
+ }
1035
1043
  async function hmacSha256Hex(secret, data) {
1036
1044
  const key = await crypto.subtle.importKey(
1037
1045
  "raw",
@@ -2232,6 +2240,100 @@ function isTestTriggerUserAgent(userAgent) {
2232
2240
  return userAgent.trimStart().toLowerCase().startsWith(TEST_TRIGGER_UA_PREFIX.toLowerCase());
2233
2241
  }
2234
2242
 
2243
+ // src/offensive-toolchain.ts
2244
+ var TOOLCHAIN_REGISTRY_REVISION = 1;
2245
+ var FRAMEWORK_REGISTRY_REVISION = 5;
2246
+ var reviewedTools = Object.freeze({
2247
+ nmap_scan: "network_reconnaissance",
2248
+ nmap_advanced_scan: "network_reconnaissance",
2249
+ masscan_scan: "network_reconnaissance",
2250
+ nuclei_scan: "vulnerability_scanning",
2251
+ sqlmap_scan: "injection_testing",
2252
+ metasploit_run: "exploitation"
2253
+ });
2254
+ async function createOffensiveToolchainEvidence(input) {
2255
+ const sensor = input.sensor.trim();
2256
+ if (!/^[a-z0-9][a-z0-9_.-]{0,127}$/i.test(sensor)) {
2257
+ throw new Error("sensor must be a 1-128 character stable identifier");
2258
+ }
2259
+ if (!input.runId || input.runId.length > 1024) {
2260
+ throw new Error("runId must be 1-1024 characters");
2261
+ }
2262
+ if (input.correlationSecret.length < 32 || input.correlationSecret.length > 4096) {
2263
+ throw new Error("correlationSecret must be 32-4096 characters");
2264
+ }
2265
+ if (!Array.isArray(input.invocations) || input.invocations.length === 0 || input.invocations.length > 256) {
2266
+ throw new Error("invocations must contain 1-256 entries");
2267
+ }
2268
+ const sequence = [];
2269
+ let redactedArgumentCount = 0;
2270
+ let droppedToolCount = 0;
2271
+ for (const invocation of input.invocations) {
2272
+ if (!invocation.tool || invocation.tool.length > 128) {
2273
+ throw new Error("tool must be 1-128 characters");
2274
+ }
2275
+ const redacted = invocation.redactedArgumentCount ?? 0;
2276
+ if (!Number.isInteger(redacted) || redacted < 0 || redacted > 1024) {
2277
+ throw new Error("redactedArgumentCount must be an integer from 0 through 1024");
2278
+ }
2279
+ const family = reviewedTools[invocation.tool.trim().toLowerCase()];
2280
+ if (!family) {
2281
+ droppedToolCount++;
2282
+ continue;
2283
+ }
2284
+ sequence.push(family);
2285
+ redactedArgumentCount += redacted;
2286
+ if (redactedArgumentCount > 1024) throw new Error("redacted argument count exceeds 1024");
2287
+ }
2288
+ if (sequence.length === 0) throw new Error("no reviewed offensive tools were observed");
2289
+ const families = [...new Set(sequence)].sort();
2290
+ const offensive_toolchain = {
2291
+ schema_version: 1,
2292
+ registry_revision: TOOLCHAIN_REGISTRY_REVISION,
2293
+ plane: "model_api",
2294
+ sensor,
2295
+ run_correlation_id: await hmacSha256Hex(input.correlationSecret, input.runId),
2296
+ tool_families: families,
2297
+ invocation_count: sequence.length,
2298
+ family_set_sha256: await fingerprintIDs(families),
2299
+ sequence_sha256: await sha256Hex(sequence.join("\n")),
2300
+ redacted_argument_count: redactedArgumentCount,
2301
+ dropped_tool_count: droppedToolCount
2302
+ };
2303
+ const evidence = { offensive_toolchain };
2304
+ if (input.orchestrator === "hexstrike_ai") {
2305
+ evidence.framework_evidence = await hexStrikeEvidence();
2306
+ }
2307
+ return evidence;
2308
+ }
2309
+ async function hexStrikeEvidence() {
2310
+ const family = {
2311
+ family_id: "orchestrator_identity",
2312
+ count: 1,
2313
+ sha256: await fingerprintIDs(["hexstrike-ai-mcp"])
2314
+ };
2315
+ return {
2316
+ schema_version: 1,
2317
+ registry_revision: FRAMEWORK_REGISTRY_REVISION,
2318
+ framework: "hexstrike_ai",
2319
+ plane: "model_api",
2320
+ evidence: [family],
2321
+ observation_sha256: await fingerprintEvidence([family])
2322
+ };
2323
+ }
2324
+ async function fingerprintIDs(values) {
2325
+ const canonical = [
2326
+ ...new Set(values.map((value) => value.trim().toLowerCase()).filter(Boolean))
2327
+ ].sort();
2328
+ return sha256Hex(canonical.join("\n"));
2329
+ }
2330
+ async function fingerprintEvidence(evidence) {
2331
+ const canonical = evidence.map(
2332
+ (value) => `${value.family_id.trim().toLowerCase()}\0${value.count}\0${value.sha256.trim().toLowerCase()}`
2333
+ );
2334
+ return fingerprintIDs(canonical);
2335
+ }
2336
+
2235
2337
  // src/sdk.ts
2236
2338
  var WebDecoy = class {
2237
2339
  constructor(config = {}) {
@@ -2254,7 +2356,8 @@ var WebDecoy = class {
2254
2356
  apiKey: config.apiKey,
2255
2357
  apiUrl: config.apiUrl || "https://in.webdecoy.com",
2256
2358
  enableTLSFingerprinting: config.enableTLSFingerprinting ?? true,
2257
- threatScoreThreshold: config.threatScoreThreshold ?? 80,
2359
+ decisionMode: config.decisionMode ?? "legacy",
2360
+ threatScoreThreshold: config.threatScoreThreshold,
2258
2361
  timeout: config.timeout ?? 5e3,
2259
2362
  debug: config.debug ?? false,
2260
2363
  tlsRejectUnauthorized: config.tlsRejectUnauthorized ?? true,
@@ -2276,7 +2379,7 @@ var WebDecoy = class {
2276
2379
  }
2277
2380
  this.webBotAuthOptions = config.webBotAuth;
2278
2381
  this.characteristics = config.characteristics ?? DEFAULT_CHARACTERISTICS;
2279
- this.decisionCache = config.decisionCache === false ? null : new DecisionCache(config.decisionCache ?? {});
2382
+ this.decisionCache = config.decisionCache === false || this.config.decisionMode === "unified_v1" ? null : new DecisionCache(config.decisionCache ?? {});
2280
2383
  const rules = config.rules ?? [tripwire()];
2281
2384
  if (rules.length > 0) {
2282
2385
  this.ruleEngine = new RuleEngine(rules);
@@ -2499,6 +2602,38 @@ var WebDecoy = class {
2499
2602
  honeyCredentialFingerprint(tokenId, bearer) {
2500
2603
  return hmacSha256Hex(this.config.apiKey, `webdecoy/honey-credential/v1\0${tokenId}\0${bearer}`);
2501
2604
  }
2605
+ /**
2606
+ * Report a privacy-bounded model-plane tool run. The helper sends only
2607
+ * reviewed generic families, counts, and digests; it never sends prompts,
2608
+ * arguments, results, credentials, targets, or the raw run ID.
2609
+ */
2610
+ async reportOffensiveToolchain(input) {
2611
+ if (!this.client) {
2612
+ throw new Error("An apiKey is required to report an offensive toolchain");
2613
+ }
2614
+ const evidence = await createOffensiveToolchainEvidence(input);
2615
+ return this.client.detect({
2616
+ request_metadata: {
2617
+ method: "MODEL",
2618
+ path: "/model-toolchain",
2619
+ // The existing SDK route requires an address. Model-plane evidence has
2620
+ // no target client IP, so use the unspecified address rather than
2621
+ // inventing an identity that could enter actor correlation.
2622
+ ip: "0.0.0.0",
2623
+ headers: {},
2624
+ timestamp: Date.now()
2625
+ },
2626
+ local_analysis: {
2627
+ suspicious_headers: false,
2628
+ missing_sec_ch_ua: false,
2629
+ datacenter_ip: false,
2630
+ local_score: 0,
2631
+ needs_verification: true,
2632
+ flags: ["model_plane_toolchain"]
2633
+ },
2634
+ ...evidence
2635
+ });
2636
+ }
2502
2637
  /**
2503
2638
  * Whether this SDK instance has filter rules that need async enrichment
2504
2639
  */
@@ -2525,7 +2660,8 @@ var WebDecoy = class {
2525
2660
  this.referralCounter?.observe(metadata);
2526
2661
  const span = startSpan(this.tracer, "webdecoy.protect");
2527
2662
  try {
2528
- const decision = (await this.decide(metadata, options)).withEdge(edge);
2663
+ setAttribute(span, "webdecoy.cloud.decision_mode", this.config.decisionMode);
2664
+ const decision = (await this.decide(metadata, options, span)).withEdge(edge);
2529
2665
  setAttribute(span, "webdecoy.decision.id", decision.id);
2530
2666
  setAttribute(span, "webdecoy.decision.conclusion", decision.conclusion);
2531
2667
  setAttribute(span, "webdecoy.decision.allowed", decision.allowed);
@@ -2549,7 +2685,7 @@ var WebDecoy = class {
2549
2685
  endSpan(span);
2550
2686
  }
2551
2687
  }
2552
- async decide(metadata, options = {}) {
2688
+ async decide(metadata, options, span) {
2553
2689
  const id = newDecisionId();
2554
2690
  let key = metadata.ip || "unknown";
2555
2691
  try {
@@ -2560,6 +2696,7 @@ var WebDecoy = class {
2560
2696
  metadata.timestamp = Date.now();
2561
2697
  }
2562
2698
  if (isTestTriggerUserAgent(metadata.user_agent)) {
2699
+ setAttribute(span, "webdecoy.cloud.admission", "test_trigger");
2563
2700
  return this.reportTestTrigger(metadata, id);
2564
2701
  }
2565
2702
  const needsAsync = this._hasFilterRules || this._hasAgentRules || this._preparingRules.length > 0;
@@ -2568,6 +2705,7 @@ var WebDecoy = class {
2568
2705
  const agentVerdict = context.agent;
2569
2706
  const ruleResult = this.ruleEngine ? this.runRules(context) : null;
2570
2707
  if (ruleResult && ruleResult.action !== "ALLOW") {
2708
+ setAttribute(span, "webdecoy.cloud.admission", "local_rule");
2571
2709
  const throttled = ruleResult.action === "THROTTLE";
2572
2710
  return new Decision({
2573
2711
  conclusion: "DENY",
@@ -2588,6 +2726,7 @@ var WebDecoy = class {
2588
2726
  });
2589
2727
  }
2590
2728
  if (!this.client) {
2729
+ setAttribute(span, "webdecoy.cloud.admission", "no_api_key");
2591
2730
  return new Decision({
2592
2731
  conclusion: "ALLOW",
2593
2732
  detection: {
@@ -2606,7 +2745,10 @@ var WebDecoy = class {
2606
2745
  });
2607
2746
  }
2608
2747
  const cached = this.decisionCache?.get(key);
2609
- if (cached) return cached.asCached();
2748
+ if (cached) {
2749
+ setAttribute(span, "webdecoy.cloud.admission", "cached");
2750
+ return cached.asCached();
2751
+ }
2610
2752
  const localAnalysis = options.skipLocalAnalysis ? {
2611
2753
  suspicious_headers: false,
2612
2754
  missing_sec_ch_ua: false,
@@ -2616,12 +2758,11 @@ var WebDecoy = class {
2616
2758
  flags: ["local_analysis_skipped"]
2617
2759
  } : analyzeRequest(metadata);
2618
2760
  this.log.debug("Local analysis", { ...localAnalysis });
2619
- const detectionRequest = {
2620
- request_metadata: metadata,
2621
- local_analysis: localAnalysis
2622
- };
2623
2761
  const shouldCallServer = localAnalysis.needs_verification || this.config.enableTLSFingerprinting && metadata.tls_info;
2624
2762
  if (!shouldCallServer) {
2763
+ setAttribute(span, "webdecoy.cloud.admission", "local_gate");
2764
+ setAttribute(span, "webdecoy.cloud.gate_datacenter_ip", localAnalysis.datacenter_ip);
2765
+ setAttribute(span, "webdecoy.cloud.gate_missing_sec_ch_ua", localAnalysis.missing_sec_ch_ua);
2625
2766
  return new Decision({
2626
2767
  conclusion: "ALLOW",
2627
2768
  detection: {
@@ -2639,8 +2780,14 @@ var WebDecoy = class {
2639
2780
  key
2640
2781
  });
2641
2782
  }
2642
- const detection = await this.client.detect(detectionRequest);
2643
- const threshold = options.threshold ?? this.config.threatScoreThreshold;
2783
+ const unified = this.config.decisionMode === "unified_v1";
2784
+ setAttribute(span, "webdecoy.cloud.admission", "cloud");
2785
+ const detection = await this.client.detect({
2786
+ request_metadata: metadata,
2787
+ local_analysis: localAnalysis,
2788
+ ...unified && { decision_mode: "unified_v1" }
2789
+ });
2790
+ const threshold = options.threshold ?? this.config.threatScoreThreshold ?? (unified ? 0 : 80);
2644
2791
  const allowed = detection.decision === "allow" || detection.confidence < threshold;
2645
2792
  this.log.debug("Server detection", {
2646
2793
  decision: detection.decision,
@@ -2650,7 +2797,7 @@ var WebDecoy = class {
2650
2797
  const conclusion = allowed ? "ALLOW" : detection.decision === "challenge" ? "CHALLENGE" : "DENY";
2651
2798
  const decision = new Decision({
2652
2799
  conclusion,
2653
- reason: allowed ? void 0 : `Threat score ${detection.confidence} (threshold ${threshold})`,
2800
+ reason: allowed ? void 0 : unified ? `Unified verdict ${detection.decision} (score ${detection.unified_score}, confidence ${detection.confidence})` : `Threat score ${detection.confidence} (threshold ${threshold})`,
2654
2801
  detection,
2655
2802
  id,
2656
2803
  results: ruleResult?.results ?? [],
@@ -2662,6 +2809,9 @@ var WebDecoy = class {
2662
2809
  if (this.decisionCache) this.decisionCache.set(key, decision);
2663
2810
  return decision;
2664
2811
  } catch (error) {
2812
+ if (error instanceof WebDecoyUnavailableError) {
2813
+ setAttribute(span, "webdecoy.cloud.admission", "backoff");
2814
+ }
2665
2815
  const log = error instanceof WebDecoyUnavailableError ? this.log.debug.bind(this.log) : this.log.error.bind(this.log);
2666
2816
  log("Protection error", {
2667
2817
  error: error instanceof Error ? error.message : String(error)
@@ -2715,6 +2865,7 @@ var WebDecoy = class {
2715
2865
  try {
2716
2866
  const detection = await this.client.detect({
2717
2867
  request_metadata: metadata,
2868
+ ...this.config.decisionMode === "unified_v1" && { decision_mode: "unified_v1" },
2718
2869
  local_analysis: {
2719
2870
  suspicious_headers: false,
2720
2871
  missing_sec_ch_ua: false,
package/dist/testing.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  WebDecoy,
3
3
  silentLogger
4
- } from "./chunk-AUHVIVMA.mjs";
4
+ } from "./chunk-2SIFEEYE.mjs";
5
5
 
6
6
  // src/testing.ts
7
7
  function request(over = {}) {
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-B1HMK-Sd.mjs';
2
- import './sdk-UlKzxL3L.mjs';
1
+ import { a as ClearanceGateOptions, C as ClearanceContext, D as DetectAndGateOptions, d as GateOutcome } from './detect-and-gate-NBeqXdH6.mjs';
2
+ import './sdk-Dh8Jj07-.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-B4KDPdyP.js';
2
- import './sdk-UlKzxL3L.js';
1
+ import { a as ClearanceGateOptions, C as ClearanceContext, D as DetectAndGateOptions, d as GateOutcome } from './detect-and-gate-Ay294Lr2.js';
2
+ import './sdk-Dh8Jj07-.js';
3
3
 
4
4
  /**
5
5
  * WebDecoy for Vercel Routing Middleware, any framework.
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
- return response.data;
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", {
@@ -2394,6 +2398,10 @@ function toHex(bytes) {
2394
2398
  for (let i = 0; i < bytes.length; i++) hex += bytes[i].toString(16).padStart(2, "0");
2395
2399
  return hex;
2396
2400
  }
2401
+ async function sha256Hex(data) {
2402
+ const digest2 = await crypto.subtle.digest("SHA-256", encoder.encode(data));
2403
+ return toHex(new Uint8Array(digest2));
2404
+ }
2397
2405
  async function hmacSha256Hex(secret, data) {
2398
2406
  const key = await crypto.subtle.importKey(
2399
2407
  "raw",
@@ -3656,6 +3664,100 @@ function isTestTriggerUserAgent(userAgent) {
3656
3664
  return userAgent.trimStart().toLowerCase().startsWith(TEST_TRIGGER_UA_PREFIX.toLowerCase());
3657
3665
  }
3658
3666
 
3667
+ // src/offensive-toolchain.ts
3668
+ var TOOLCHAIN_REGISTRY_REVISION = 1;
3669
+ var FRAMEWORK_REGISTRY_REVISION = 5;
3670
+ var reviewedTools = Object.freeze({
3671
+ nmap_scan: "network_reconnaissance",
3672
+ nmap_advanced_scan: "network_reconnaissance",
3673
+ masscan_scan: "network_reconnaissance",
3674
+ nuclei_scan: "vulnerability_scanning",
3675
+ sqlmap_scan: "injection_testing",
3676
+ metasploit_run: "exploitation"
3677
+ });
3678
+ async function createOffensiveToolchainEvidence(input) {
3679
+ const sensor = input.sensor.trim();
3680
+ if (!/^[a-z0-9][a-z0-9_.-]{0,127}$/i.test(sensor)) {
3681
+ throw new Error("sensor must be a 1-128 character stable identifier");
3682
+ }
3683
+ if (!input.runId || input.runId.length > 1024) {
3684
+ throw new Error("runId must be 1-1024 characters");
3685
+ }
3686
+ if (input.correlationSecret.length < 32 || input.correlationSecret.length > 4096) {
3687
+ throw new Error("correlationSecret must be 32-4096 characters");
3688
+ }
3689
+ if (!Array.isArray(input.invocations) || input.invocations.length === 0 || input.invocations.length > 256) {
3690
+ throw new Error("invocations must contain 1-256 entries");
3691
+ }
3692
+ const sequence = [];
3693
+ let redactedArgumentCount = 0;
3694
+ let droppedToolCount = 0;
3695
+ for (const invocation of input.invocations) {
3696
+ if (!invocation.tool || invocation.tool.length > 128) {
3697
+ throw new Error("tool must be 1-128 characters");
3698
+ }
3699
+ const redacted = invocation.redactedArgumentCount ?? 0;
3700
+ if (!Number.isInteger(redacted) || redacted < 0 || redacted > 1024) {
3701
+ throw new Error("redactedArgumentCount must be an integer from 0 through 1024");
3702
+ }
3703
+ const family = reviewedTools[invocation.tool.trim().toLowerCase()];
3704
+ if (!family) {
3705
+ droppedToolCount++;
3706
+ continue;
3707
+ }
3708
+ sequence.push(family);
3709
+ redactedArgumentCount += redacted;
3710
+ if (redactedArgumentCount > 1024) throw new Error("redacted argument count exceeds 1024");
3711
+ }
3712
+ if (sequence.length === 0) throw new Error("no reviewed offensive tools were observed");
3713
+ const families = [...new Set(sequence)].sort();
3714
+ const offensive_toolchain = {
3715
+ schema_version: 1,
3716
+ registry_revision: TOOLCHAIN_REGISTRY_REVISION,
3717
+ plane: "model_api",
3718
+ sensor,
3719
+ run_correlation_id: await hmacSha256Hex(input.correlationSecret, input.runId),
3720
+ tool_families: families,
3721
+ invocation_count: sequence.length,
3722
+ family_set_sha256: await fingerprintIDs(families),
3723
+ sequence_sha256: await sha256Hex(sequence.join("\n")),
3724
+ redacted_argument_count: redactedArgumentCount,
3725
+ dropped_tool_count: droppedToolCount
3726
+ };
3727
+ const evidence = { offensive_toolchain };
3728
+ if (input.orchestrator === "hexstrike_ai") {
3729
+ evidence.framework_evidence = await hexStrikeEvidence();
3730
+ }
3731
+ return evidence;
3732
+ }
3733
+ async function hexStrikeEvidence() {
3734
+ const family = {
3735
+ family_id: "orchestrator_identity",
3736
+ count: 1,
3737
+ sha256: await fingerprintIDs(["hexstrike-ai-mcp"])
3738
+ };
3739
+ return {
3740
+ schema_version: 1,
3741
+ registry_revision: FRAMEWORK_REGISTRY_REVISION,
3742
+ framework: "hexstrike_ai",
3743
+ plane: "model_api",
3744
+ evidence: [family],
3745
+ observation_sha256: await fingerprintEvidence([family])
3746
+ };
3747
+ }
3748
+ async function fingerprintIDs(values) {
3749
+ const canonical = [
3750
+ ...new Set(values.map((value) => value.trim().toLowerCase()).filter(Boolean))
3751
+ ].sort();
3752
+ return sha256Hex(canonical.join("\n"));
3753
+ }
3754
+ async function fingerprintEvidence(evidence) {
3755
+ const canonical = evidence.map(
3756
+ (value) => `${value.family_id.trim().toLowerCase()}\0${value.count}\0${value.sha256.trim().toLowerCase()}`
3757
+ );
3758
+ return fingerprintIDs(canonical);
3759
+ }
3760
+
3659
3761
  // src/sdk.ts
3660
3762
  var WebDecoy = class {
3661
3763
  constructor(config = {}) {
@@ -3678,7 +3780,8 @@ var WebDecoy = class {
3678
3780
  apiKey: config.apiKey,
3679
3781
  apiUrl: config.apiUrl || "https://in.webdecoy.com",
3680
3782
  enableTLSFingerprinting: config.enableTLSFingerprinting ?? true,
3681
- threatScoreThreshold: config.threatScoreThreshold ?? 80,
3783
+ decisionMode: config.decisionMode ?? "legacy",
3784
+ threatScoreThreshold: config.threatScoreThreshold,
3682
3785
  timeout: config.timeout ?? 5e3,
3683
3786
  debug: config.debug ?? false,
3684
3787
  tlsRejectUnauthorized: config.tlsRejectUnauthorized ?? true,
@@ -3700,7 +3803,7 @@ var WebDecoy = class {
3700
3803
  }
3701
3804
  this.webBotAuthOptions = config.webBotAuth;
3702
3805
  this.characteristics = config.characteristics ?? DEFAULT_CHARACTERISTICS;
3703
- this.decisionCache = config.decisionCache === false ? null : new DecisionCache(config.decisionCache ?? {});
3806
+ this.decisionCache = config.decisionCache === false || this.config.decisionMode === "unified_v1" ? null : new DecisionCache(config.decisionCache ?? {});
3704
3807
  const rules = config.rules ?? [tripwire()];
3705
3808
  if (rules.length > 0) {
3706
3809
  this.ruleEngine = new RuleEngine(rules);
@@ -3923,6 +4026,38 @@ var WebDecoy = class {
3923
4026
  honeyCredentialFingerprint(tokenId, bearer) {
3924
4027
  return hmacSha256Hex(this.config.apiKey, `webdecoy/honey-credential/v1\0${tokenId}\0${bearer}`);
3925
4028
  }
4029
+ /**
4030
+ * Report a privacy-bounded model-plane tool run. The helper sends only
4031
+ * reviewed generic families, counts, and digests; it never sends prompts,
4032
+ * arguments, results, credentials, targets, or the raw run ID.
4033
+ */
4034
+ async reportOffensiveToolchain(input) {
4035
+ if (!this.client) {
4036
+ throw new Error("An apiKey is required to report an offensive toolchain");
4037
+ }
4038
+ const evidence = await createOffensiveToolchainEvidence(input);
4039
+ return this.client.detect({
4040
+ request_metadata: {
4041
+ method: "MODEL",
4042
+ path: "/model-toolchain",
4043
+ // The existing SDK route requires an address. Model-plane evidence has
4044
+ // no target client IP, so use the unspecified address rather than
4045
+ // inventing an identity that could enter actor correlation.
4046
+ ip: "0.0.0.0",
4047
+ headers: {},
4048
+ timestamp: Date.now()
4049
+ },
4050
+ local_analysis: {
4051
+ suspicious_headers: false,
4052
+ missing_sec_ch_ua: false,
4053
+ datacenter_ip: false,
4054
+ local_score: 0,
4055
+ needs_verification: true,
4056
+ flags: ["model_plane_toolchain"]
4057
+ },
4058
+ ...evidence
4059
+ });
4060
+ }
3926
4061
  /**
3927
4062
  * Whether this SDK instance has filter rules that need async enrichment
3928
4063
  */
@@ -3949,7 +4084,8 @@ var WebDecoy = class {
3949
4084
  this.referralCounter?.observe(metadata);
3950
4085
  const span = startSpan(this.tracer, "webdecoy.protect");
3951
4086
  try {
3952
- const decision = (await this.decide(metadata, options)).withEdge(edge);
4087
+ setAttribute(span, "webdecoy.cloud.decision_mode", this.config.decisionMode);
4088
+ const decision = (await this.decide(metadata, options, span)).withEdge(edge);
3953
4089
  setAttribute(span, "webdecoy.decision.id", decision.id);
3954
4090
  setAttribute(span, "webdecoy.decision.conclusion", decision.conclusion);
3955
4091
  setAttribute(span, "webdecoy.decision.allowed", decision.allowed);
@@ -3973,7 +4109,7 @@ var WebDecoy = class {
3973
4109
  endSpan(span);
3974
4110
  }
3975
4111
  }
3976
- async decide(metadata, options = {}) {
4112
+ async decide(metadata, options, span) {
3977
4113
  const id = newDecisionId();
3978
4114
  let key = metadata.ip || "unknown";
3979
4115
  try {
@@ -3984,6 +4120,7 @@ var WebDecoy = class {
3984
4120
  metadata.timestamp = Date.now();
3985
4121
  }
3986
4122
  if (isTestTriggerUserAgent(metadata.user_agent)) {
4123
+ setAttribute(span, "webdecoy.cloud.admission", "test_trigger");
3987
4124
  return this.reportTestTrigger(metadata, id);
3988
4125
  }
3989
4126
  const needsAsync = this._hasFilterRules || this._hasAgentRules || this._preparingRules.length > 0;
@@ -3992,6 +4129,7 @@ var WebDecoy = class {
3992
4129
  const agentVerdict = context.agent;
3993
4130
  const ruleResult = this.ruleEngine ? this.runRules(context) : null;
3994
4131
  if (ruleResult && ruleResult.action !== "ALLOW") {
4132
+ setAttribute(span, "webdecoy.cloud.admission", "local_rule");
3995
4133
  const throttled = ruleResult.action === "THROTTLE";
3996
4134
  return new Decision({
3997
4135
  conclusion: "DENY",
@@ -4012,6 +4150,7 @@ var WebDecoy = class {
4012
4150
  });
4013
4151
  }
4014
4152
  if (!this.client) {
4153
+ setAttribute(span, "webdecoy.cloud.admission", "no_api_key");
4015
4154
  return new Decision({
4016
4155
  conclusion: "ALLOW",
4017
4156
  detection: {
@@ -4030,7 +4169,10 @@ var WebDecoy = class {
4030
4169
  });
4031
4170
  }
4032
4171
  const cached = this.decisionCache?.get(key);
4033
- if (cached) return cached.asCached();
4172
+ if (cached) {
4173
+ setAttribute(span, "webdecoy.cloud.admission", "cached");
4174
+ return cached.asCached();
4175
+ }
4034
4176
  const localAnalysis = options.skipLocalAnalysis ? {
4035
4177
  suspicious_headers: false,
4036
4178
  missing_sec_ch_ua: false,
@@ -4040,12 +4182,11 @@ var WebDecoy = class {
4040
4182
  flags: ["local_analysis_skipped"]
4041
4183
  } : analyzeRequest(metadata);
4042
4184
  this.log.debug("Local analysis", { ...localAnalysis });
4043
- const detectionRequest = {
4044
- request_metadata: metadata,
4045
- local_analysis: localAnalysis
4046
- };
4047
4185
  const shouldCallServer = localAnalysis.needs_verification || this.config.enableTLSFingerprinting && metadata.tls_info;
4048
4186
  if (!shouldCallServer) {
4187
+ setAttribute(span, "webdecoy.cloud.admission", "local_gate");
4188
+ setAttribute(span, "webdecoy.cloud.gate_datacenter_ip", localAnalysis.datacenter_ip);
4189
+ setAttribute(span, "webdecoy.cloud.gate_missing_sec_ch_ua", localAnalysis.missing_sec_ch_ua);
4049
4190
  return new Decision({
4050
4191
  conclusion: "ALLOW",
4051
4192
  detection: {
@@ -4063,8 +4204,14 @@ var WebDecoy = class {
4063
4204
  key
4064
4205
  });
4065
4206
  }
4066
- const detection = await this.client.detect(detectionRequest);
4067
- const threshold = options.threshold ?? this.config.threatScoreThreshold;
4207
+ const unified = this.config.decisionMode === "unified_v1";
4208
+ setAttribute(span, "webdecoy.cloud.admission", "cloud");
4209
+ const detection = await this.client.detect({
4210
+ request_metadata: metadata,
4211
+ local_analysis: localAnalysis,
4212
+ ...unified && { decision_mode: "unified_v1" }
4213
+ });
4214
+ const threshold = options.threshold ?? this.config.threatScoreThreshold ?? (unified ? 0 : 80);
4068
4215
  const allowed = detection.decision === "allow" || detection.confidence < threshold;
4069
4216
  this.log.debug("Server detection", {
4070
4217
  decision: detection.decision,
@@ -4074,7 +4221,7 @@ var WebDecoy = class {
4074
4221
  const conclusion = allowed ? "ALLOW" : detection.decision === "challenge" ? "CHALLENGE" : "DENY";
4075
4222
  const decision = new Decision({
4076
4223
  conclusion,
4077
- reason: allowed ? void 0 : `Threat score ${detection.confidence} (threshold ${threshold})`,
4224
+ reason: allowed ? void 0 : unified ? `Unified verdict ${detection.decision} (score ${detection.unified_score}, confidence ${detection.confidence})` : `Threat score ${detection.confidence} (threshold ${threshold})`,
4078
4225
  detection,
4079
4226
  id,
4080
4227
  results: ruleResult?.results ?? [],
@@ -4086,6 +4233,9 @@ var WebDecoy = class {
4086
4233
  if (this.decisionCache) this.decisionCache.set(key, decision);
4087
4234
  return decision;
4088
4235
  } catch (error) {
4236
+ if (error instanceof WebDecoyUnavailableError) {
4237
+ setAttribute(span, "webdecoy.cloud.admission", "backoff");
4238
+ }
4089
4239
  const log = error instanceof WebDecoyUnavailableError ? this.log.debug.bind(this.log) : this.log.error.bind(this.log);
4090
4240
  log("Protection error", {
4091
4241
  error: error instanceof Error ? error.message : String(error)
@@ -4139,6 +4289,7 @@ var WebDecoy = class {
4139
4289
  try {
4140
4290
  const detection = await this.client.detect({
4141
4291
  request_metadata: metadata,
4292
+ ...this.config.decisionMode === "unified_v1" && { decision_mode: "unified_v1" },
4142
4293
  local_analysis: {
4143
4294
  suspicious_headers: false,
4144
4295
  missing_sec_ch_ua: false,
package/dist/vercel.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createClearanceGate,
3
3
  createDetectAndGate
4
- } from "./chunk-G5WMRJSQ.mjs";
5
- import "./chunk-AUHVIVMA.mjs";
4
+ } from "./chunk-CFJ7R2CG.mjs";
5
+ import "./chunk-2SIFEEYE.mjs";
6
6
 
7
7
  // src/vercel.ts
8
8
  function toMiddlewareResponse(outcome) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webdecoy/node",
3
- "version": "0.25.2",
3
+ "version": "0.26.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",