@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/README.md
CHANGED
|
@@ -103,6 +103,33 @@ credential is sent. A presentation request is made only when the candidate is
|
|
|
103
103
|
an exact local match for the inert token. Retrieval alone remains an ordinary
|
|
104
104
|
decoy event, and this API never blocks or grants access.
|
|
105
105
|
|
|
106
|
+
### Correlate an offensive model toolchain
|
|
107
|
+
|
|
108
|
+
Instrument an authorized model/MCP gateway with the reviewed helper. It maps
|
|
109
|
+
known tool names into generic families and sends only bounded counts and
|
|
110
|
+
digests. Raw prompts, arguments, results, targets, credentials, and run IDs are
|
|
111
|
+
not included. Use a deployment-held random secret of at least 32 characters for
|
|
112
|
+
`correlationSecret`; do not reuse an API key.
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
const result = await wd.reportOffensiveToolchain({
|
|
116
|
+
sensor: 'mcp-gateway',
|
|
117
|
+
runId: internalRunId,
|
|
118
|
+
correlationSecret: process.env.WEBDECOY_CORRELATION_SECRET!,
|
|
119
|
+
invocations: [
|
|
120
|
+
{ tool: 'nmap_scan', redactedArgumentCount: 2 },
|
|
121
|
+
{ tool: 'nuclei_scan', redactedArgumentCount: 1 },
|
|
122
|
+
],
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
One tool family is retained for coverage but does not create a correlation.
|
|
127
|
+
Two or more reviewed families can create a generic toolchain association. Set
|
|
128
|
+
`orchestrator: 'hexstrike_ai'` only inside an integration that has independently
|
|
129
|
+
verified the official `hexstrike-ai-mcp` orchestrator; common Nmap or Nuclei use
|
|
130
|
+
alone never becomes HexStrike attribution. This API records evidence and never
|
|
131
|
+
blocks or grants access.
|
|
132
|
+
|
|
106
133
|
### Monitor first
|
|
107
134
|
|
|
108
135
|
`protect()` only returns a decision. It never writes a response, so nothing is blocked until your code acts on `decision.allowed`. The framework adapters and `createFetchGuard()` follow the same rule: they start in **monitor mode** (`mode: 'monitor'`), record the decision and serve every request. Set `mode: 'enforce'` only after you have reviewed what would have been blocked.
|
|
@@ -167,6 +194,12 @@ const wd = new WebDecoy({
|
|
|
167
194
|
|
|
168
195
|
A tripwire match is evidence, not proof of intent: link prefetchers, preview bots and your own security scanners can request a hidden or scanner-bait path. Use `dryRun: true` on a rule to observe it before enforcing.
|
|
169
196
|
|
|
197
|
+
### Rule violation delivery
|
|
198
|
+
|
|
199
|
+
Local rules decide the request before the SDK reports their events. With an API key, the SDK sends rule violations to ingest in batches. Rate limits and rule dry runs are violation events. Framework adapters mark monitor-mode violations as dry runs and omit tripwire clearance tokens. An enforced tripwire denial can also appear in Detections.
|
|
200
|
+
|
|
201
|
+
For a long-lived SDK instance, call `getViolationDeliveryStats()` for counts of events acknowledged by ingest, failed batches, discarded events, and events waiting for an attempt. Call `await sdk.destroy()` during graceful shutdown to finish an in-flight send and attempt the remaining queue. Reporting has a fixed in-memory buffer. When the client pauses after a failure, unattempted events stay buffered. An attempted batch with an uncertain acknowledgment is discarded to avoid replaying its server-side effects.
|
|
202
|
+
|
|
170
203
|
## Fetch runtimes (Bun, Deno, Workers, Astro, SvelteKit, Remix)
|
|
171
204
|
|
|
172
205
|
`createFetchGuard()` wraps the SDK for any runtime that hands you a WHATWG `Request`. It is the same implementation `@webdecoy/hono` uses.
|
|
@@ -237,7 +270,8 @@ const wd = new WebDecoy({
|
|
|
237
270
|
apiKey: process.env.WEBDECOY_API_KEY, // optional; without it, local rules only
|
|
238
271
|
rules: [tripwire()], // optional; default [tripwire()], [] to opt out
|
|
239
272
|
apiUrl: 'https://in.webdecoy.com', // optional (default shown)
|
|
240
|
-
|
|
273
|
+
decisionMode: 'legacy', // use 'unified_v1' to opt in
|
|
274
|
+
threatScoreThreshold: 80, // optional minimum confidence, default 80 in legacy mode
|
|
241
275
|
timeout: 5000, // optional, ms (default 5000)
|
|
242
276
|
enableTLSFingerprinting: true, // optional (default true)
|
|
243
277
|
tlsRejectUnauthorized: true, // optional (default true)
|
|
@@ -250,6 +284,14 @@ Also accepted: `characteristics` (what identifies the same caller for rate limit
|
|
|
250
284
|
|
|
251
285
|
`protect()` also takes per-request options: `threshold`, `skipLocalAnalysis` and `metadata`.
|
|
252
286
|
|
|
287
|
+
### Unified cloud decisions
|
|
288
|
+
|
|
289
|
+
Set `decisionMode: 'unified_v1'` on `WebDecoy`, `createFetchGuard()`, or the Express, Fastify, Hono, and Next.js adapters. Adapter monitor mode exposes the verdict on `webdecoyDecision` while serving the request. `decision.detection.unified_score` is the score at request time. Later enrichment can update the detection in the dashboard.
|
|
290
|
+
|
|
291
|
+
Ingest applies its own confidence gates. An explicit `threshold`, `threatScoreThreshold`, or Next.js Pages `blockThreshold` can add a minimum confidence. Cloud-eligible requests each get their own unified verdict, including repeats from the same caller. During a cloud outage or an invalid response, the request proceeds with an `ERROR` decision.
|
|
292
|
+
|
|
293
|
+
Local rules decide first. The cloud gate forwards requests with a local bot signal, TLS material, or an explicit `skipLocalAnalysis` bypass. A datacenter IP or a missing Sec-CH-UA alone stays local. With `tracer` configured, count `webdecoy.cloud.admission` by `webdecoy.cloud.decision_mode`. The `local_gate` outcome includes two booleans for the datacenter and missing Sec-CH-UA observations. `cloud` records requests handed to the client and `backoff` records calls skipped during an outage. These attributes contain only bounded outcomes and booleans.
|
|
294
|
+
|
|
253
295
|
Without an API key no request leaves your server. With one, a request goes to WebDecoy only when local analysis flags it as needing verification (or carries TLS details); that call is awaited, bounded by `timeout`, and fails open on error.
|
|
254
296
|
|
|
255
297
|
## Client IP behind a proxy
|
|
@@ -2636,6 +2636,100 @@ function isTestTriggerUserAgent(userAgent) {
|
|
|
2636
2636
|
return userAgent.trimStart().toLowerCase().startsWith(TEST_TRIGGER_UA_PREFIX.toLowerCase());
|
|
2637
2637
|
}
|
|
2638
2638
|
|
|
2639
|
+
// src/offensive-toolchain.ts
|
|
2640
|
+
var TOOLCHAIN_REGISTRY_REVISION = 1;
|
|
2641
|
+
var FRAMEWORK_REGISTRY_REVISION = 5;
|
|
2642
|
+
var reviewedTools = Object.freeze({
|
|
2643
|
+
nmap_scan: "network_reconnaissance",
|
|
2644
|
+
nmap_advanced_scan: "network_reconnaissance",
|
|
2645
|
+
masscan_scan: "network_reconnaissance",
|
|
2646
|
+
nuclei_scan: "vulnerability_scanning",
|
|
2647
|
+
sqlmap_scan: "injection_testing",
|
|
2648
|
+
metasploit_run: "exploitation"
|
|
2649
|
+
});
|
|
2650
|
+
async function createOffensiveToolchainEvidence(input) {
|
|
2651
|
+
const sensor = input.sensor.trim();
|
|
2652
|
+
if (!/^[a-z0-9][a-z0-9_.-]{0,127}$/i.test(sensor)) {
|
|
2653
|
+
throw new Error("sensor must be a 1-128 character stable identifier");
|
|
2654
|
+
}
|
|
2655
|
+
if (!input.runId || input.runId.length > 1024) {
|
|
2656
|
+
throw new Error("runId must be 1-1024 characters");
|
|
2657
|
+
}
|
|
2658
|
+
if (input.correlationSecret.length < 32 || input.correlationSecret.length > 4096) {
|
|
2659
|
+
throw new Error("correlationSecret must be 32-4096 characters");
|
|
2660
|
+
}
|
|
2661
|
+
if (!Array.isArray(input.invocations) || input.invocations.length === 0 || input.invocations.length > 256) {
|
|
2662
|
+
throw new Error("invocations must contain 1-256 entries");
|
|
2663
|
+
}
|
|
2664
|
+
const sequence = [];
|
|
2665
|
+
let redactedArgumentCount = 0;
|
|
2666
|
+
let droppedToolCount = 0;
|
|
2667
|
+
for (const invocation of input.invocations) {
|
|
2668
|
+
if (!invocation.tool || invocation.tool.length > 128) {
|
|
2669
|
+
throw new Error("tool must be 1-128 characters");
|
|
2670
|
+
}
|
|
2671
|
+
const redacted = invocation.redactedArgumentCount ?? 0;
|
|
2672
|
+
if (!Number.isInteger(redacted) || redacted < 0 || redacted > 1024) {
|
|
2673
|
+
throw new Error("redactedArgumentCount must be an integer from 0 through 1024");
|
|
2674
|
+
}
|
|
2675
|
+
const family = reviewedTools[invocation.tool.trim().toLowerCase()];
|
|
2676
|
+
if (!family) {
|
|
2677
|
+
droppedToolCount++;
|
|
2678
|
+
continue;
|
|
2679
|
+
}
|
|
2680
|
+
sequence.push(family);
|
|
2681
|
+
redactedArgumentCount += redacted;
|
|
2682
|
+
if (redactedArgumentCount > 1024) throw new Error("redacted argument count exceeds 1024");
|
|
2683
|
+
}
|
|
2684
|
+
if (sequence.length === 0) throw new Error("no reviewed offensive tools were observed");
|
|
2685
|
+
const families = [...new Set(sequence)].sort();
|
|
2686
|
+
const offensive_toolchain = {
|
|
2687
|
+
schema_version: 1,
|
|
2688
|
+
registry_revision: TOOLCHAIN_REGISTRY_REVISION,
|
|
2689
|
+
plane: "model_api",
|
|
2690
|
+
sensor,
|
|
2691
|
+
run_correlation_id: await hmacSha256Hex(input.correlationSecret, input.runId),
|
|
2692
|
+
tool_families: families,
|
|
2693
|
+
invocation_count: sequence.length,
|
|
2694
|
+
family_set_sha256: await fingerprintIDs(families),
|
|
2695
|
+
sequence_sha256: await sha256Hex(sequence.join("\n")),
|
|
2696
|
+
redacted_argument_count: redactedArgumentCount,
|
|
2697
|
+
dropped_tool_count: droppedToolCount
|
|
2698
|
+
};
|
|
2699
|
+
const evidence = { offensive_toolchain };
|
|
2700
|
+
if (input.orchestrator === "hexstrike_ai") {
|
|
2701
|
+
evidence.framework_evidence = await hexStrikeEvidence();
|
|
2702
|
+
}
|
|
2703
|
+
return evidence;
|
|
2704
|
+
}
|
|
2705
|
+
async function hexStrikeEvidence() {
|
|
2706
|
+
const family = {
|
|
2707
|
+
family_id: "orchestrator_identity",
|
|
2708
|
+
count: 1,
|
|
2709
|
+
sha256: await fingerprintIDs(["hexstrike-ai-mcp"])
|
|
2710
|
+
};
|
|
2711
|
+
return {
|
|
2712
|
+
schema_version: 1,
|
|
2713
|
+
registry_revision: FRAMEWORK_REGISTRY_REVISION,
|
|
2714
|
+
framework: "hexstrike_ai",
|
|
2715
|
+
plane: "model_api",
|
|
2716
|
+
evidence: [family],
|
|
2717
|
+
observation_sha256: await fingerprintEvidence([family])
|
|
2718
|
+
};
|
|
2719
|
+
}
|
|
2720
|
+
async function fingerprintIDs(values) {
|
|
2721
|
+
const canonical = [
|
|
2722
|
+
...new Set(values.map((value) => value.trim().toLowerCase()).filter(Boolean))
|
|
2723
|
+
].sort();
|
|
2724
|
+
return sha256Hex(canonical.join("\n"));
|
|
2725
|
+
}
|
|
2726
|
+
async function fingerprintEvidence(evidence) {
|
|
2727
|
+
const canonical = evidence.map(
|
|
2728
|
+
(value) => `${value.family_id.trim().toLowerCase()}\0${value.count}\0${value.sha256.trim().toLowerCase()}`
|
|
2729
|
+
);
|
|
2730
|
+
return fingerprintIDs(canonical);
|
|
2731
|
+
}
|
|
2732
|
+
|
|
2639
2733
|
// src/report-headers.ts
|
|
2640
2734
|
var CREDENTIAL_HEADER = /cookie|auth|token|secret|passw|session|credential|csrf|xsrf|api[-_]?key|access[-_]?key|private[-_]?key/i;
|
|
2641
2735
|
var CLEARANCE_COOKIE = "wd_clearance";
|
|
@@ -2785,7 +2879,11 @@ var WebDecoyClient = class {
|
|
|
2785
2879
|
}
|
|
2786
2880
|
throw new Error(`API request failed: HTTP ${response.status}`);
|
|
2787
2881
|
}
|
|
2788
|
-
|
|
2882
|
+
const detection = response.data;
|
|
2883
|
+
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)) {
|
|
2884
|
+
throw new Error("WebDecoy did not return a valid unified decision");
|
|
2885
|
+
}
|
|
2886
|
+
return detection;
|
|
2789
2887
|
}
|
|
2790
2888
|
async createSSRFCanary(options) {
|
|
2791
2889
|
const response = await this.request("POST", "/api/v1/sdk/ssrf/markers", {
|
|
@@ -2872,13 +2970,22 @@ var WebDecoyClient = class {
|
|
|
2872
2970
|
* Send violation events to the ingest service
|
|
2873
2971
|
*/
|
|
2874
2972
|
async sendViolations(events) {
|
|
2973
|
+
await this.sendViolationBatch(events);
|
|
2974
|
+
}
|
|
2975
|
+
/** Acknowledgment from ingest for one batch. Transport failures resolve false. */
|
|
2976
|
+
async sendViolationBatch(events) {
|
|
2875
2977
|
try {
|
|
2876
|
-
await this.request("POST", "/api/v1/sdk/violations/batch", { events });
|
|
2978
|
+
const { status } = await this.request("POST", "/api/v1/sdk/violations/batch", { events });
|
|
2979
|
+
if (status >= 200 && status < 300) return true;
|
|
2980
|
+
if (this.config.debug) {
|
|
2981
|
+
console.warn(`[WebDecoy] Violation batch returned HTTP ${status}`);
|
|
2982
|
+
}
|
|
2877
2983
|
} catch (error) {
|
|
2878
2984
|
if (this.config.debug) {
|
|
2879
2985
|
console.error("[WebDecoy] Failed to send violations:", error);
|
|
2880
2986
|
}
|
|
2881
2987
|
}
|
|
2988
|
+
return false;
|
|
2882
2989
|
}
|
|
2883
2990
|
/**
|
|
2884
2991
|
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
@@ -3084,7 +3191,9 @@ var MAX_BUFFERED_VIOLATIONS = 1e3;
|
|
|
3084
3191
|
var ViolationReporter = class {
|
|
3085
3192
|
constructor(client, config = {}) {
|
|
3086
3193
|
this.buffer = [];
|
|
3087
|
-
this.
|
|
3194
|
+
this.acknowledgedEvents = 0;
|
|
3195
|
+
this.failedBatches = 0;
|
|
3196
|
+
this.droppedEvents = 0;
|
|
3088
3197
|
this.client = client;
|
|
3089
3198
|
this.maxBufferSize = config.maxBufferSize ?? 50;
|
|
3090
3199
|
this.debug = config.debug ?? false;
|
|
@@ -3100,42 +3209,63 @@ var ViolationReporter = class {
|
|
|
3100
3209
|
report(violations) {
|
|
3101
3210
|
this.buffer.push(...violations);
|
|
3102
3211
|
if (this.buffer.length > MAX_BUFFERED_VIOLATIONS) {
|
|
3103
|
-
|
|
3212
|
+
const overflow = this.buffer.length - MAX_BUFFERED_VIOLATIONS;
|
|
3213
|
+
this.buffer.splice(0, overflow);
|
|
3214
|
+
this.droppedEvents += overflow;
|
|
3104
3215
|
}
|
|
3105
3216
|
if (this.buffer.length >= this.maxBufferSize) {
|
|
3106
3217
|
this.flush().catch(() => {
|
|
3107
3218
|
});
|
|
3108
3219
|
}
|
|
3109
3220
|
}
|
|
3110
|
-
/**
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3221
|
+
/** Flush the buffer, coalescing requests that arrive during an active send. */
|
|
3222
|
+
flush() {
|
|
3223
|
+
if (this.queuedFlush) return this.queuedFlush;
|
|
3224
|
+
if (this.flushPromise) {
|
|
3225
|
+
if (this.buffer.length === 0 || !this.client.isAvailable()) return this.flushPromise;
|
|
3226
|
+
this.queuedFlush = this.flushPromise.then(() => {
|
|
3227
|
+
this.queuedFlush = void 0;
|
|
3228
|
+
return this.flush();
|
|
3229
|
+
});
|
|
3230
|
+
return this.queuedFlush;
|
|
3231
|
+
}
|
|
3232
|
+
if (this.buffer.length === 0 || !this.client.isAvailable()) return Promise.resolve();
|
|
3233
|
+
const size = this.buffer.length;
|
|
3234
|
+
this.flushPromise = Promise.resolve().then(() => this.flushBatches(size)).finally(() => {
|
|
3235
|
+
this.flushPromise = void 0;
|
|
3236
|
+
});
|
|
3237
|
+
return this.flushPromise;
|
|
3238
|
+
}
|
|
3239
|
+
async flushBatches(remaining) {
|
|
3240
|
+
while (remaining > 0 && this.buffer.length > 0 && this.client.isAvailable()) {
|
|
3241
|
+
const batch = this.buffer.splice(0, Math.min(100, remaining));
|
|
3242
|
+
remaining -= batch.length;
|
|
3243
|
+
if (await this.client.sendViolationBatch(batch)) {
|
|
3244
|
+
this.acknowledgedEvents += batch.length;
|
|
3121
3245
|
if (this.debug) {
|
|
3122
3246
|
console.log(`[WebDecoy] Flushed ${batch.length} violation events`);
|
|
3123
3247
|
}
|
|
3248
|
+
} else {
|
|
3249
|
+
this.failedBatches++;
|
|
3250
|
+
this.droppedEvents += batch.length;
|
|
3124
3251
|
}
|
|
3125
|
-
} catch (error) {
|
|
3126
|
-
if (this.debug) {
|
|
3127
|
-
console.error("[WebDecoy] Failed to flush violations:", error);
|
|
3128
|
-
}
|
|
3129
|
-
} finally {
|
|
3130
|
-
this.flushing = false;
|
|
3131
3252
|
}
|
|
3132
3253
|
}
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3254
|
+
getDeliveryStats() {
|
|
3255
|
+
return {
|
|
3256
|
+
acknowledgedEvents: this.acknowledgedEvents,
|
|
3257
|
+
failedBatches: this.failedBatches,
|
|
3258
|
+
droppedEvents: this.droppedEvents,
|
|
3259
|
+
bufferedEvents: this.buffer.length
|
|
3260
|
+
};
|
|
3261
|
+
}
|
|
3262
|
+
/** Stop the timer and give remaining events one final flush. */
|
|
3136
3263
|
async destroy() {
|
|
3137
3264
|
clearInterval(this.flushTimer);
|
|
3265
|
+
if (this.flushPromise) await this.flushPromise;
|
|
3138
3266
|
await this.flush();
|
|
3267
|
+
this.droppedEvents += this.buffer.length;
|
|
3268
|
+
this.buffer.length = 0;
|
|
3139
3269
|
}
|
|
3140
3270
|
};
|
|
3141
3271
|
|
|
@@ -3390,7 +3520,8 @@ var WebDecoy = class {
|
|
|
3390
3520
|
apiKey: config.apiKey,
|
|
3391
3521
|
apiUrl: config.apiUrl || "https://in.webdecoy.com",
|
|
3392
3522
|
enableTLSFingerprinting: config.enableTLSFingerprinting ?? true,
|
|
3393
|
-
|
|
3523
|
+
decisionMode: config.decisionMode ?? "legacy",
|
|
3524
|
+
threatScoreThreshold: config.threatScoreThreshold,
|
|
3394
3525
|
timeout: config.timeout ?? 5e3,
|
|
3395
3526
|
debug: config.debug ?? false,
|
|
3396
3527
|
tlsRejectUnauthorized: config.tlsRejectUnauthorized ?? true,
|
|
@@ -3412,7 +3543,7 @@ var WebDecoy = class {
|
|
|
3412
3543
|
}
|
|
3413
3544
|
this.webBotAuthOptions = config.webBotAuth;
|
|
3414
3545
|
this.characteristics = config.characteristics ?? DEFAULT_CHARACTERISTICS;
|
|
3415
|
-
this.decisionCache = config.decisionCache === false ? null : new DecisionCache(config.decisionCache ?? {});
|
|
3546
|
+
this.decisionCache = config.decisionCache === false || this.config.decisionMode === "unified_v1" ? null : new DecisionCache(config.decisionCache ?? {});
|
|
3416
3547
|
const rules = config.rules ?? [tripwire()];
|
|
3417
3548
|
if (rules.length > 0) {
|
|
3418
3549
|
this.ruleEngine = new RuleEngine(rules);
|
|
@@ -3526,7 +3657,7 @@ var WebDecoy = class {
|
|
|
3526
3657
|
return context;
|
|
3527
3658
|
}
|
|
3528
3659
|
/** Evaluate rules against a prepared context and report any violations. */
|
|
3529
|
-
runRules(context) {
|
|
3660
|
+
runRules(context, reporting) {
|
|
3530
3661
|
if (!this.ruleEngine) return null;
|
|
3531
3662
|
const span = startSpan(this.tracer, "webdecoy.rules");
|
|
3532
3663
|
const result = this.ruleEngine.evaluate(context);
|
|
@@ -3535,8 +3666,17 @@ var WebDecoy = class {
|
|
|
3535
3666
|
setAttribute(span, "webdecoy.rules.violations", result.violations.length);
|
|
3536
3667
|
if (result.rule) setAttribute(span, "webdecoy.rules.deciding", result.rule);
|
|
3537
3668
|
endSpan(span);
|
|
3538
|
-
|
|
3539
|
-
|
|
3669
|
+
const reporter = this.violationReporter;
|
|
3670
|
+
if (reporter && result.violations.length > 0) {
|
|
3671
|
+
const violations = reporting?.mode === "monitor" ? result.violations.map((event) => ({ ...event, dryRun: true, clearance: void 0 })) : result.violations;
|
|
3672
|
+
reporter.report(violations);
|
|
3673
|
+
if (reporting?.waitUntil) {
|
|
3674
|
+
const delivery = Promise.resolve().then(() => reporter.flush()).catch(() => void 0);
|
|
3675
|
+
try {
|
|
3676
|
+
reporting.waitUntil(delivery);
|
|
3677
|
+
} catch {
|
|
3678
|
+
}
|
|
3679
|
+
}
|
|
3540
3680
|
}
|
|
3541
3681
|
return result;
|
|
3542
3682
|
}
|
|
@@ -3635,6 +3775,38 @@ var WebDecoy = class {
|
|
|
3635
3775
|
honeyCredentialFingerprint(tokenId, bearer) {
|
|
3636
3776
|
return hmacSha256Hex(this.config.apiKey, `webdecoy/honey-credential/v1\0${tokenId}\0${bearer}`);
|
|
3637
3777
|
}
|
|
3778
|
+
/**
|
|
3779
|
+
* Report a privacy-bounded model-plane tool run. The helper sends only
|
|
3780
|
+
* reviewed generic families, counts, and digests; it never sends prompts,
|
|
3781
|
+
* arguments, results, credentials, targets, or the raw run ID.
|
|
3782
|
+
*/
|
|
3783
|
+
async reportOffensiveToolchain(input) {
|
|
3784
|
+
if (!this.client) {
|
|
3785
|
+
throw new Error("An apiKey is required to report an offensive toolchain");
|
|
3786
|
+
}
|
|
3787
|
+
const evidence = await createOffensiveToolchainEvidence(input);
|
|
3788
|
+
return this.client.detect({
|
|
3789
|
+
request_metadata: {
|
|
3790
|
+
method: "MODEL",
|
|
3791
|
+
path: "/model-toolchain",
|
|
3792
|
+
// The existing SDK route requires an address. Model-plane evidence has
|
|
3793
|
+
// no target client IP, so use the unspecified address rather than
|
|
3794
|
+
// inventing an identity that could enter actor correlation.
|
|
3795
|
+
ip: "0.0.0.0",
|
|
3796
|
+
headers: {},
|
|
3797
|
+
timestamp: Date.now()
|
|
3798
|
+
},
|
|
3799
|
+
local_analysis: {
|
|
3800
|
+
suspicious_headers: false,
|
|
3801
|
+
missing_sec_ch_ua: false,
|
|
3802
|
+
datacenter_ip: false,
|
|
3803
|
+
local_score: 0,
|
|
3804
|
+
needs_verification: true,
|
|
3805
|
+
flags: ["model_plane_toolchain"]
|
|
3806
|
+
},
|
|
3807
|
+
...evidence
|
|
3808
|
+
});
|
|
3809
|
+
}
|
|
3638
3810
|
/**
|
|
3639
3811
|
* Whether this SDK instance has filter rules that need async enrichment
|
|
3640
3812
|
*/
|
|
@@ -3661,7 +3833,8 @@ var WebDecoy = class {
|
|
|
3661
3833
|
this.referralCounter?.observe(metadata);
|
|
3662
3834
|
const span = startSpan(this.tracer, "webdecoy.protect");
|
|
3663
3835
|
try {
|
|
3664
|
-
|
|
3836
|
+
setAttribute(span, "webdecoy.cloud.decision_mode", this.config.decisionMode);
|
|
3837
|
+
const decision = (await this.decide(metadata, options, span)).withEdge(edge);
|
|
3665
3838
|
setAttribute(span, "webdecoy.decision.id", decision.id);
|
|
3666
3839
|
setAttribute(span, "webdecoy.decision.conclusion", decision.conclusion);
|
|
3667
3840
|
setAttribute(span, "webdecoy.decision.allowed", decision.allowed);
|
|
@@ -3685,7 +3858,7 @@ var WebDecoy = class {
|
|
|
3685
3858
|
endSpan(span);
|
|
3686
3859
|
}
|
|
3687
3860
|
}
|
|
3688
|
-
async decide(metadata, options
|
|
3861
|
+
async decide(metadata, options, span) {
|
|
3689
3862
|
const id = newDecisionId();
|
|
3690
3863
|
let key = metadata.ip || "unknown";
|
|
3691
3864
|
try {
|
|
@@ -3696,14 +3869,16 @@ var WebDecoy = class {
|
|
|
3696
3869
|
metadata.timestamp = Date.now();
|
|
3697
3870
|
}
|
|
3698
3871
|
if (isTestTriggerUserAgent(metadata.user_agent)) {
|
|
3872
|
+
setAttribute(span, "webdecoy.cloud.admission", "test_trigger");
|
|
3699
3873
|
return this.reportTestTrigger(metadata, id);
|
|
3700
3874
|
}
|
|
3701
3875
|
const needsAsync = this._hasFilterRules || this._hasAgentRules || this._preparingRules.length > 0;
|
|
3702
3876
|
const context = needsAsync ? await this.buildAsyncContext(metadata) : this.buildContext(metadata);
|
|
3703
3877
|
key = context.key ?? key;
|
|
3704
3878
|
const agentVerdict = context.agent;
|
|
3705
|
-
const ruleResult = this.ruleEngine ? this.runRules(context) : null;
|
|
3879
|
+
const ruleResult = this.ruleEngine ? this.runRules(context, options.violationReporting) : null;
|
|
3706
3880
|
if (ruleResult && ruleResult.action !== "ALLOW") {
|
|
3881
|
+
setAttribute(span, "webdecoy.cloud.admission", "local_rule");
|
|
3707
3882
|
const throttled = ruleResult.action === "THROTTLE";
|
|
3708
3883
|
return new Decision({
|
|
3709
3884
|
conclusion: "DENY",
|
|
@@ -3724,6 +3899,7 @@ var WebDecoy = class {
|
|
|
3724
3899
|
});
|
|
3725
3900
|
}
|
|
3726
3901
|
if (!this.client) {
|
|
3902
|
+
setAttribute(span, "webdecoy.cloud.admission", "no_api_key");
|
|
3727
3903
|
return new Decision({
|
|
3728
3904
|
conclusion: "ALLOW",
|
|
3729
3905
|
detection: {
|
|
@@ -3742,7 +3918,10 @@ var WebDecoy = class {
|
|
|
3742
3918
|
});
|
|
3743
3919
|
}
|
|
3744
3920
|
const cached = this.decisionCache?.get(key);
|
|
3745
|
-
if (cached)
|
|
3921
|
+
if (cached) {
|
|
3922
|
+
setAttribute(span, "webdecoy.cloud.admission", "cached");
|
|
3923
|
+
return cached.asCached();
|
|
3924
|
+
}
|
|
3746
3925
|
const localAnalysis = options.skipLocalAnalysis ? {
|
|
3747
3926
|
suspicious_headers: false,
|
|
3748
3927
|
missing_sec_ch_ua: false,
|
|
@@ -3752,12 +3931,11 @@ var WebDecoy = class {
|
|
|
3752
3931
|
flags: ["local_analysis_skipped"]
|
|
3753
3932
|
} : analyzeRequest(metadata);
|
|
3754
3933
|
this.log.debug("Local analysis", { ...localAnalysis });
|
|
3755
|
-
const detectionRequest = {
|
|
3756
|
-
request_metadata: metadata,
|
|
3757
|
-
local_analysis: localAnalysis
|
|
3758
|
-
};
|
|
3759
3934
|
const shouldCallServer = localAnalysis.needs_verification || this.config.enableTLSFingerprinting && metadata.tls_info;
|
|
3760
3935
|
if (!shouldCallServer) {
|
|
3936
|
+
setAttribute(span, "webdecoy.cloud.admission", "local_gate");
|
|
3937
|
+
setAttribute(span, "webdecoy.cloud.gate_datacenter_ip", localAnalysis.datacenter_ip);
|
|
3938
|
+
setAttribute(span, "webdecoy.cloud.gate_missing_sec_ch_ua", localAnalysis.missing_sec_ch_ua);
|
|
3761
3939
|
return new Decision({
|
|
3762
3940
|
conclusion: "ALLOW",
|
|
3763
3941
|
detection: {
|
|
@@ -3775,8 +3953,14 @@ var WebDecoy = class {
|
|
|
3775
3953
|
key
|
|
3776
3954
|
});
|
|
3777
3955
|
}
|
|
3778
|
-
const
|
|
3779
|
-
|
|
3956
|
+
const unified = this.config.decisionMode === "unified_v1";
|
|
3957
|
+
setAttribute(span, "webdecoy.cloud.admission", "cloud");
|
|
3958
|
+
const detection = await this.client.detect({
|
|
3959
|
+
request_metadata: metadata,
|
|
3960
|
+
local_analysis: localAnalysis,
|
|
3961
|
+
...unified && { decision_mode: "unified_v1" }
|
|
3962
|
+
});
|
|
3963
|
+
const threshold = options.threshold ?? this.config.threatScoreThreshold ?? (unified ? 0 : 80);
|
|
3780
3964
|
const allowed = detection.decision === "allow" || detection.confidence < threshold;
|
|
3781
3965
|
this.log.debug("Server detection", {
|
|
3782
3966
|
decision: detection.decision,
|
|
@@ -3786,7 +3970,7 @@ var WebDecoy = class {
|
|
|
3786
3970
|
const conclusion = allowed ? "ALLOW" : detection.decision === "challenge" ? "CHALLENGE" : "DENY";
|
|
3787
3971
|
const decision = new Decision({
|
|
3788
3972
|
conclusion,
|
|
3789
|
-
reason: allowed ? void 0 : `Threat score ${detection.confidence} (threshold ${threshold})`,
|
|
3973
|
+
reason: allowed ? void 0 : unified ? `Unified verdict ${detection.decision} (score ${detection.unified_score}, confidence ${detection.confidence})` : `Threat score ${detection.confidence} (threshold ${threshold})`,
|
|
3790
3974
|
detection,
|
|
3791
3975
|
id,
|
|
3792
3976
|
results: ruleResult?.results ?? [],
|
|
@@ -3798,6 +3982,9 @@ var WebDecoy = class {
|
|
|
3798
3982
|
if (this.decisionCache) this.decisionCache.set(key, decision);
|
|
3799
3983
|
return decision;
|
|
3800
3984
|
} catch (error) {
|
|
3985
|
+
if (error instanceof WebDecoyUnavailableError) {
|
|
3986
|
+
setAttribute(span, "webdecoy.cloud.admission", "backoff");
|
|
3987
|
+
}
|
|
3801
3988
|
const log = error instanceof WebDecoyUnavailableError ? this.log.debug.bind(this.log) : this.log.error.bind(this.log);
|
|
3802
3989
|
log("Protection error", {
|
|
3803
3990
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -3851,6 +4038,7 @@ var WebDecoy = class {
|
|
|
3851
4038
|
try {
|
|
3852
4039
|
const detection = await this.client.detect({
|
|
3853
4040
|
request_metadata: metadata,
|
|
4041
|
+
...this.config.decisionMode === "unified_v1" && { decision_mode: "unified_v1" },
|
|
3854
4042
|
local_analysis: {
|
|
3855
4043
|
suspicious_headers: false,
|
|
3856
4044
|
missing_sec_ch_ua: false,
|
|
@@ -3901,6 +4089,10 @@ var WebDecoy = class {
|
|
|
3901
4089
|
setViolationReporter(reporter) {
|
|
3902
4090
|
this.violationReporter = reporter;
|
|
3903
4091
|
}
|
|
4092
|
+
/** Snapshot of this instance's violation delivery, when reporting is enabled. */
|
|
4093
|
+
getViolationDeliveryStats() {
|
|
4094
|
+
return this.violationReporter?.getDeliveryStats?.();
|
|
4095
|
+
}
|
|
3904
4096
|
/**
|
|
3905
4097
|
* Get the API client (for use by violation reporter, enrichment, etc.)
|
|
3906
4098
|
*/
|
|
@@ -3998,5 +4190,6 @@ export {
|
|
|
3998
4190
|
TEST_TRIGGER_UA_PREFIX,
|
|
3999
4191
|
TEST_TRIGGER_USER_AGENT,
|
|
4000
4192
|
isTestTriggerUserAgent,
|
|
4193
|
+
createOffensiveToolchainEvidence,
|
|
4001
4194
|
WebDecoy
|
|
4002
4195
|
};
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
isInjectableHtml,
|
|
5
5
|
siteHoneytoken,
|
|
6
6
|
tripwire
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-32TEUD5K.mjs";
|
|
8
8
|
|
|
9
9
|
// src/client-ip.ts
|
|
10
10
|
var IPV4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
|
|
@@ -1482,7 +1482,8 @@ function createFetchGuard(options = {}) {
|
|
|
1482
1482
|
const decision = await sdk.protect(metadata, {
|
|
1483
1483
|
threshold: options.threshold,
|
|
1484
1484
|
skipLocalAnalysis: options.skipLocalAnalysis,
|
|
1485
|
-
metadata: options.metadata
|
|
1485
|
+
metadata: options.metadata,
|
|
1486
|
+
violationReporting: { mode }
|
|
1486
1487
|
});
|
|
1487
1488
|
if (decision.allowed || mode !== "enforce") return { decision };
|
|
1488
1489
|
return { decision, response: await onBlocked(request, decision) };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ad as WebDecoyConfig, _ as ProtectOptions, s as Decision, W as WebDecoy } from './sdk-CJ6pmQGy.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Resolving the client IP address behind a proxy.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ad as WebDecoyConfig, _ as ProtectOptions, s as Decision, W as WebDecoy } from './sdk-CJ6pmQGy.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Resolving the client IP address behind a proxy.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { R as Rule, a as RuleContext, b as RuleResult, c as RuleEngineResult, d as RateLimitConfig, F as FilterConfig, T as TripwireConfig, B as BotRuleConfig, e as BotAgent, f as BotCategory, A as AgentCategory, g as RateLimitStore, h as RateLimitConsume, i as RateLimitOutcome, W as WebDecoy, P as ProtectResult, j as AgentVerifierOptions, k as AgentRequestInput, l as AgentVerdict, S as SignedAgentDirectory } from './sdk-
|
|
2
|
-
export { m as AgentStatus, n as BOT_CATEGORIES, o as BOT_REGISTRY, p as BotVerdict, C as Characteristic, q as Conclusion, r as CreatedHoneyCredential, D as DEFAULT_CHARACTERISTICS, s as Decision, t as DecisionCache, u as DecisionCacheOptions, v as DecisionInit, E as EDGE_CLASS_HEADER,
|
|
3
|
-
export { B as CLEARANCE_GATE_BUILD, C as ClearanceContext, a as ClearanceGateOptions, D as DetectAndGateOptions, b as DetectAndGateOutcome, F as FetchGuard, c as FetchGuardOptions, G as GateEnv, d as GateOutcome, e as GuardOutcome, H as HeaderSource, R as ResolveClientIpOptions, T as TrustedProxies, f as createClearanceGate, g as createDetectAndGate, h as createFetchGuard, i as ipInCidr, n as normalizeIp, r as resolveClientIp, j as resolveGateEnv } from './detect-and-gate-
|
|
1
|
+
import { R as Rule, a as RuleContext, b as RuleResult, c as RuleEngineResult, d as RateLimitConfig, F as FilterConfig, T as TripwireConfig, B as BotRuleConfig, e as BotAgent, f as BotCategory, A as AgentCategory, g as RateLimitStore, h as RateLimitConsume, i as RateLimitOutcome, W as WebDecoy, P as ProtectResult, j as AgentVerifierOptions, k as AgentRequestInput, l as AgentVerdict, S as SignedAgentDirectory } from './sdk-CJ6pmQGy.mjs';
|
|
2
|
+
export { m as AgentStatus, n as BOT_CATEGORIES, o as BOT_REGISTRY, p as BotVerdict, C as Characteristic, q as Conclusion, r as CreatedHoneyCredential, D as DEFAULT_CHARACTERISTICS, s as Decision, t as DecisionCache, u as DecisionCacheOptions, v as DecisionInit, w as DecisionMode, E as EDGE_CLASS_HEADER, x as EDGE_CLEARANCE_HEADER, y as EdgeClass, z as EdgeVerdict, G as FrameworkEvidenceObservation, H as HoneyCredentialHandle, I as HoneyCredentialOptions, J as HoneyCredentialPresentationResult, K as HoneyCredentialReceipt, L as IPEnrichmentData, M as LocalAnalysis, N as LogFields, O as Logger, Q as MemoryRateLimitStore, U as OffensiveToolFamily, V as OffensiveToolInvocation, X as OffensiveToolchainEvidence, Y as OffensiveToolchainEvidenceInput, Z as OffensiveToolchainObservation, _ as ProtectOptions, $ as RequestMetadata, a0 as RuleOutcome, a1 as RuleState, a2 as SDKDetectionRequest, a3 as SDKDetectionResponse, a4 as SSRFCanary, a5 as SSRFCanaryOptions, a6 as SSRFInitiationReceipt, a7 as Span, a8 as SyncRateLimitStore, a9 as TLSInfo, aa as Tracer, ab as ViolationDeliveryStats, ac as ViolationEvent, ad as WebDecoyConfig, ae as classifyUserAgent, af as consoleLogger, ag as createOffensiveToolchainEvidence, ah as deriveKey, ai as fromPino, aj as matchUserAgent, ak as newDecisionId, al as readEdgeVerdict, am as silentLogger } from './sdk-CJ6pmQGy.mjs';
|
|
3
|
+
export { B as CLEARANCE_GATE_BUILD, C as ClearanceContext, a as ClearanceGateOptions, D as DetectAndGateOptions, b as DetectAndGateOutcome, F as FetchGuard, c as FetchGuardOptions, G as GateEnv, d as GateOutcome, e as GuardOutcome, H as HeaderSource, R as ResolveClientIpOptions, T as TrustedProxies, f as createClearanceGate, g as createDetectAndGate, h as createFetchGuard, i as ipInCidr, n as normalizeIp, r as resolveClientIp, j as resolveGateEnv } from './detect-and-gate-BNq26N9d.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The reserved test trigger.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { R as Rule, a as RuleContext, b as RuleResult, c as RuleEngineResult, d as RateLimitConfig, F as FilterConfig, T as TripwireConfig, B as BotRuleConfig, e as BotAgent, f as BotCategory, A as AgentCategory, g as RateLimitStore, h as RateLimitConsume, i as RateLimitOutcome, W as WebDecoy, P as ProtectResult, j as AgentVerifierOptions, k as AgentRequestInput, l as AgentVerdict, S as SignedAgentDirectory } from './sdk-
|
|
2
|
-
export { m as AgentStatus, n as BOT_CATEGORIES, o as BOT_REGISTRY, p as BotVerdict, C as Characteristic, q as Conclusion, r as CreatedHoneyCredential, D as DEFAULT_CHARACTERISTICS, s as Decision, t as DecisionCache, u as DecisionCacheOptions, v as DecisionInit, E as EDGE_CLASS_HEADER,
|
|
3
|
-
export { B as CLEARANCE_GATE_BUILD, C as ClearanceContext, a as ClearanceGateOptions, D as DetectAndGateOptions, b as DetectAndGateOutcome, F as FetchGuard, c as FetchGuardOptions, G as GateEnv, d as GateOutcome, e as GuardOutcome, H as HeaderSource, R as ResolveClientIpOptions, T as TrustedProxies, f as createClearanceGate, g as createDetectAndGate, h as createFetchGuard, i as ipInCidr, n as normalizeIp, r as resolveClientIp, j as resolveGateEnv } from './detect-and-gate-
|
|
1
|
+
import { R as Rule, a as RuleContext, b as RuleResult, c as RuleEngineResult, d as RateLimitConfig, F as FilterConfig, T as TripwireConfig, B as BotRuleConfig, e as BotAgent, f as BotCategory, A as AgentCategory, g as RateLimitStore, h as RateLimitConsume, i as RateLimitOutcome, W as WebDecoy, P as ProtectResult, j as AgentVerifierOptions, k as AgentRequestInput, l as AgentVerdict, S as SignedAgentDirectory } from './sdk-CJ6pmQGy.js';
|
|
2
|
+
export { m as AgentStatus, n as BOT_CATEGORIES, o as BOT_REGISTRY, p as BotVerdict, C as Characteristic, q as Conclusion, r as CreatedHoneyCredential, D as DEFAULT_CHARACTERISTICS, s as Decision, t as DecisionCache, u as DecisionCacheOptions, v as DecisionInit, w as DecisionMode, E as EDGE_CLASS_HEADER, x as EDGE_CLEARANCE_HEADER, y as EdgeClass, z as EdgeVerdict, G as FrameworkEvidenceObservation, H as HoneyCredentialHandle, I as HoneyCredentialOptions, J as HoneyCredentialPresentationResult, K as HoneyCredentialReceipt, L as IPEnrichmentData, M as LocalAnalysis, N as LogFields, O as Logger, Q as MemoryRateLimitStore, U as OffensiveToolFamily, V as OffensiveToolInvocation, X as OffensiveToolchainEvidence, Y as OffensiveToolchainEvidenceInput, Z as OffensiveToolchainObservation, _ as ProtectOptions, $ as RequestMetadata, a0 as RuleOutcome, a1 as RuleState, a2 as SDKDetectionRequest, a3 as SDKDetectionResponse, a4 as SSRFCanary, a5 as SSRFCanaryOptions, a6 as SSRFInitiationReceipt, a7 as Span, a8 as SyncRateLimitStore, a9 as TLSInfo, aa as Tracer, ab as ViolationDeliveryStats, ac as ViolationEvent, ad as WebDecoyConfig, ae as classifyUserAgent, af as consoleLogger, ag as createOffensiveToolchainEvidence, ah as deriveKey, ai as fromPino, aj as matchUserAgent, ak as newDecisionId, al as readEdgeVerdict, am as silentLogger } from './sdk-CJ6pmQGy.js';
|
|
3
|
+
export { B as CLEARANCE_GATE_BUILD, C as ClearanceContext, a as ClearanceGateOptions, D as DetectAndGateOptions, b as DetectAndGateOutcome, F as FetchGuard, c as FetchGuardOptions, G as GateEnv, d as GateOutcome, e as GuardOutcome, H as HeaderSource, R as ResolveClientIpOptions, T as TrustedProxies, f as createClearanceGate, g as createDetectAndGate, h as createFetchGuard, i as ipInCidr, n as normalizeIp, r as resolveClientIp, j as resolveGateEnv } from './detect-and-gate-Dnfo2t3B.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The reserved test trigger.
|