@webdecoy/node 0.26.0 → 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 +6 -0
- package/dist/{chunk-2SIFEEYE.mjs → chunk-32TEUD5K.mjs} +72 -27
- package/dist/{chunk-CFJ7R2CG.mjs → chunk-P6IWJ7K5.mjs} +3 -2
- package/dist/{detect-and-gate-NBeqXdH6.d.mts → detect-and-gate-BNq26N9d.d.mts} +1 -1
- package/dist/{detect-and-gate-Ay294Lr2.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 +74 -28
- package/dist/index.mjs +2 -2
- package/dist/{sdk-Dh8Jj07-.d.mts → sdk-CJ6pmQGy.d.mts} +60 -6
- package/dist/{sdk-Dh8Jj07-.d.ts → sdk-CJ6pmQGy.d.ts} +60 -6
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +72 -27
- package/dist/testing.mjs +1 -1
- package/dist/vercel.d.mts +2 -2
- package/dist/vercel.d.ts +2 -2
- package/dist/vercel.js +74 -28
- package/dist/vercel.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -194,6 +194,12 @@ const wd = new WebDecoy({
|
|
|
194
194
|
|
|
195
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.
|
|
196
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
|
+
|
|
197
203
|
## Fetch runtimes (Bun, Deno, Workers, Astro, SvelteKit, Remix)
|
|
198
204
|
|
|
199
205
|
`createFetchGuard()` wraps the SDK for any runtime that hands you a WHATWG `Request`. It is the same implementation `@webdecoy/hono` uses.
|
|
@@ -2970,13 +2970,22 @@ var WebDecoyClient = class {
|
|
|
2970
2970
|
* Send violation events to the ingest service
|
|
2971
2971
|
*/
|
|
2972
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) {
|
|
2973
2977
|
try {
|
|
2974
|
-
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
|
+
}
|
|
2975
2983
|
} catch (error) {
|
|
2976
2984
|
if (this.config.debug) {
|
|
2977
2985
|
console.error("[WebDecoy] Failed to send violations:", error);
|
|
2978
2986
|
}
|
|
2979
2987
|
}
|
|
2988
|
+
return false;
|
|
2980
2989
|
}
|
|
2981
2990
|
/**
|
|
2982
2991
|
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
@@ -3182,7 +3191,9 @@ var MAX_BUFFERED_VIOLATIONS = 1e3;
|
|
|
3182
3191
|
var ViolationReporter = class {
|
|
3183
3192
|
constructor(client, config = {}) {
|
|
3184
3193
|
this.buffer = [];
|
|
3185
|
-
this.
|
|
3194
|
+
this.acknowledgedEvents = 0;
|
|
3195
|
+
this.failedBatches = 0;
|
|
3196
|
+
this.droppedEvents = 0;
|
|
3186
3197
|
this.client = client;
|
|
3187
3198
|
this.maxBufferSize = config.maxBufferSize ?? 50;
|
|
3188
3199
|
this.debug = config.debug ?? false;
|
|
@@ -3198,42 +3209,63 @@ var ViolationReporter = class {
|
|
|
3198
3209
|
report(violations) {
|
|
3199
3210
|
this.buffer.push(...violations);
|
|
3200
3211
|
if (this.buffer.length > MAX_BUFFERED_VIOLATIONS) {
|
|
3201
|
-
|
|
3212
|
+
const overflow = this.buffer.length - MAX_BUFFERED_VIOLATIONS;
|
|
3213
|
+
this.buffer.splice(0, overflow);
|
|
3214
|
+
this.droppedEvents += overflow;
|
|
3202
3215
|
}
|
|
3203
3216
|
if (this.buffer.length >= this.maxBufferSize) {
|
|
3204
3217
|
this.flush().catch(() => {
|
|
3205
3218
|
});
|
|
3206
3219
|
}
|
|
3207
3220
|
}
|
|
3208
|
-
/**
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
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;
|
|
3219
3245
|
if (this.debug) {
|
|
3220
3246
|
console.log(`[WebDecoy] Flushed ${batch.length} violation events`);
|
|
3221
3247
|
}
|
|
3248
|
+
} else {
|
|
3249
|
+
this.failedBatches++;
|
|
3250
|
+
this.droppedEvents += batch.length;
|
|
3222
3251
|
}
|
|
3223
|
-
} catch (error) {
|
|
3224
|
-
if (this.debug) {
|
|
3225
|
-
console.error("[WebDecoy] Failed to flush violations:", error);
|
|
3226
|
-
}
|
|
3227
|
-
} finally {
|
|
3228
|
-
this.flushing = false;
|
|
3229
3252
|
}
|
|
3230
3253
|
}
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
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. */
|
|
3234
3263
|
async destroy() {
|
|
3235
3264
|
clearInterval(this.flushTimer);
|
|
3265
|
+
if (this.flushPromise) await this.flushPromise;
|
|
3236
3266
|
await this.flush();
|
|
3267
|
+
this.droppedEvents += this.buffer.length;
|
|
3268
|
+
this.buffer.length = 0;
|
|
3237
3269
|
}
|
|
3238
3270
|
};
|
|
3239
3271
|
|
|
@@ -3625,7 +3657,7 @@ var WebDecoy = class {
|
|
|
3625
3657
|
return context;
|
|
3626
3658
|
}
|
|
3627
3659
|
/** Evaluate rules against a prepared context and report any violations. */
|
|
3628
|
-
runRules(context) {
|
|
3660
|
+
runRules(context, reporting) {
|
|
3629
3661
|
if (!this.ruleEngine) return null;
|
|
3630
3662
|
const span = startSpan(this.tracer, "webdecoy.rules");
|
|
3631
3663
|
const result = this.ruleEngine.evaluate(context);
|
|
@@ -3634,8 +3666,17 @@ var WebDecoy = class {
|
|
|
3634
3666
|
setAttribute(span, "webdecoy.rules.violations", result.violations.length);
|
|
3635
3667
|
if (result.rule) setAttribute(span, "webdecoy.rules.deciding", result.rule);
|
|
3636
3668
|
endSpan(span);
|
|
3637
|
-
|
|
3638
|
-
|
|
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
|
+
}
|
|
3639
3680
|
}
|
|
3640
3681
|
return result;
|
|
3641
3682
|
}
|
|
@@ -3835,7 +3876,7 @@ var WebDecoy = class {
|
|
|
3835
3876
|
const context = needsAsync ? await this.buildAsyncContext(metadata) : this.buildContext(metadata);
|
|
3836
3877
|
key = context.key ?? key;
|
|
3837
3878
|
const agentVerdict = context.agent;
|
|
3838
|
-
const ruleResult = this.ruleEngine ? this.runRules(context) : null;
|
|
3879
|
+
const ruleResult = this.ruleEngine ? this.runRules(context, options.violationReporting) : null;
|
|
3839
3880
|
if (ruleResult && ruleResult.action !== "ALLOW") {
|
|
3840
3881
|
setAttribute(span, "webdecoy.cloud.admission", "local_rule");
|
|
3841
3882
|
const throttled = ruleResult.action === "THROTTLE";
|
|
@@ -4048,6 +4089,10 @@ var WebDecoy = class {
|
|
|
4048
4089
|
setViolationReporter(reporter) {
|
|
4049
4090
|
this.violationReporter = reporter;
|
|
4050
4091
|
}
|
|
4092
|
+
/** Snapshot of this instance's violation delivery, when reporting is enabled. */
|
|
4093
|
+
getViolationDeliveryStats() {
|
|
4094
|
+
return this.violationReporter?.getDeliveryStats?.();
|
|
4095
|
+
}
|
|
4051
4096
|
/**
|
|
4052
4097
|
* Get the API client (for use by violation reporter, enrichment, etc.)
|
|
4053
4098
|
*/
|
|
@@ -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, 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
|
|
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, 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
|
|
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.
|
package/dist/index.js
CHANGED
|
@@ -347,13 +347,22 @@ var WebDecoyClient = class {
|
|
|
347
347
|
* Send violation events to the ingest service
|
|
348
348
|
*/
|
|
349
349
|
async sendViolations(events) {
|
|
350
|
+
await this.sendViolationBatch(events);
|
|
351
|
+
}
|
|
352
|
+
/** Acknowledgment from ingest for one batch. Transport failures resolve false. */
|
|
353
|
+
async sendViolationBatch(events) {
|
|
350
354
|
try {
|
|
351
|
-
await this.request("POST", "/api/v1/sdk/violations/batch", { events });
|
|
355
|
+
const { status } = await this.request("POST", "/api/v1/sdk/violations/batch", { events });
|
|
356
|
+
if (status >= 200 && status < 300) return true;
|
|
357
|
+
if (this.config.debug) {
|
|
358
|
+
console.warn(`[WebDecoy] Violation batch returned HTTP ${status}`);
|
|
359
|
+
}
|
|
352
360
|
} catch (error) {
|
|
353
361
|
if (this.config.debug) {
|
|
354
362
|
console.error("[WebDecoy] Failed to send violations:", error);
|
|
355
363
|
}
|
|
356
364
|
}
|
|
365
|
+
return false;
|
|
357
366
|
}
|
|
358
367
|
/**
|
|
359
368
|
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
@@ -2302,7 +2311,9 @@ var MAX_BUFFERED_VIOLATIONS = 1e3;
|
|
|
2302
2311
|
var ViolationReporter = class {
|
|
2303
2312
|
constructor(client, config = {}) {
|
|
2304
2313
|
this.buffer = [];
|
|
2305
|
-
this.
|
|
2314
|
+
this.acknowledgedEvents = 0;
|
|
2315
|
+
this.failedBatches = 0;
|
|
2316
|
+
this.droppedEvents = 0;
|
|
2306
2317
|
this.client = client;
|
|
2307
2318
|
this.maxBufferSize = config.maxBufferSize ?? 50;
|
|
2308
2319
|
this.debug = config.debug ?? false;
|
|
@@ -2318,42 +2329,63 @@ var ViolationReporter = class {
|
|
|
2318
2329
|
report(violations) {
|
|
2319
2330
|
this.buffer.push(...violations);
|
|
2320
2331
|
if (this.buffer.length > MAX_BUFFERED_VIOLATIONS) {
|
|
2321
|
-
|
|
2332
|
+
const overflow = this.buffer.length - MAX_BUFFERED_VIOLATIONS;
|
|
2333
|
+
this.buffer.splice(0, overflow);
|
|
2334
|
+
this.droppedEvents += overflow;
|
|
2322
2335
|
}
|
|
2323
2336
|
if (this.buffer.length >= this.maxBufferSize) {
|
|
2324
2337
|
this.flush().catch(() => {
|
|
2325
2338
|
});
|
|
2326
2339
|
}
|
|
2327
2340
|
}
|
|
2328
|
-
/**
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2341
|
+
/** Flush the buffer, coalescing requests that arrive during an active send. */
|
|
2342
|
+
flush() {
|
|
2343
|
+
if (this.queuedFlush) return this.queuedFlush;
|
|
2344
|
+
if (this.flushPromise) {
|
|
2345
|
+
if (this.buffer.length === 0 || !this.client.isAvailable()) return this.flushPromise;
|
|
2346
|
+
this.queuedFlush = this.flushPromise.then(() => {
|
|
2347
|
+
this.queuedFlush = void 0;
|
|
2348
|
+
return this.flush();
|
|
2349
|
+
});
|
|
2350
|
+
return this.queuedFlush;
|
|
2351
|
+
}
|
|
2352
|
+
if (this.buffer.length === 0 || !this.client.isAvailable()) return Promise.resolve();
|
|
2353
|
+
const size = this.buffer.length;
|
|
2354
|
+
this.flushPromise = Promise.resolve().then(() => this.flushBatches(size)).finally(() => {
|
|
2355
|
+
this.flushPromise = void 0;
|
|
2356
|
+
});
|
|
2357
|
+
return this.flushPromise;
|
|
2358
|
+
}
|
|
2359
|
+
async flushBatches(remaining) {
|
|
2360
|
+
while (remaining > 0 && this.buffer.length > 0 && this.client.isAvailable()) {
|
|
2361
|
+
const batch = this.buffer.splice(0, Math.min(100, remaining));
|
|
2362
|
+
remaining -= batch.length;
|
|
2363
|
+
if (await this.client.sendViolationBatch(batch)) {
|
|
2364
|
+
this.acknowledgedEvents += batch.length;
|
|
2339
2365
|
if (this.debug) {
|
|
2340
2366
|
console.log(`[WebDecoy] Flushed ${batch.length} violation events`);
|
|
2341
2367
|
}
|
|
2368
|
+
} else {
|
|
2369
|
+
this.failedBatches++;
|
|
2370
|
+
this.droppedEvents += batch.length;
|
|
2342
2371
|
}
|
|
2343
|
-
} catch (error) {
|
|
2344
|
-
if (this.debug) {
|
|
2345
|
-
console.error("[WebDecoy] Failed to flush violations:", error);
|
|
2346
|
-
}
|
|
2347
|
-
} finally {
|
|
2348
|
-
this.flushing = false;
|
|
2349
2372
|
}
|
|
2350
2373
|
}
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2374
|
+
getDeliveryStats() {
|
|
2375
|
+
return {
|
|
2376
|
+
acknowledgedEvents: this.acknowledgedEvents,
|
|
2377
|
+
failedBatches: this.failedBatches,
|
|
2378
|
+
droppedEvents: this.droppedEvents,
|
|
2379
|
+
bufferedEvents: this.buffer.length
|
|
2380
|
+
};
|
|
2381
|
+
}
|
|
2382
|
+
/** Stop the timer and give remaining events one final flush. */
|
|
2354
2383
|
async destroy() {
|
|
2355
2384
|
clearInterval(this.flushTimer);
|
|
2385
|
+
if (this.flushPromise) await this.flushPromise;
|
|
2356
2386
|
await this.flush();
|
|
2387
|
+
this.droppedEvents += this.buffer.length;
|
|
2388
|
+
this.buffer.length = 0;
|
|
2357
2389
|
}
|
|
2358
2390
|
};
|
|
2359
2391
|
|
|
@@ -3734,7 +3766,7 @@ var WebDecoy = class {
|
|
|
3734
3766
|
return context;
|
|
3735
3767
|
}
|
|
3736
3768
|
/** Evaluate rules against a prepared context and report any violations. */
|
|
3737
|
-
runRules(context) {
|
|
3769
|
+
runRules(context, reporting) {
|
|
3738
3770
|
if (!this.ruleEngine) return null;
|
|
3739
3771
|
const span = startSpan(this.tracer, "webdecoy.rules");
|
|
3740
3772
|
const result = this.ruleEngine.evaluate(context);
|
|
@@ -3743,8 +3775,17 @@ var WebDecoy = class {
|
|
|
3743
3775
|
setAttribute(span, "webdecoy.rules.violations", result.violations.length);
|
|
3744
3776
|
if (result.rule) setAttribute(span, "webdecoy.rules.deciding", result.rule);
|
|
3745
3777
|
endSpan(span);
|
|
3746
|
-
|
|
3747
|
-
|
|
3778
|
+
const reporter = this.violationReporter;
|
|
3779
|
+
if (reporter && result.violations.length > 0) {
|
|
3780
|
+
const violations = reporting?.mode === "monitor" ? result.violations.map((event) => ({ ...event, dryRun: true, clearance: void 0 })) : result.violations;
|
|
3781
|
+
reporter.report(violations);
|
|
3782
|
+
if (reporting?.waitUntil) {
|
|
3783
|
+
const delivery = Promise.resolve().then(() => reporter.flush()).catch(() => void 0);
|
|
3784
|
+
try {
|
|
3785
|
+
reporting.waitUntil(delivery);
|
|
3786
|
+
} catch {
|
|
3787
|
+
}
|
|
3788
|
+
}
|
|
3748
3789
|
}
|
|
3749
3790
|
return result;
|
|
3750
3791
|
}
|
|
@@ -3944,7 +3985,7 @@ var WebDecoy = class {
|
|
|
3944
3985
|
const context = needsAsync ? await this.buildAsyncContext(metadata) : this.buildContext(metadata);
|
|
3945
3986
|
key = context.key ?? key;
|
|
3946
3987
|
const agentVerdict = context.agent;
|
|
3947
|
-
const ruleResult = this.ruleEngine ? this.runRules(context) : null;
|
|
3988
|
+
const ruleResult = this.ruleEngine ? this.runRules(context, options.violationReporting) : null;
|
|
3948
3989
|
if (ruleResult && ruleResult.action !== "ALLOW") {
|
|
3949
3990
|
setAttribute(span, "webdecoy.cloud.admission", "local_rule");
|
|
3950
3991
|
const throttled = ruleResult.action === "THROTTLE";
|
|
@@ -4157,6 +4198,10 @@ var WebDecoy = class {
|
|
|
4157
4198
|
setViolationReporter(reporter) {
|
|
4158
4199
|
this.violationReporter = reporter;
|
|
4159
4200
|
}
|
|
4201
|
+
/** Snapshot of this instance's violation delivery, when reporting is enabled. */
|
|
4202
|
+
getViolationDeliveryStats() {
|
|
4203
|
+
return this.violationReporter?.getDeliveryStats?.();
|
|
4204
|
+
}
|
|
4160
4205
|
/**
|
|
4161
4206
|
* Get the API client (for use by violation reporter, enrichment, etc.)
|
|
4162
4207
|
*/
|
|
@@ -5675,7 +5720,8 @@ function createFetchGuard(options = {}) {
|
|
|
5675
5720
|
const decision = await sdk.protect(metadata, {
|
|
5676
5721
|
threshold: options.threshold,
|
|
5677
5722
|
skipLocalAnalysis: options.skipLocalAnalysis,
|
|
5678
|
-
metadata: options.metadata
|
|
5723
|
+
metadata: options.metadata,
|
|
5724
|
+
violationReporting: { mode }
|
|
5679
5725
|
});
|
|
5680
5726
|
if (decision.allowed || mode !== "enforce") return { decision };
|
|
5681
5727
|
return { decision, response: await onBlocked(request, decision) };
|
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
resolveGateEnv,
|
|
12
12
|
ruleBlockResponse,
|
|
13
13
|
shouldSkipPath
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-P6IWJ7K5.mjs";
|
|
15
15
|
import {
|
|
16
16
|
ATTACK_SIGNATURE_IDS,
|
|
17
17
|
AgentVerifier,
|
|
@@ -69,7 +69,7 @@ import {
|
|
|
69
69
|
tripwire,
|
|
70
70
|
upstashRateLimitStore,
|
|
71
71
|
webBotAuth
|
|
72
|
-
} from "./chunk-
|
|
72
|
+
} from "./chunk-32TEUD5K.mjs";
|
|
73
73
|
|
|
74
74
|
// src/client-signals.ts
|
|
75
75
|
var MemoryClientSignalStore = class {
|
|
@@ -916,6 +916,11 @@ interface ProtectOptions {
|
|
|
916
916
|
skipLocalAnalysis?: boolean;
|
|
917
917
|
/** Additional metadata to include in the detection */
|
|
918
918
|
metadata?: Record<string, any>;
|
|
919
|
+
/** How the caller handles local violations and keeps a background report alive. */
|
|
920
|
+
violationReporting?: {
|
|
921
|
+
mode: 'monitor' | 'enforce';
|
|
922
|
+
waitUntil?: (delivery: Promise<void>) => void;
|
|
923
|
+
};
|
|
919
924
|
}
|
|
920
925
|
|
|
921
926
|
/**
|
|
@@ -1412,6 +1417,8 @@ declare class WebDecoyClient {
|
|
|
1412
1417
|
* Send violation events to the ingest service
|
|
1413
1418
|
*/
|
|
1414
1419
|
sendViolations(events: ViolationEvent[]): Promise<void>;
|
|
1420
|
+
/** Acknowledgment from ingest for one batch. Transport failures resolve false. */
|
|
1421
|
+
sendViolationBatch(events: ViolationEvent[]): Promise<boolean>;
|
|
1415
1422
|
/**
|
|
1416
1423
|
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
1417
1424
|
* accepted, or refused for a reason a retry cannot fix (a 4xx). Only a
|
|
@@ -1429,6 +1436,54 @@ declare class WebDecoyClient {
|
|
|
1429
1436
|
validateAPIKey(): Promise<boolean>;
|
|
1430
1437
|
}
|
|
1431
1438
|
|
|
1439
|
+
/**
|
|
1440
|
+
* Violation Reporter
|
|
1441
|
+
* Buffers violation events and flushes them to the backend in batches
|
|
1442
|
+
*/
|
|
1443
|
+
|
|
1444
|
+
interface ViolationReporterConfig {
|
|
1445
|
+
/** Flush interval in milliseconds (default: 5000) */
|
|
1446
|
+
flushInterval?: number;
|
|
1447
|
+
/** Max buffer size before auto-flush (default: 50) */
|
|
1448
|
+
maxBufferSize?: number;
|
|
1449
|
+
/** Enable debug logging */
|
|
1450
|
+
debug?: boolean;
|
|
1451
|
+
}
|
|
1452
|
+
/** Delivery counters for this SDK instance. */
|
|
1453
|
+
interface ViolationDeliveryStats {
|
|
1454
|
+
/** Events in batches acknowledged by ingest. */
|
|
1455
|
+
acknowledgedEvents: number;
|
|
1456
|
+
/** HTTP or transport failures for attempted batches. */
|
|
1457
|
+
failedBatches: number;
|
|
1458
|
+
/** Events discarded after failure, overflow, or shutdown. */
|
|
1459
|
+
droppedEvents: number;
|
|
1460
|
+
/** Events waiting for an attempt. */
|
|
1461
|
+
bufferedEvents: number;
|
|
1462
|
+
}
|
|
1463
|
+
declare class ViolationReporter {
|
|
1464
|
+
private client;
|
|
1465
|
+
private buffer;
|
|
1466
|
+
private flushTimer;
|
|
1467
|
+
private maxBufferSize;
|
|
1468
|
+
private debug;
|
|
1469
|
+
private flushPromise;
|
|
1470
|
+
private queuedFlush;
|
|
1471
|
+
private acknowledgedEvents;
|
|
1472
|
+
private failedBatches;
|
|
1473
|
+
private droppedEvents;
|
|
1474
|
+
constructor(client: WebDecoyClient, config?: ViolationReporterConfig);
|
|
1475
|
+
/**
|
|
1476
|
+
* Add violations to the buffer. Auto-flushes when buffer reaches maxBufferSize.
|
|
1477
|
+
*/
|
|
1478
|
+
report(violations: ViolationEvent[]): void;
|
|
1479
|
+
/** Flush the buffer, coalescing requests that arrive during an active send. */
|
|
1480
|
+
flush(): Promise<void>;
|
|
1481
|
+
private flushBatches;
|
|
1482
|
+
getDeliveryStats(): ViolationDeliveryStats;
|
|
1483
|
+
/** Stop the timer and give remaining events one final flush. */
|
|
1484
|
+
destroy(): Promise<void>;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1432
1487
|
interface OffensiveToolInvocation {
|
|
1433
1488
|
/** Reviewed tool identifier. Unknown identifiers are counted and dropped. */
|
|
1434
1489
|
tool: string;
|
|
@@ -1460,6 +1515,7 @@ interface OffensiveToolchainEvidence {
|
|
|
1460
1515
|
*/
|
|
1461
1516
|
declare function createOffensiveToolchainEvidence(input: OffensiveToolchainEvidenceInput): Promise<OffensiveToolchainEvidence>;
|
|
1462
1517
|
|
|
1518
|
+
type ConfiguredViolationReporter = Pick<ViolationReporter, 'report' | 'flush' | 'destroy'> & Partial<Pick<ViolationReporter, 'getDeliveryStats'>>;
|
|
1463
1519
|
declare class WebDecoy {
|
|
1464
1520
|
private client;
|
|
1465
1521
|
private config;
|
|
@@ -1602,11 +1658,9 @@ declare class WebDecoy {
|
|
|
1602
1658
|
* Attach a violation reporter for sending violations to the backend.
|
|
1603
1659
|
* Called internally when apiKey is present and rules are configured.
|
|
1604
1660
|
*/
|
|
1605
|
-
setViolationReporter(reporter:
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
destroy(): Promise<void>;
|
|
1609
|
-
}): void;
|
|
1661
|
+
setViolationReporter(reporter: ConfiguredViolationReporter): void;
|
|
1662
|
+
/** Snapshot of this instance's violation delivery, when reporting is enabled. */
|
|
1663
|
+
getViolationDeliveryStats(): ViolationDeliveryStats | undefined;
|
|
1610
1664
|
/**
|
|
1611
1665
|
* Get the API client (for use by violation reporter, enrichment, etc.)
|
|
1612
1666
|
*/
|
|
@@ -1621,4 +1675,4 @@ declare class WebDecoy {
|
|
|
1621
1675
|
destroy(): Promise<void>;
|
|
1622
1676
|
}
|
|
1623
1677
|
|
|
1624
|
-
export { type RequestMetadata as $, type AgentCategory as A, type BotRuleConfig as B, type Characteristic as C, DEFAULT_CHARACTERISTICS as D, EDGE_CLASS_HEADER as E, type FilterConfig as F, type FrameworkEvidenceObservation as G, type HoneyCredentialHandle as H, type HoneyCredentialOptions as I, type HoneyCredentialPresentationResult as J, type HoneyCredentialReceipt as K, type IPEnrichmentData as L, type LocalAnalysis as M, type LogFields as N, type Logger as O, type ProtectResult as P, MemoryRateLimitStore as Q, type Rule as R, type SignedAgentDirectory as S, type TripwireConfig as T, type OffensiveToolFamily as U, type OffensiveToolInvocation as V, WebDecoy as W, type OffensiveToolchainEvidence as X, type OffensiveToolchainEvidenceInput as Y, type OffensiveToolchainObservation as Z, type ProtectOptions as _, type RuleContext as a, type RuleOutcome as a0, type RuleState as a1, type SDKDetectionRequest as a2, type SDKDetectionResponse as a3, type SSRFCanary as a4, type SSRFCanaryOptions as a5, type SSRFInitiationReceipt as a6, type Span as a7, type SyncRateLimitStore as a8, type TLSInfo as a9, type Tracer as aa, type
|
|
1678
|
+
export { type RequestMetadata as $, type AgentCategory as A, type BotRuleConfig as B, type Characteristic as C, DEFAULT_CHARACTERISTICS as D, EDGE_CLASS_HEADER as E, type FilterConfig as F, type FrameworkEvidenceObservation as G, type HoneyCredentialHandle as H, type HoneyCredentialOptions as I, type HoneyCredentialPresentationResult as J, type HoneyCredentialReceipt as K, type IPEnrichmentData as L, type LocalAnalysis as M, type LogFields as N, type Logger as O, type ProtectResult as P, MemoryRateLimitStore as Q, type Rule as R, type SignedAgentDirectory as S, type TripwireConfig as T, type OffensiveToolFamily as U, type OffensiveToolInvocation as V, WebDecoy as W, type OffensiveToolchainEvidence as X, type OffensiveToolchainEvidenceInput as Y, type OffensiveToolchainObservation as Z, type ProtectOptions as _, type RuleContext as a, type RuleOutcome as a0, type RuleState as a1, type SDKDetectionRequest as a2, type SDKDetectionResponse as a3, type SSRFCanary as a4, type SSRFCanaryOptions as a5, type SSRFInitiationReceipt as a6, type Span as a7, type SyncRateLimitStore as a8, type TLSInfo as a9, type Tracer as aa, type ViolationDeliveryStats as ab, type ViolationEvent as ac, type WebDecoyConfig as ad, classifyUserAgent as ae, consoleLogger as af, createOffensiveToolchainEvidence as ag, deriveKey as ah, fromPino as ai, matchUserAgent as aj, newDecisionId as ak, readEdgeVerdict as al, silentLogger as am, type RuleResult as b, type RuleEngineResult as c, type RateLimitConfig as d, type BotAgent as e, type BotCategory as f, type RateLimitStore as g, type RateLimitConsume as h, type RateLimitOutcome as i, type AgentVerifierOptions as j, type AgentRequestInput as k, type AgentVerdict as l, type AgentStatus as m, BOT_CATEGORIES as n, BOT_REGISTRY as o, type BotVerdict as p, type Conclusion as q, type CreatedHoneyCredential as r, Decision as s, DecisionCache as t, type DecisionCacheOptions as u, type DecisionInit as v, type DecisionMode as w, EDGE_CLEARANCE_HEADER as x, type EdgeClass as y, type EdgeVerdict as z };
|
|
@@ -916,6 +916,11 @@ interface ProtectOptions {
|
|
|
916
916
|
skipLocalAnalysis?: boolean;
|
|
917
917
|
/** Additional metadata to include in the detection */
|
|
918
918
|
metadata?: Record<string, any>;
|
|
919
|
+
/** How the caller handles local violations and keeps a background report alive. */
|
|
920
|
+
violationReporting?: {
|
|
921
|
+
mode: 'monitor' | 'enforce';
|
|
922
|
+
waitUntil?: (delivery: Promise<void>) => void;
|
|
923
|
+
};
|
|
919
924
|
}
|
|
920
925
|
|
|
921
926
|
/**
|
|
@@ -1412,6 +1417,8 @@ declare class WebDecoyClient {
|
|
|
1412
1417
|
* Send violation events to the ingest service
|
|
1413
1418
|
*/
|
|
1414
1419
|
sendViolations(events: ViolationEvent[]): Promise<void>;
|
|
1420
|
+
/** Acknowledgment from ingest for one batch. Transport failures resolve false. */
|
|
1421
|
+
sendViolationBatch(events: ViolationEvent[]): Promise<boolean>;
|
|
1415
1422
|
/**
|
|
1416
1423
|
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
1417
1424
|
* accepted, or refused for a reason a retry cannot fix (a 4xx). Only a
|
|
@@ -1429,6 +1436,54 @@ declare class WebDecoyClient {
|
|
|
1429
1436
|
validateAPIKey(): Promise<boolean>;
|
|
1430
1437
|
}
|
|
1431
1438
|
|
|
1439
|
+
/**
|
|
1440
|
+
* Violation Reporter
|
|
1441
|
+
* Buffers violation events and flushes them to the backend in batches
|
|
1442
|
+
*/
|
|
1443
|
+
|
|
1444
|
+
interface ViolationReporterConfig {
|
|
1445
|
+
/** Flush interval in milliseconds (default: 5000) */
|
|
1446
|
+
flushInterval?: number;
|
|
1447
|
+
/** Max buffer size before auto-flush (default: 50) */
|
|
1448
|
+
maxBufferSize?: number;
|
|
1449
|
+
/** Enable debug logging */
|
|
1450
|
+
debug?: boolean;
|
|
1451
|
+
}
|
|
1452
|
+
/** Delivery counters for this SDK instance. */
|
|
1453
|
+
interface ViolationDeliveryStats {
|
|
1454
|
+
/** Events in batches acknowledged by ingest. */
|
|
1455
|
+
acknowledgedEvents: number;
|
|
1456
|
+
/** HTTP or transport failures for attempted batches. */
|
|
1457
|
+
failedBatches: number;
|
|
1458
|
+
/** Events discarded after failure, overflow, or shutdown. */
|
|
1459
|
+
droppedEvents: number;
|
|
1460
|
+
/** Events waiting for an attempt. */
|
|
1461
|
+
bufferedEvents: number;
|
|
1462
|
+
}
|
|
1463
|
+
declare class ViolationReporter {
|
|
1464
|
+
private client;
|
|
1465
|
+
private buffer;
|
|
1466
|
+
private flushTimer;
|
|
1467
|
+
private maxBufferSize;
|
|
1468
|
+
private debug;
|
|
1469
|
+
private flushPromise;
|
|
1470
|
+
private queuedFlush;
|
|
1471
|
+
private acknowledgedEvents;
|
|
1472
|
+
private failedBatches;
|
|
1473
|
+
private droppedEvents;
|
|
1474
|
+
constructor(client: WebDecoyClient, config?: ViolationReporterConfig);
|
|
1475
|
+
/**
|
|
1476
|
+
* Add violations to the buffer. Auto-flushes when buffer reaches maxBufferSize.
|
|
1477
|
+
*/
|
|
1478
|
+
report(violations: ViolationEvent[]): void;
|
|
1479
|
+
/** Flush the buffer, coalescing requests that arrive during an active send. */
|
|
1480
|
+
flush(): Promise<void>;
|
|
1481
|
+
private flushBatches;
|
|
1482
|
+
getDeliveryStats(): ViolationDeliveryStats;
|
|
1483
|
+
/** Stop the timer and give remaining events one final flush. */
|
|
1484
|
+
destroy(): Promise<void>;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1432
1487
|
interface OffensiveToolInvocation {
|
|
1433
1488
|
/** Reviewed tool identifier. Unknown identifiers are counted and dropped. */
|
|
1434
1489
|
tool: string;
|
|
@@ -1460,6 +1515,7 @@ interface OffensiveToolchainEvidence {
|
|
|
1460
1515
|
*/
|
|
1461
1516
|
declare function createOffensiveToolchainEvidence(input: OffensiveToolchainEvidenceInput): Promise<OffensiveToolchainEvidence>;
|
|
1462
1517
|
|
|
1518
|
+
type ConfiguredViolationReporter = Pick<ViolationReporter, 'report' | 'flush' | 'destroy'> & Partial<Pick<ViolationReporter, 'getDeliveryStats'>>;
|
|
1463
1519
|
declare class WebDecoy {
|
|
1464
1520
|
private client;
|
|
1465
1521
|
private config;
|
|
@@ -1602,11 +1658,9 @@ declare class WebDecoy {
|
|
|
1602
1658
|
* Attach a violation reporter for sending violations to the backend.
|
|
1603
1659
|
* Called internally when apiKey is present and rules are configured.
|
|
1604
1660
|
*/
|
|
1605
|
-
setViolationReporter(reporter:
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
destroy(): Promise<void>;
|
|
1609
|
-
}): void;
|
|
1661
|
+
setViolationReporter(reporter: ConfiguredViolationReporter): void;
|
|
1662
|
+
/** Snapshot of this instance's violation delivery, when reporting is enabled. */
|
|
1663
|
+
getViolationDeliveryStats(): ViolationDeliveryStats | undefined;
|
|
1610
1664
|
/**
|
|
1611
1665
|
* Get the API client (for use by violation reporter, enrichment, etc.)
|
|
1612
1666
|
*/
|
|
@@ -1621,4 +1675,4 @@ declare class WebDecoy {
|
|
|
1621
1675
|
destroy(): Promise<void>;
|
|
1622
1676
|
}
|
|
1623
1677
|
|
|
1624
|
-
export { type RequestMetadata as $, type AgentCategory as A, type BotRuleConfig as B, type Characteristic as C, DEFAULT_CHARACTERISTICS as D, EDGE_CLASS_HEADER as E, type FilterConfig as F, type FrameworkEvidenceObservation as G, type HoneyCredentialHandle as H, type HoneyCredentialOptions as I, type HoneyCredentialPresentationResult as J, type HoneyCredentialReceipt as K, type IPEnrichmentData as L, type LocalAnalysis as M, type LogFields as N, type Logger as O, type ProtectResult as P, MemoryRateLimitStore as Q, type Rule as R, type SignedAgentDirectory as S, type TripwireConfig as T, type OffensiveToolFamily as U, type OffensiveToolInvocation as V, WebDecoy as W, type OffensiveToolchainEvidence as X, type OffensiveToolchainEvidenceInput as Y, type OffensiveToolchainObservation as Z, type ProtectOptions as _, type RuleContext as a, type RuleOutcome as a0, type RuleState as a1, type SDKDetectionRequest as a2, type SDKDetectionResponse as a3, type SSRFCanary as a4, type SSRFCanaryOptions as a5, type SSRFInitiationReceipt as a6, type Span as a7, type SyncRateLimitStore as a8, type TLSInfo as a9, type Tracer as aa, type
|
|
1678
|
+
export { type RequestMetadata as $, type AgentCategory as A, type BotRuleConfig as B, type Characteristic as C, DEFAULT_CHARACTERISTICS as D, EDGE_CLASS_HEADER as E, type FilterConfig as F, type FrameworkEvidenceObservation as G, type HoneyCredentialHandle as H, type HoneyCredentialOptions as I, type HoneyCredentialPresentationResult as J, type HoneyCredentialReceipt as K, type IPEnrichmentData as L, type LocalAnalysis as M, type LogFields as N, type Logger as O, type ProtectResult as P, MemoryRateLimitStore as Q, type Rule as R, type SignedAgentDirectory as S, type TripwireConfig as T, type OffensiveToolFamily as U, type OffensiveToolInvocation as V, WebDecoy as W, type OffensiveToolchainEvidence as X, type OffensiveToolchainEvidenceInput as Y, type OffensiveToolchainObservation as Z, type ProtectOptions as _, type RuleContext as a, type RuleOutcome as a0, type RuleState as a1, type SDKDetectionRequest as a2, type SDKDetectionResponse as a3, type SSRFCanary as a4, type SSRFCanaryOptions as a5, type SSRFInitiationReceipt as a6, type Span as a7, type SyncRateLimitStore as a8, type TLSInfo as a9, type Tracer as aa, type ViolationDeliveryStats as ab, type ViolationEvent as ac, type WebDecoyConfig as ad, classifyUserAgent as ae, consoleLogger as af, createOffensiveToolchainEvidence as ag, deriveKey as ah, fromPino as ai, matchUserAgent as aj, newDecisionId as ak, readEdgeVerdict as al, silentLogger as am, type RuleResult as b, type RuleEngineResult as c, type RateLimitConfig as d, type BotAgent as e, type BotCategory as f, type RateLimitStore as g, type RateLimitConsume as h, type RateLimitOutcome as i, type AgentVerifierOptions as j, type AgentRequestInput as k, type AgentVerdict as l, type AgentStatus as m, BOT_CATEGORIES as n, BOT_REGISTRY as o, type BotVerdict as p, type Conclusion as q, type CreatedHoneyCredential as r, Decision as s, DecisionCache as t, type DecisionCacheOptions as u, type DecisionInit as v, type DecisionMode as w, EDGE_CLEARANCE_HEADER as x, type EdgeClass as y, type EdgeVerdict as z };
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ad as WebDecoyConfig, $ as RequestMetadata, W as WebDecoy, P as ProtectResult, a1 as RuleState } from './sdk-CJ6pmQGy.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Testing utilities, for the application's test suite rather than ours.
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ad as WebDecoyConfig, $ as RequestMetadata, W as WebDecoy, P as ProtectResult, a1 as RuleState } from './sdk-CJ6pmQGy.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Testing utilities, for the application's test suite rather than ours.
|
package/dist/testing.js
CHANGED
|
@@ -272,13 +272,22 @@ var WebDecoyClient = class {
|
|
|
272
272
|
* Send violation events to the ingest service
|
|
273
273
|
*/
|
|
274
274
|
async sendViolations(events) {
|
|
275
|
+
await this.sendViolationBatch(events);
|
|
276
|
+
}
|
|
277
|
+
/** Acknowledgment from ingest for one batch. Transport failures resolve false. */
|
|
278
|
+
async sendViolationBatch(events) {
|
|
275
279
|
try {
|
|
276
|
-
await this.request("POST", "/api/v1/sdk/violations/batch", { events });
|
|
280
|
+
const { status } = await this.request("POST", "/api/v1/sdk/violations/batch", { events });
|
|
281
|
+
if (status >= 200 && status < 300) return true;
|
|
282
|
+
if (this.config.debug) {
|
|
283
|
+
console.warn(`[WebDecoy] Violation batch returned HTTP ${status}`);
|
|
284
|
+
}
|
|
277
285
|
} catch (error) {
|
|
278
286
|
if (this.config.debug) {
|
|
279
287
|
console.error("[WebDecoy] Failed to send violations:", error);
|
|
280
288
|
}
|
|
281
289
|
}
|
|
290
|
+
return false;
|
|
282
291
|
}
|
|
283
292
|
/**
|
|
284
293
|
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
@@ -1073,7 +1082,9 @@ var MAX_BUFFERED_VIOLATIONS = 1e3;
|
|
|
1073
1082
|
var ViolationReporter = class {
|
|
1074
1083
|
constructor(client, config = {}) {
|
|
1075
1084
|
this.buffer = [];
|
|
1076
|
-
this.
|
|
1085
|
+
this.acknowledgedEvents = 0;
|
|
1086
|
+
this.failedBatches = 0;
|
|
1087
|
+
this.droppedEvents = 0;
|
|
1077
1088
|
this.client = client;
|
|
1078
1089
|
this.maxBufferSize = config.maxBufferSize ?? 50;
|
|
1079
1090
|
this.debug = config.debug ?? false;
|
|
@@ -1089,42 +1100,63 @@ var ViolationReporter = class {
|
|
|
1089
1100
|
report(violations) {
|
|
1090
1101
|
this.buffer.push(...violations);
|
|
1091
1102
|
if (this.buffer.length > MAX_BUFFERED_VIOLATIONS) {
|
|
1092
|
-
|
|
1103
|
+
const overflow = this.buffer.length - MAX_BUFFERED_VIOLATIONS;
|
|
1104
|
+
this.buffer.splice(0, overflow);
|
|
1105
|
+
this.droppedEvents += overflow;
|
|
1093
1106
|
}
|
|
1094
1107
|
if (this.buffer.length >= this.maxBufferSize) {
|
|
1095
1108
|
this.flush().catch(() => {
|
|
1096
1109
|
});
|
|
1097
1110
|
}
|
|
1098
1111
|
}
|
|
1099
|
-
/**
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1112
|
+
/** Flush the buffer, coalescing requests that arrive during an active send. */
|
|
1113
|
+
flush() {
|
|
1114
|
+
if (this.queuedFlush) return this.queuedFlush;
|
|
1115
|
+
if (this.flushPromise) {
|
|
1116
|
+
if (this.buffer.length === 0 || !this.client.isAvailable()) return this.flushPromise;
|
|
1117
|
+
this.queuedFlush = this.flushPromise.then(() => {
|
|
1118
|
+
this.queuedFlush = void 0;
|
|
1119
|
+
return this.flush();
|
|
1120
|
+
});
|
|
1121
|
+
return this.queuedFlush;
|
|
1122
|
+
}
|
|
1123
|
+
if (this.buffer.length === 0 || !this.client.isAvailable()) return Promise.resolve();
|
|
1124
|
+
const size = this.buffer.length;
|
|
1125
|
+
this.flushPromise = Promise.resolve().then(() => this.flushBatches(size)).finally(() => {
|
|
1126
|
+
this.flushPromise = void 0;
|
|
1127
|
+
});
|
|
1128
|
+
return this.flushPromise;
|
|
1129
|
+
}
|
|
1130
|
+
async flushBatches(remaining) {
|
|
1131
|
+
while (remaining > 0 && this.buffer.length > 0 && this.client.isAvailable()) {
|
|
1132
|
+
const batch = this.buffer.splice(0, Math.min(100, remaining));
|
|
1133
|
+
remaining -= batch.length;
|
|
1134
|
+
if (await this.client.sendViolationBatch(batch)) {
|
|
1135
|
+
this.acknowledgedEvents += batch.length;
|
|
1110
1136
|
if (this.debug) {
|
|
1111
1137
|
console.log(`[WebDecoy] Flushed ${batch.length} violation events`);
|
|
1112
1138
|
}
|
|
1139
|
+
} else {
|
|
1140
|
+
this.failedBatches++;
|
|
1141
|
+
this.droppedEvents += batch.length;
|
|
1113
1142
|
}
|
|
1114
|
-
} catch (error) {
|
|
1115
|
-
if (this.debug) {
|
|
1116
|
-
console.error("[WebDecoy] Failed to flush violations:", error);
|
|
1117
|
-
}
|
|
1118
|
-
} finally {
|
|
1119
|
-
this.flushing = false;
|
|
1120
1143
|
}
|
|
1121
1144
|
}
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1145
|
+
getDeliveryStats() {
|
|
1146
|
+
return {
|
|
1147
|
+
acknowledgedEvents: this.acknowledgedEvents,
|
|
1148
|
+
failedBatches: this.failedBatches,
|
|
1149
|
+
droppedEvents: this.droppedEvents,
|
|
1150
|
+
bufferedEvents: this.buffer.length
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
/** Stop the timer and give remaining events one final flush. */
|
|
1125
1154
|
async destroy() {
|
|
1126
1155
|
clearInterval(this.flushTimer);
|
|
1156
|
+
if (this.flushPromise) await this.flushPromise;
|
|
1127
1157
|
await this.flush();
|
|
1158
|
+
this.droppedEvents += this.buffer.length;
|
|
1159
|
+
this.buffer.length = 0;
|
|
1128
1160
|
}
|
|
1129
1161
|
};
|
|
1130
1162
|
|
|
@@ -2493,7 +2525,7 @@ var WebDecoy = class {
|
|
|
2493
2525
|
return context;
|
|
2494
2526
|
}
|
|
2495
2527
|
/** Evaluate rules against a prepared context and report any violations. */
|
|
2496
|
-
runRules(context) {
|
|
2528
|
+
runRules(context, reporting) {
|
|
2497
2529
|
if (!this.ruleEngine) return null;
|
|
2498
2530
|
const span = startSpan(this.tracer, "webdecoy.rules");
|
|
2499
2531
|
const result = this.ruleEngine.evaluate(context);
|
|
@@ -2502,8 +2534,17 @@ var WebDecoy = class {
|
|
|
2502
2534
|
setAttribute(span, "webdecoy.rules.violations", result.violations.length);
|
|
2503
2535
|
if (result.rule) setAttribute(span, "webdecoy.rules.deciding", result.rule);
|
|
2504
2536
|
endSpan(span);
|
|
2505
|
-
|
|
2506
|
-
|
|
2537
|
+
const reporter = this.violationReporter;
|
|
2538
|
+
if (reporter && result.violations.length > 0) {
|
|
2539
|
+
const violations = reporting?.mode === "monitor" ? result.violations.map((event) => ({ ...event, dryRun: true, clearance: void 0 })) : result.violations;
|
|
2540
|
+
reporter.report(violations);
|
|
2541
|
+
if (reporting?.waitUntil) {
|
|
2542
|
+
const delivery = Promise.resolve().then(() => reporter.flush()).catch(() => void 0);
|
|
2543
|
+
try {
|
|
2544
|
+
reporting.waitUntil(delivery);
|
|
2545
|
+
} catch {
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2507
2548
|
}
|
|
2508
2549
|
return result;
|
|
2509
2550
|
}
|
|
@@ -2703,7 +2744,7 @@ var WebDecoy = class {
|
|
|
2703
2744
|
const context = needsAsync ? await this.buildAsyncContext(metadata) : this.buildContext(metadata);
|
|
2704
2745
|
key = context.key ?? key;
|
|
2705
2746
|
const agentVerdict = context.agent;
|
|
2706
|
-
const ruleResult = this.ruleEngine ? this.runRules(context) : null;
|
|
2747
|
+
const ruleResult = this.ruleEngine ? this.runRules(context, options.violationReporting) : null;
|
|
2707
2748
|
if (ruleResult && ruleResult.action !== "ALLOW") {
|
|
2708
2749
|
setAttribute(span, "webdecoy.cloud.admission", "local_rule");
|
|
2709
2750
|
const throttled = ruleResult.action === "THROTTLE";
|
|
@@ -2916,6 +2957,10 @@ var WebDecoy = class {
|
|
|
2916
2957
|
setViolationReporter(reporter) {
|
|
2917
2958
|
this.violationReporter = reporter;
|
|
2918
2959
|
}
|
|
2960
|
+
/** Snapshot of this instance's violation delivery, when reporting is enabled. */
|
|
2961
|
+
getViolationDeliveryStats() {
|
|
2962
|
+
return this.violationReporter?.getDeliveryStats?.();
|
|
2963
|
+
}
|
|
2919
2964
|
/**
|
|
2920
2965
|
* Get the API client (for use by violation reporter, enrichment, etc.)
|
|
2921
2966
|
*/
|
package/dist/testing.mjs
CHANGED
package/dist/vercel.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ClearanceGateOptions, C as ClearanceContext, D as DetectAndGateOptions, d as GateOutcome } from './detect-and-gate-
|
|
2
|
-
import './sdk-
|
|
1
|
+
import { a as ClearanceGateOptions, C as ClearanceContext, D as DetectAndGateOptions, d as GateOutcome } from './detect-and-gate-BNq26N9d.mjs';
|
|
2
|
+
import './sdk-CJ6pmQGy.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* WebDecoy for Vercel Routing Middleware, any framework.
|
package/dist/vercel.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ClearanceGateOptions, C as ClearanceContext, D as DetectAndGateOptions, d as GateOutcome } from './detect-and-gate-
|
|
2
|
-
import './sdk-
|
|
1
|
+
import { a as ClearanceGateOptions, C as ClearanceContext, D as DetectAndGateOptions, d as GateOutcome } from './detect-and-gate-Dnfo2t3B.js';
|
|
2
|
+
import './sdk-CJ6pmQGy.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* WebDecoy for Vercel Routing Middleware, any framework.
|
package/dist/vercel.js
CHANGED
|
@@ -1634,13 +1634,22 @@ var WebDecoyClient = class {
|
|
|
1634
1634
|
* Send violation events to the ingest service
|
|
1635
1635
|
*/
|
|
1636
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) {
|
|
1637
1641
|
try {
|
|
1638
|
-
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
|
+
}
|
|
1639
1647
|
} catch (error) {
|
|
1640
1648
|
if (this.config.debug) {
|
|
1641
1649
|
console.error("[WebDecoy] Failed to send violations:", error);
|
|
1642
1650
|
}
|
|
1643
1651
|
}
|
|
1652
|
+
return false;
|
|
1644
1653
|
}
|
|
1645
1654
|
/**
|
|
1646
1655
|
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
@@ -2507,7 +2516,9 @@ var MAX_BUFFERED_VIOLATIONS = 1e3;
|
|
|
2507
2516
|
var ViolationReporter = class {
|
|
2508
2517
|
constructor(client, config = {}) {
|
|
2509
2518
|
this.buffer = [];
|
|
2510
|
-
this.
|
|
2519
|
+
this.acknowledgedEvents = 0;
|
|
2520
|
+
this.failedBatches = 0;
|
|
2521
|
+
this.droppedEvents = 0;
|
|
2511
2522
|
this.client = client;
|
|
2512
2523
|
this.maxBufferSize = config.maxBufferSize ?? 50;
|
|
2513
2524
|
this.debug = config.debug ?? false;
|
|
@@ -2523,42 +2534,63 @@ var ViolationReporter = class {
|
|
|
2523
2534
|
report(violations) {
|
|
2524
2535
|
this.buffer.push(...violations);
|
|
2525
2536
|
if (this.buffer.length > MAX_BUFFERED_VIOLATIONS) {
|
|
2526
|
-
|
|
2537
|
+
const overflow = this.buffer.length - MAX_BUFFERED_VIOLATIONS;
|
|
2538
|
+
this.buffer.splice(0, overflow);
|
|
2539
|
+
this.droppedEvents += overflow;
|
|
2527
2540
|
}
|
|
2528
2541
|
if (this.buffer.length >= this.maxBufferSize) {
|
|
2529
2542
|
this.flush().catch(() => {
|
|
2530
2543
|
});
|
|
2531
2544
|
}
|
|
2532
2545
|
}
|
|
2533
|
-
/**
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
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;
|
|
2544
2570
|
if (this.debug) {
|
|
2545
2571
|
console.log(`[WebDecoy] Flushed ${batch.length} violation events`);
|
|
2546
2572
|
}
|
|
2573
|
+
} else {
|
|
2574
|
+
this.failedBatches++;
|
|
2575
|
+
this.droppedEvents += batch.length;
|
|
2547
2576
|
}
|
|
2548
|
-
} catch (error) {
|
|
2549
|
-
if (this.debug) {
|
|
2550
|
-
console.error("[WebDecoy] Failed to flush violations:", error);
|
|
2551
|
-
}
|
|
2552
|
-
} finally {
|
|
2553
|
-
this.flushing = false;
|
|
2554
2577
|
}
|
|
2555
2578
|
}
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
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. */
|
|
2559
2588
|
async destroy() {
|
|
2560
2589
|
clearInterval(this.flushTimer);
|
|
2590
|
+
if (this.flushPromise) await this.flushPromise;
|
|
2561
2591
|
await this.flush();
|
|
2592
|
+
this.droppedEvents += this.buffer.length;
|
|
2593
|
+
this.buffer.length = 0;
|
|
2562
2594
|
}
|
|
2563
2595
|
};
|
|
2564
2596
|
|
|
@@ -3917,7 +3949,7 @@ var WebDecoy = class {
|
|
|
3917
3949
|
return context;
|
|
3918
3950
|
}
|
|
3919
3951
|
/** Evaluate rules against a prepared context and report any violations. */
|
|
3920
|
-
runRules(context) {
|
|
3952
|
+
runRules(context, reporting) {
|
|
3921
3953
|
if (!this.ruleEngine) return null;
|
|
3922
3954
|
const span = startSpan(this.tracer, "webdecoy.rules");
|
|
3923
3955
|
const result = this.ruleEngine.evaluate(context);
|
|
@@ -3926,8 +3958,17 @@ var WebDecoy = class {
|
|
|
3926
3958
|
setAttribute(span, "webdecoy.rules.violations", result.violations.length);
|
|
3927
3959
|
if (result.rule) setAttribute(span, "webdecoy.rules.deciding", result.rule);
|
|
3928
3960
|
endSpan(span);
|
|
3929
|
-
|
|
3930
|
-
|
|
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
|
+
}
|
|
3931
3972
|
}
|
|
3932
3973
|
return result;
|
|
3933
3974
|
}
|
|
@@ -4127,7 +4168,7 @@ var WebDecoy = class {
|
|
|
4127
4168
|
const context = needsAsync ? await this.buildAsyncContext(metadata) : this.buildContext(metadata);
|
|
4128
4169
|
key = context.key ?? key;
|
|
4129
4170
|
const agentVerdict = context.agent;
|
|
4130
|
-
const ruleResult = this.ruleEngine ? this.runRules(context) : null;
|
|
4171
|
+
const ruleResult = this.ruleEngine ? this.runRules(context, options.violationReporting) : null;
|
|
4131
4172
|
if (ruleResult && ruleResult.action !== "ALLOW") {
|
|
4132
4173
|
setAttribute(span, "webdecoy.cloud.admission", "local_rule");
|
|
4133
4174
|
const throttled = ruleResult.action === "THROTTLE";
|
|
@@ -4340,6 +4381,10 @@ var WebDecoy = class {
|
|
|
4340
4381
|
setViolationReporter(reporter) {
|
|
4341
4382
|
this.violationReporter = reporter;
|
|
4342
4383
|
}
|
|
4384
|
+
/** Snapshot of this instance's violation delivery, when reporting is enabled. */
|
|
4385
|
+
getViolationDeliveryStats() {
|
|
4386
|
+
return this.violationReporter?.getDeliveryStats?.();
|
|
4387
|
+
}
|
|
4343
4388
|
/**
|
|
4344
4389
|
* Get the API client (for use by violation reporter, enrichment, etc.)
|
|
4345
4390
|
*/
|
|
@@ -4491,7 +4536,8 @@ function createFetchGuard(options = {}) {
|
|
|
4491
4536
|
const decision = await sdk.protect(metadata, {
|
|
4492
4537
|
threshold: options.threshold,
|
|
4493
4538
|
skipLocalAnalysis: options.skipLocalAnalysis,
|
|
4494
|
-
metadata: options.metadata
|
|
4539
|
+
metadata: options.metadata,
|
|
4540
|
+
violationReporting: { mode }
|
|
4495
4541
|
});
|
|
4496
4542
|
if (decision.allowed || mode !== "enforce") return { decision };
|
|
4497
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",
|