@webdecoy/node 0.13.0 → 0.15.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 +1 -1
- package/dist/{chunk-CIRFOOMU.mjs → chunk-T6MX62T5.mjs} +80 -9
- package/dist/index.d.mts +162 -89
- package/dist/index.d.ts +162 -89
- package/dist/index.js +160 -53
- package/dist/index.mjs +77 -45
- package/dist/{sdk-DjeCBrHu.d.mts → sdk-qUjMf8ZX.d.mts} +61 -4
- package/dist/{sdk-DjeCBrHu.d.ts → sdk-qUjMf8ZX.d.ts} +61 -4
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +80 -9
- package/dist/testing.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ const webdecoy = new WebDecoy({
|
|
|
45
45
|
apiKey: 'sk_live_xxxxx',
|
|
46
46
|
|
|
47
47
|
// Optional: API endpoint (defaults to production)
|
|
48
|
-
apiUrl: 'https://
|
|
48
|
+
apiUrl: 'https://in.webdecoy.com',
|
|
49
49
|
|
|
50
50
|
// Optional: Enable TLS fingerprinting (default: true)
|
|
51
51
|
enableTLSFingerprinting: true,
|
|
@@ -863,6 +863,7 @@ var BOT_CATEGORIES = [
|
|
|
863
863
|
"none"
|
|
864
864
|
];
|
|
865
865
|
var BOT_REGISTRY = [
|
|
866
|
+
{ id: "reflectionbot", name: "Reflectionbot", category: "training_crawler", organization: "Reflection AI", baseScore: 70, respectsRobots: true, uaPatterns: ["reflectionbot"] },
|
|
866
867
|
{ id: "gptbot", name: "GPTBot", category: "training_crawler", organization: "OpenAI", baseScore: 85, respectsRobots: true, uaPatterns: ["gptbot"] },
|
|
867
868
|
{ id: "chatgpt-user", name: "ChatGPT-User", category: "training_crawler", organization: "OpenAI", baseScore: 85, respectsRobots: true, uaPatterns: ["chatgpt-user", "chatgpt"] },
|
|
868
869
|
{ id: "oai-searchbot", name: "OAI-SearchBot", category: "training_crawler", organization: "OpenAI", baseScore: 80, respectsRobots: true, uaPatterns: ["oai-searchbot"] },
|
|
@@ -891,6 +892,10 @@ var BOT_REGISTRY = [
|
|
|
891
892
|
{ id: "velenpublicwebcrawler", name: "VelenPublicWebCrawler", category: "training_crawler", organization: "Velen", baseScore: 70, respectsRobots: false, uaPatterns: ["velenpublicwebcrawler"] },
|
|
892
893
|
{ id: "isscyberriskcrawler", name: "ISSCyberRiskCrawler", category: "training_crawler", organization: "ISS", baseScore: 65, respectsRobots: false, uaPatterns: ["isscyberriskcrawler"] },
|
|
893
894
|
{ id: "friendlycrawler", name: "FriendlyCrawler", category: "training_crawler", organization: "Unknown", baseScore: 65, respectsRobots: true, uaPatterns: ["friendlycrawler"] },
|
|
895
|
+
{ id: "duckassistbot", name: "DuckAssistBot", category: "ai_search_crawler", organization: "DuckDuckGo", baseScore: 65, respectsRobots: true, uaPatterns: ["duckassistbot"] },
|
|
896
|
+
{ id: "sofyabot", name: "SofyaBot", category: "ai_search_crawler", organization: "Sofya", baseScore: 65, respectsRobots: true, uaPatterns: ["sofyabot"] },
|
|
897
|
+
{ id: "xai-searchbot", name: "xAI-SearchBot", category: "ai_search_crawler", organization: "xAI", baseScore: 70, respectsRobots: true, uaPatterns: ["xai-searchbot"] },
|
|
898
|
+
{ id: "linkupbot", name: "LinkupBot", category: "ai_search_crawler", organization: "Linkup", baseScore: 65, respectsRobots: true, uaPatterns: ["linkupbot"] },
|
|
894
899
|
{ id: "searchgpt", name: "SearchGPT", category: "ai_search_crawler", organization: "OpenAI", baseScore: 75, respectsRobots: true, uaPatterns: ["searchgpt"] },
|
|
895
900
|
{ id: "phind", name: "Phind", category: "ai_search_crawler", organization: "Phind", baseScore: 70, respectsRobots: true, uaPatterns: ["phind"] },
|
|
896
901
|
{ id: "kagi", name: "Kagi", category: "ai_search_crawler", organization: "Kagi", baseScore: 65, respectsRobots: true, uaPatterns: ["kagi"] },
|
|
@@ -907,6 +912,7 @@ var BOT_REGISTRY = [
|
|
|
907
912
|
{ id: "browser-use", name: "Browser-Use", category: "ai_agent", organization: "Open Source", baseScore: 70, respectsRobots: false, uaPatterns: ["browser-use"] },
|
|
908
913
|
{ id: "stagehand", name: "Stagehand", category: "ai_agent", organization: "Browserbase", baseScore: 70, respectsRobots: false, uaPatterns: ["stagehand"] },
|
|
909
914
|
{ id: "multion", name: "MultiOn", category: "ai_agent", organization: "MultiOn", baseScore: 70, respectsRobots: false, uaPatterns: ["multion"] },
|
|
915
|
+
{ id: "iboubot", name: "IbouBot", category: "search_crawler", organization: "Ibou", baseScore: 30, respectsRobots: true, uaPatterns: ["iboubot"] },
|
|
910
916
|
{ id: "googlebot", name: "Googlebot", category: "search_crawler", organization: "Google", baseScore: 30, respectsRobots: true, uaPatterns: ["googlebot"] },
|
|
911
917
|
{ id: "bingbot", name: "Bingbot", category: "search_crawler", organization: "Microsoft", baseScore: 30, respectsRobots: true, uaPatterns: ["bingbot"] },
|
|
912
918
|
{ id: "yandexbot", name: "YandexBot", category: "search_crawler", organization: "Yandex", baseScore: 35, respectsRobots: true, uaPatterns: ["yandexbot"] },
|
|
@@ -2664,11 +2670,8 @@ function calculateLocalScore(suspiciousHeaders, missingSecCHUA, datacenterIP) {
|
|
|
2664
2670
|
if (datacenterIP) score += 40;
|
|
2665
2671
|
return Math.min(score, 100);
|
|
2666
2672
|
}
|
|
2667
|
-
function needsVerification(
|
|
2668
|
-
|
|
2669
|
-
return true;
|
|
2670
|
-
}
|
|
2671
|
-
return localScore >= 30;
|
|
2673
|
+
function needsVerification(suspiciousHeaders, hasTLSInfo) {
|
|
2674
|
+
return hasTLSInfo || suspiciousHeaders;
|
|
2672
2675
|
}
|
|
2673
2676
|
function buildFlags(suspiciousHeaders, missingSecCHUA, datacenterIP, metadata) {
|
|
2674
2677
|
const flags = [];
|
|
@@ -2696,7 +2699,7 @@ function analyzeRequest(metadata) {
|
|
|
2696
2699
|
const datacenterIP = isDatacenterIP(metadata.ip);
|
|
2697
2700
|
const localScore = calculateLocalScore(suspiciousHeaders, missingSecCHUA, datacenterIP);
|
|
2698
2701
|
const hasTLSInfo = Boolean(metadata.tls_info);
|
|
2699
|
-
const needsVerify = needsVerification(
|
|
2702
|
+
const needsVerify = needsVerification(suspiciousHeaders, hasTLSInfo);
|
|
2700
2703
|
const flags = buildFlags(suspiciousHeaders, missingSecCHUA, datacenterIP, metadata);
|
|
2701
2704
|
return {
|
|
2702
2705
|
suspicious_headers: suspiciousHeaders,
|
|
@@ -2812,6 +2815,43 @@ var IPEnrichmentClient = class {
|
|
|
2812
2815
|
}
|
|
2813
2816
|
};
|
|
2814
2817
|
|
|
2818
|
+
// src/tracing.ts
|
|
2819
|
+
var STATUS_ERROR = 2;
|
|
2820
|
+
var NOOP_SPAN = {
|
|
2821
|
+
setAttribute: () => void 0,
|
|
2822
|
+
end: () => void 0
|
|
2823
|
+
};
|
|
2824
|
+
function startSpan(tracer, name) {
|
|
2825
|
+
if (!tracer) return NOOP_SPAN;
|
|
2826
|
+
try {
|
|
2827
|
+
return tracer.startSpan(name) ?? NOOP_SPAN;
|
|
2828
|
+
} catch {
|
|
2829
|
+
return NOOP_SPAN;
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
function setAttribute(span, key, value) {
|
|
2833
|
+
try {
|
|
2834
|
+
span.setAttribute(key, value);
|
|
2835
|
+
} catch {
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
function recordError(span, error) {
|
|
2839
|
+
try {
|
|
2840
|
+
span.recordException?.(error);
|
|
2841
|
+
span.setStatus?.({
|
|
2842
|
+
code: STATUS_ERROR,
|
|
2843
|
+
message: error instanceof Error ? error.message : String(error)
|
|
2844
|
+
});
|
|
2845
|
+
} catch {
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
function endSpan(span) {
|
|
2849
|
+
try {
|
|
2850
|
+
span.end();
|
|
2851
|
+
} catch {
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
|
|
2815
2855
|
// src/sdk.ts
|
|
2816
2856
|
var WebDecoy = class {
|
|
2817
2857
|
constructor(config) {
|
|
@@ -2831,7 +2871,7 @@ var WebDecoy = class {
|
|
|
2831
2871
|
}
|
|
2832
2872
|
this.config = {
|
|
2833
2873
|
apiKey: config.apiKey,
|
|
2834
|
-
apiUrl: config.apiUrl || "https://
|
|
2874
|
+
apiUrl: config.apiUrl || "https://in.webdecoy.com",
|
|
2835
2875
|
enableTLSFingerprinting: config.enableTLSFingerprinting ?? true,
|
|
2836
2876
|
threatScoreThreshold: config.threatScoreThreshold ?? 80,
|
|
2837
2877
|
timeout: config.timeout ?? 5e3,
|
|
@@ -2839,6 +2879,7 @@ var WebDecoy = class {
|
|
|
2839
2879
|
tlsRejectUnauthorized: config.tlsRejectUnauthorized ?? true
|
|
2840
2880
|
};
|
|
2841
2881
|
this.log = resolveLogger(config.logger, this.config.debug);
|
|
2882
|
+
this.tracer = config.tracer;
|
|
2842
2883
|
if (hasApiKey) {
|
|
2843
2884
|
this.client = new WebDecoyClient({
|
|
2844
2885
|
apiKey: config.apiKey,
|
|
@@ -2966,7 +3007,13 @@ var WebDecoy = class {
|
|
|
2966
3007
|
/** Evaluate rules against a prepared context and report any violations. */
|
|
2967
3008
|
runRules(context) {
|
|
2968
3009
|
if (!this.ruleEngine) return null;
|
|
3010
|
+
const span = startSpan(this.tracer, "webdecoy.rules");
|
|
2969
3011
|
const result = this.ruleEngine.evaluate(context);
|
|
3012
|
+
setAttribute(span, "webdecoy.rules.action", result.action);
|
|
3013
|
+
setAttribute(span, "webdecoy.rules.evaluated", result.results.length);
|
|
3014
|
+
setAttribute(span, "webdecoy.rules.violations", result.violations.length);
|
|
3015
|
+
if (result.rule) setAttribute(span, "webdecoy.rules.deciding", result.rule);
|
|
3016
|
+
endSpan(span);
|
|
2970
3017
|
if (result.violations.length > 0 && this.violationReporter) {
|
|
2971
3018
|
this.violationReporter.report(result.violations);
|
|
2972
3019
|
}
|
|
@@ -3034,7 +3081,31 @@ var WebDecoy = class {
|
|
|
3034
3081
|
*/
|
|
3035
3082
|
async protect(metadata, options = {}) {
|
|
3036
3083
|
const edge = readEdgeVerdict(metadata.headers);
|
|
3037
|
-
|
|
3084
|
+
const span = startSpan(this.tracer, "webdecoy.protect");
|
|
3085
|
+
try {
|
|
3086
|
+
const decision = (await this.decide(metadata, options)).withEdge(edge);
|
|
3087
|
+
setAttribute(span, "webdecoy.decision.id", decision.id);
|
|
3088
|
+
setAttribute(span, "webdecoy.decision.conclusion", decision.conclusion);
|
|
3089
|
+
setAttribute(span, "webdecoy.decision.allowed", decision.allowed);
|
|
3090
|
+
setAttribute(span, "webdecoy.rules.evaluated", decision.results.length);
|
|
3091
|
+
if (decision.ruleResult?.rule) {
|
|
3092
|
+
setAttribute(span, "webdecoy.decision.rule", decision.ruleResult.rule);
|
|
3093
|
+
}
|
|
3094
|
+
setAttribute(
|
|
3095
|
+
span,
|
|
3096
|
+
"webdecoy.remote",
|
|
3097
|
+
decision.detection.detection_id !== decision.id
|
|
3098
|
+
);
|
|
3099
|
+
if (decision.error) {
|
|
3100
|
+
setAttribute(span, "webdecoy.error", decision.error);
|
|
3101
|
+
}
|
|
3102
|
+
return decision;
|
|
3103
|
+
} catch (error) {
|
|
3104
|
+
recordError(span, error);
|
|
3105
|
+
throw error;
|
|
3106
|
+
} finally {
|
|
3107
|
+
endSpan(span);
|
|
3108
|
+
}
|
|
3038
3109
|
}
|
|
3039
3110
|
async decide(metadata, options = {}) {
|
|
3040
3111
|
const id = newDecisionId();
|
|
@@ -3108,7 +3179,7 @@ var WebDecoy = class {
|
|
|
3108
3179
|
local_analysis: localAnalysis
|
|
3109
3180
|
};
|
|
3110
3181
|
const shouldCallServer = localAnalysis.needs_verification || this.config.enableTLSFingerprinting && metadata.tls_info;
|
|
3111
|
-
if (!shouldCallServer
|
|
3182
|
+
if (!shouldCallServer) {
|
|
3112
3183
|
return new Decision({
|
|
3113
3184
|
conclusion: "ALLOW",
|
|
3114
3185
|
detection: {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as Rule, a as RuleContext, b as RuleResult,
|
|
2
|
-
export {
|
|
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, D as Decision, j as WebDecoyConfig, k as ProtectOptions, l as AgentVerifierOptions, m as AgentRequestInput, n as AgentVerdict, S as SignedAgentDirectory } from './sdk-qUjMf8ZX.mjs';
|
|
2
|
+
export { o as AgentStatus, p as BOT_CATEGORIES, q as BOT_REGISTRY, r as BotVerdict, C as Characteristic, s as Conclusion, t as DEFAULT_CHARACTERISTICS, u as DecisionCache, v as DecisionCacheOptions, w as DecisionInit, E as EDGE_CLASS_HEADER, x as EDGE_CLEARANCE_HEADER, y as EdgeClass, z as EdgeVerdict, I as IPEnrichmentData, L as LocalAnalysis, G as LogFields, H as Logger, M as MemoryRateLimitStore, J as RequestMetadata, K as RuleOutcome, N as RuleState, O as SDKDetectionRequest, Q as SDKDetectionResponse, U as Span, V as SyncRateLimitStore, X as TLSInfo, Y as Tracer, Z as ViolationEvent, _ as classifyUserAgent, $ as consoleLogger, a0 as deriveKey, a1 as fromPino, a2 as matchUserAgent, a3 as newDecisionId, a4 as readEdgeVerdict, a5 as silentLogger } from './sdk-qUjMf8ZX.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The reserved test trigger.
|
|
@@ -634,92 +634,6 @@ declare class ClientSignalRule implements Rule {
|
|
|
634
634
|
/** Act on the browser widget's verdict for this session. See {@link ClientSignalConfig}. */
|
|
635
635
|
declare function clientSignals(config: ClientSignalConfig): Rule;
|
|
636
636
|
|
|
637
|
-
/**
|
|
638
|
-
* One adapter, for every runtime that speaks `Request` and `Response`.
|
|
639
|
-
*
|
|
640
|
-
* WHY THIS EXISTS
|
|
641
|
-
*
|
|
642
|
-
* Express, Fastify and Next.js each grew their own copy of the same middleware:
|
|
643
|
-
* skip-path matching, monitor-versus-enforce, honeytoken arming, the 429 with a
|
|
644
|
-
* `Retry-After`, fail-open error handling. Three copies of a decision tree is
|
|
645
|
-
* three places for the branch that matters to be subtly different — and it
|
|
646
|
-
* already had been, which is how the leftmost-`X-Forwarded-For` bug survived in
|
|
647
|
-
* two adapters after the WordPress plugin fixed it.
|
|
648
|
-
*
|
|
649
|
-
* It is also the answer to "which framework do you support?". Hono, Bun, Deno,
|
|
650
|
-
* Astro, Nitro, SvelteKit and Remix all hand you a WHATWG `Request` and want a
|
|
651
|
-
* `Response` back. Written once here, each of those is a translation layer thin
|
|
652
|
-
* enough not to need a package — see the README recipe — and `@webdecoy/hono` is
|
|
653
|
-
* the one that does, because Hono has a middleware contract worth fitting.
|
|
654
|
-
*
|
|
655
|
-
* No `node:` imports: this is the code path that has to run on Workers.
|
|
656
|
-
*/
|
|
657
|
-
|
|
658
|
-
interface FetchGuardOptions extends WebDecoyConfig, ProtectOptions {
|
|
659
|
-
/**
|
|
660
|
-
* Whether a blocking verdict actually blocks. Defaults to `'monitor'`.
|
|
661
|
-
*
|
|
662
|
-
* Nobody adopts a defence by having it break their site on the first install.
|
|
663
|
-
* Watch what it would have done, then switch.
|
|
664
|
-
*/
|
|
665
|
-
mode?: 'monitor' | 'enforce';
|
|
666
|
-
/** Paths to skip entirely — health checks, static assets. */
|
|
667
|
-
skipPaths?: (string | RegExp)[];
|
|
668
|
-
/**
|
|
669
|
-
* How much of the `X-Forwarded-For` chain to believe. Defaults to `1` trusted
|
|
670
|
-
* hop: a fetch handler has no socket to fall back on, so there is no
|
|
671
|
-
* believe-nothing default available. See `resolveClientIp`.
|
|
672
|
-
*/
|
|
673
|
-
trustProxy?: TrustedProxies;
|
|
674
|
-
/** Override IP resolution entirely. */
|
|
675
|
-
getIP?: (request: Request) => string;
|
|
676
|
-
/**
|
|
677
|
-
* Inject a hidden honeytoken link into HTML responses, and arm the tripwire it
|
|
678
|
-
* points at. Defaults to on when an `apiKey` is present.
|
|
679
|
-
*/
|
|
680
|
-
honeytoken?: boolean;
|
|
681
|
-
/** Build the blocking response. Defaults to 403, or 429 for a throttle. */
|
|
682
|
-
onBlocked?: (request: Request, decision: Decision) => Response | Promise<Response>;
|
|
683
|
-
}
|
|
684
|
-
interface GuardOutcome {
|
|
685
|
-
/** What the SDK concluded. Always present, in both modes. */
|
|
686
|
-
decision: Decision;
|
|
687
|
-
/**
|
|
688
|
-
* The response to return instead of calling the handler, or undefined to
|
|
689
|
-
* carry on. Undefined in monitor mode even when the decision is a denial.
|
|
690
|
-
*/
|
|
691
|
-
response?: Response;
|
|
692
|
-
}
|
|
693
|
-
interface FetchGuard {
|
|
694
|
-
/** Evaluate one request. */
|
|
695
|
-
check(request: Request, peer?: string): Promise<GuardOutcome>;
|
|
696
|
-
/**
|
|
697
|
-
* Rewrite an HTML response to carry the honeytoken link. Returns the response
|
|
698
|
-
* unchanged when there is no token yet, or the body is not injectable HTML.
|
|
699
|
-
*/
|
|
700
|
-
decorate(response: Response): Promise<Response>;
|
|
701
|
-
/** Whether this path is skipped. */
|
|
702
|
-
skips(pathname: string): boolean;
|
|
703
|
-
/** The underlying SDK, for `detectBot()` and friends. */
|
|
704
|
-
sdk: WebDecoy;
|
|
705
|
-
}
|
|
706
|
-
/**
|
|
707
|
-
* A guard over WHATWG `Request`/`Response`.
|
|
708
|
-
*
|
|
709
|
-
* ```ts
|
|
710
|
-
* const guard = createFetchGuard({ rules: [tripwire()] });
|
|
711
|
-
*
|
|
712
|
-
* export default {
|
|
713
|
-
* async fetch(request) {
|
|
714
|
-
* const { response } = await guard.check(request);
|
|
715
|
-
* if (response) return response;
|
|
716
|
-
* return guard.decorate(await handle(request));
|
|
717
|
-
* },
|
|
718
|
-
* };
|
|
719
|
-
* ```
|
|
720
|
-
*/
|
|
721
|
-
declare function createFetchGuard(options?: FetchGuardOptions): FetchGuard;
|
|
722
|
-
|
|
723
637
|
/**
|
|
724
638
|
* Rule Engine
|
|
725
639
|
* Evaluates rules in order — first DENY/THROTTLE wins
|
|
@@ -1398,6 +1312,165 @@ declare function tripwire(config?: TripwireConfig): Rule;
|
|
|
1398
1312
|
*/
|
|
1399
1313
|
declare function bots(config?: BotRuleConfig): Rule;
|
|
1400
1314
|
|
|
1315
|
+
/**
|
|
1316
|
+
* The parts of a middleware that are the same in every framework.
|
|
1317
|
+
*
|
|
1318
|
+
* WHY THIS EXISTS
|
|
1319
|
+
*
|
|
1320
|
+
* Express, Fastify, Next.js and the fetch guard each grew their own copy of the
|
|
1321
|
+
* same decision tree: skip-path matching, monitor-versus-enforce, honeytoken
|
|
1322
|
+
* arming, the 429 payload, the 403 payload. Four copies of one set of rules.
|
|
1323
|
+
*
|
|
1324
|
+
* That is not a tidiness complaint. The leftmost-`X-Forwarded-For` bug survived
|
|
1325
|
+
* in two adapters after the same class of bug had already been fixed elsewhere,
|
|
1326
|
+
* precisely because there was no one place to fix. Every copy is a place the
|
|
1327
|
+
* next correction can fail to land, and each one reads perfectly sensibly on its
|
|
1328
|
+
* own — which is why review does not catch it.
|
|
1329
|
+
*
|
|
1330
|
+
* WHAT STAYS IN THE ADAPTERS
|
|
1331
|
+
*
|
|
1332
|
+
* Everything that touches the framework: reading metadata off its request
|
|
1333
|
+
* object, writing its response, and injecting the honeytoken link into whatever
|
|
1334
|
+
* that framework calls a body. Response mechanics differ genuinely — Express
|
|
1335
|
+
* intercepts `res.write`/`res.end`, Fastify uses an `onSend` hook, a fetch
|
|
1336
|
+
* handler rebuilds a `Response` — and the detail in each is hard-won. This
|
|
1337
|
+
* module holds the decisions, not the I/O.
|
|
1338
|
+
*/
|
|
1339
|
+
|
|
1340
|
+
/** Whether a request path is exempt from protection. */
|
|
1341
|
+
declare function shouldSkipPath(path: string, patterns: readonly (string | RegExp)[] | undefined): boolean;
|
|
1342
|
+
/** A framework-agnostic description of the response a blocked request gets. */
|
|
1343
|
+
interface BlockResponse {
|
|
1344
|
+
status: number;
|
|
1345
|
+
headers: Record<string, string>;
|
|
1346
|
+
body: Record<string, unknown>;
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* What to answer a request the rules refused.
|
|
1350
|
+
*
|
|
1351
|
+
* Returns null when the decision was not a rule refusal — a server-score block
|
|
1352
|
+
* has no rule to name, and each adapter's `onBlocked` handles that case with its
|
|
1353
|
+
* own default.
|
|
1354
|
+
*/
|
|
1355
|
+
declare function ruleBlockResponse(decision: ProtectResult): BlockResponse | null;
|
|
1356
|
+
interface HoneytokenArmingOptions {
|
|
1357
|
+
/** The site honeytoken is derived from this. No key, no token. */
|
|
1358
|
+
apiKey?: string;
|
|
1359
|
+
/** Defaults to on when an apiKey is present. */
|
|
1360
|
+
enabled?: boolean;
|
|
1361
|
+
/** Reported when derivation fails, so a silent absence is at least loggable. */
|
|
1362
|
+
onError?: (error: unknown) => void;
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Derive the site honeytoken and arm the tripwire it points at.
|
|
1366
|
+
*
|
|
1367
|
+
* Returns a getter rather than a promise: derivation is async (WebCrypto HMAC,
|
|
1368
|
+
* so this still runs on edge runtimes) and requests served before it settles
|
|
1369
|
+
* simply carry no link. That is a few milliseconds at boot against the
|
|
1370
|
+
* alternative of blocking startup on crypto.
|
|
1371
|
+
*
|
|
1372
|
+
* The token is derived from the API key so every replica computes the same path
|
|
1373
|
+
* without coordinating. A random per-process token would advertise a link whose
|
|
1374
|
+
* tripwire only one replica had armed — bait with no trap behind it.
|
|
1375
|
+
*/
|
|
1376
|
+
declare function armSiteHoneytoken(sdk: WebDecoy, options: HoneytokenArmingOptions): () => SiteHoneytoken | null;
|
|
1377
|
+
/**
|
|
1378
|
+
* Derive and arm, awaited.
|
|
1379
|
+
*
|
|
1380
|
+
* For a framework whose registration is already an async boot phase — Fastify's
|
|
1381
|
+
* plugin hook — where waiting costs nothing and removes the window in which
|
|
1382
|
+
* early requests are served without the link. Same logic as
|
|
1383
|
+
* {@link armSiteHoneytoken}; only the timing differs, which is why it is a
|
|
1384
|
+
* second entry point rather than a second implementation.
|
|
1385
|
+
*/
|
|
1386
|
+
declare function deriveAndArm(sdk: WebDecoy, options: HoneytokenArmingOptions): Promise<SiteHoneytoken | null>;
|
|
1387
|
+
|
|
1388
|
+
/**
|
|
1389
|
+
* One adapter, for every runtime that speaks `Request` and `Response`.
|
|
1390
|
+
*
|
|
1391
|
+
* WHY THIS EXISTS
|
|
1392
|
+
*
|
|
1393
|
+
* Express, Fastify and Next.js each grew their own copy of the same middleware:
|
|
1394
|
+
* skip-path matching, monitor-versus-enforce, honeytoken arming, the 429 with a
|
|
1395
|
+
* `Retry-After`, fail-open error handling. Three copies of a decision tree is
|
|
1396
|
+
* three places for the branch that matters to be subtly different — and it
|
|
1397
|
+
* already had been, which is how the leftmost-`X-Forwarded-For` bug survived in
|
|
1398
|
+
* two adapters after the WordPress plugin fixed it.
|
|
1399
|
+
*
|
|
1400
|
+
* It is also the answer to "which framework do you support?". Hono, Bun, Deno,
|
|
1401
|
+
* Astro, Nitro, SvelteKit and Remix all hand you a WHATWG `Request` and want a
|
|
1402
|
+
* `Response` back. Written once here, each of those is a translation layer thin
|
|
1403
|
+
* enough not to need a package — see the README recipe — and `@webdecoy/hono` is
|
|
1404
|
+
* the one that does, because Hono has a middleware contract worth fitting.
|
|
1405
|
+
*
|
|
1406
|
+
* No `node:` imports: this is the code path that has to run on Workers.
|
|
1407
|
+
*/
|
|
1408
|
+
|
|
1409
|
+
interface FetchGuardOptions extends WebDecoyConfig, ProtectOptions {
|
|
1410
|
+
/**
|
|
1411
|
+
* Whether a blocking verdict actually blocks. Defaults to `'monitor'`.
|
|
1412
|
+
*
|
|
1413
|
+
* Nobody adopts a defence by having it break their site on the first install.
|
|
1414
|
+
* Watch what it would have done, then switch.
|
|
1415
|
+
*/
|
|
1416
|
+
mode?: 'monitor' | 'enforce';
|
|
1417
|
+
/** Paths to skip entirely — health checks, static assets. */
|
|
1418
|
+
skipPaths?: (string | RegExp)[];
|
|
1419
|
+
/**
|
|
1420
|
+
* How much of the `X-Forwarded-For` chain to believe. Defaults to `1` trusted
|
|
1421
|
+
* hop: a fetch handler has no socket to fall back on, so there is no
|
|
1422
|
+
* believe-nothing default available. See `resolveClientIp`.
|
|
1423
|
+
*/
|
|
1424
|
+
trustProxy?: TrustedProxies;
|
|
1425
|
+
/** Override IP resolution entirely. */
|
|
1426
|
+
getIP?: (request: Request) => string;
|
|
1427
|
+
/**
|
|
1428
|
+
* Inject a hidden honeytoken link into HTML responses, and arm the tripwire it
|
|
1429
|
+
* points at. Defaults to on when an `apiKey` is present.
|
|
1430
|
+
*/
|
|
1431
|
+
honeytoken?: boolean;
|
|
1432
|
+
/** Build the blocking response. Defaults to 403, or 429 for a throttle. */
|
|
1433
|
+
onBlocked?: (request: Request, decision: Decision) => Response | Promise<Response>;
|
|
1434
|
+
}
|
|
1435
|
+
interface GuardOutcome {
|
|
1436
|
+
/** What the SDK concluded. Always present, in both modes. */
|
|
1437
|
+
decision: Decision;
|
|
1438
|
+
/**
|
|
1439
|
+
* The response to return instead of calling the handler, or undefined to
|
|
1440
|
+
* carry on. Undefined in monitor mode even when the decision is a denial.
|
|
1441
|
+
*/
|
|
1442
|
+
response?: Response;
|
|
1443
|
+
}
|
|
1444
|
+
interface FetchGuard {
|
|
1445
|
+
/** Evaluate one request. */
|
|
1446
|
+
check(request: Request, peer?: string): Promise<GuardOutcome>;
|
|
1447
|
+
/**
|
|
1448
|
+
* Rewrite an HTML response to carry the honeytoken link. Returns the response
|
|
1449
|
+
* unchanged when there is no token yet, or the body is not injectable HTML.
|
|
1450
|
+
*/
|
|
1451
|
+
decorate(response: Response): Promise<Response>;
|
|
1452
|
+
/** Whether this path is skipped. */
|
|
1453
|
+
skips(pathname: string): boolean;
|
|
1454
|
+
/** The underlying SDK, for `detectBot()` and friends. */
|
|
1455
|
+
sdk: WebDecoy;
|
|
1456
|
+
}
|
|
1457
|
+
/**
|
|
1458
|
+
* A guard over WHATWG `Request`/`Response`.
|
|
1459
|
+
*
|
|
1460
|
+
* ```ts
|
|
1461
|
+
* const guard = createFetchGuard({ rules: [tripwire()] });
|
|
1462
|
+
*
|
|
1463
|
+
* export default {
|
|
1464
|
+
* async fetch(request) {
|
|
1465
|
+
* const { response } = await guard.check(request);
|
|
1466
|
+
* if (response) return response;
|
|
1467
|
+
* return guard.decorate(await handle(request));
|
|
1468
|
+
* },
|
|
1469
|
+
* };
|
|
1470
|
+
* ```
|
|
1471
|
+
*/
|
|
1472
|
+
declare function createFetchGuard(options?: FetchGuardOptions): FetchGuard;
|
|
1473
|
+
|
|
1401
1474
|
/**
|
|
1402
1475
|
* AgentVerifier — the public entry point for local Web Bot Auth verification.
|
|
1403
1476
|
*
|
|
@@ -1779,4 +1852,4 @@ declare function createCaptchaEndpoints(options?: CaptchaEndpointsOptions): {
|
|
|
1779
1852
|
};
|
|
1780
1853
|
type CaptchaEndpoints = ReturnType<typeof createCaptchaEndpoints>;
|
|
1781
1854
|
|
|
1782
|
-
export { ATTACK_SIGNATURE_IDS, AgentCategory, AgentRequestInput, AgentVerdict, AgentVerifier, AgentVerifierOptions, type AttackSignatureConfig, AttackSignatureRule, type BehavioralSignals, BotAgent, BotCategory, BotPolicy, type BotPolicyOptions, BotRule, BotRuleConfig, CLIENT_SESSION_COOKIE, CLIENT_SESSION_HEADER, Captcha, type CaptchaEndpoints, type CaptchaEndpointsOptions, type CaptchaHttpResponse, type CaptchaOptions, type CaptchaRequest, type CategoryScores, type ChallengeData, type ChallengeStore, type ClientSignalConfig, ClientSignalRule, type ClientSignalStore, type ClientVerdict, DEFAULT_SIGNED_AGENT_DIRECTORIES, DEFAULT_TRIPWIRE_PATHS, DEFAULT_WEIGHTS, Decision, type Detection, type DetectionContext, DetectionEngine, type DetectionEngineOptions, DirectoryCache, type EnvironmentalSignals, type FetchGuard, type FetchGuardOptions, FilterConfig, FilterRule, type FingerprintStore, type FormAnalysisSignals, type GuardOutcome, HONEYTOKEN_BASE_PATH, type HeaderSource, type Honeytoken, type HoneytokenLinkProps, type HoneytokenOptions, InMemoryChallengeStore, InMemoryFingerprintStore, InMemoryRateLimiter, InMemoryTokenStore, MemoryClientSignalStore, type MemoryClientSignalStoreOptions, PoWManager, type PoWManagerOptions, type PoWOutcome, type PoWSolution, type PoWVerification, ProtectOptions, RateLimitConfig, RateLimitConsume, RateLimitOutcome, RateLimitRule, RateLimitStore, type RateLimiter, type Recommendation, type ResolveClientIpOptions, type RobotsTxtOptions, Rule, RuleContext, RuleEngine, RuleEngineResult, RuleResult, type ScoreResult, type Signals, SignedAgentDirectory, type SiteHoneytoken, type SiteHoneytokenOptions, type StoredChallenge, TEST_TRIGGER_UA_PREFIX, TEST_TRIGGER_USER_AGENT, type TemporalSignals, type TextareaKeyboardStats, TokenManager, type TokenManagerOptions, type TokenStore, type TokenVerification, TripwireConfig, TripwireRule, type TrustedProxies, UpstashRateLimitStore, type UpstashStoreOptions, type Verdict, type VerifyInput, type VerifyResult, type WebBotAuthConfig, WebBotAuthRule, WebDecoy, WebDecoyConfig, attackSignatures, botPolicy, bots, calculateCategoryScores, calculateFinalScore, clientSignals, createAgentVerifier, createCaptchaEndpoints, createFetchGuard, filter, honeytoken, injectHoneytokenLink, ipInCidr, isDatacenterIP, isInjectableHtml, isMobileUA, isTestTriggerUserAgent, normalizeIp, parseUserAgent, rateLimit, readClientSession, recommend, resolveClientIp, resolveSecret, siteHoneytoken, tripwire, upstashRateLimitStore, webBotAuth };
|
|
1855
|
+
export { ATTACK_SIGNATURE_IDS, AgentCategory, AgentRequestInput, AgentVerdict, AgentVerifier, AgentVerifierOptions, type AttackSignatureConfig, AttackSignatureRule, type BehavioralSignals, type BlockResponse, BotAgent, BotCategory, BotPolicy, type BotPolicyOptions, BotRule, BotRuleConfig, CLIENT_SESSION_COOKIE, CLIENT_SESSION_HEADER, Captcha, type CaptchaEndpoints, type CaptchaEndpointsOptions, type CaptchaHttpResponse, type CaptchaOptions, type CaptchaRequest, type CategoryScores, type ChallengeData, type ChallengeStore, type ClientSignalConfig, ClientSignalRule, type ClientSignalStore, type ClientVerdict, DEFAULT_SIGNED_AGENT_DIRECTORIES, DEFAULT_TRIPWIRE_PATHS, DEFAULT_WEIGHTS, Decision, type Detection, type DetectionContext, DetectionEngine, type DetectionEngineOptions, DirectoryCache, type EnvironmentalSignals, type FetchGuard, type FetchGuardOptions, FilterConfig, FilterRule, type FingerprintStore, type FormAnalysisSignals, type GuardOutcome, HONEYTOKEN_BASE_PATH, type HeaderSource, type Honeytoken, type HoneytokenArmingOptions, type HoneytokenLinkProps, type HoneytokenOptions, InMemoryChallengeStore, InMemoryFingerprintStore, InMemoryRateLimiter, InMemoryTokenStore, MemoryClientSignalStore, type MemoryClientSignalStoreOptions, PoWManager, type PoWManagerOptions, type PoWOutcome, type PoWSolution, type PoWVerification, ProtectOptions, ProtectResult, RateLimitConfig, RateLimitConsume, RateLimitOutcome, RateLimitRule, RateLimitStore, type RateLimiter, type Recommendation, type ResolveClientIpOptions, type RobotsTxtOptions, Rule, RuleContext, RuleEngine, RuleEngineResult, RuleResult, type ScoreResult, type Signals, SignedAgentDirectory, type SiteHoneytoken, type SiteHoneytokenOptions, type StoredChallenge, TEST_TRIGGER_UA_PREFIX, TEST_TRIGGER_USER_AGENT, type TemporalSignals, type TextareaKeyboardStats, TokenManager, type TokenManagerOptions, type TokenStore, type TokenVerification, TripwireConfig, TripwireRule, type TrustedProxies, UpstashRateLimitStore, type UpstashStoreOptions, type Verdict, type VerifyInput, type VerifyResult, type WebBotAuthConfig, WebBotAuthRule, WebDecoy, WebDecoyConfig, armSiteHoneytoken, attackSignatures, botPolicy, bots, calculateCategoryScores, calculateFinalScore, clientSignals, createAgentVerifier, createCaptchaEndpoints, createFetchGuard, deriveAndArm, filter, honeytoken, injectHoneytokenLink, ipInCidr, isDatacenterIP, isInjectableHtml, isMobileUA, isTestTriggerUserAgent, normalizeIp, parseUserAgent, rateLimit, readClientSession, recommend, resolveClientIp, resolveSecret, ruleBlockResponse, shouldSkipPath, siteHoneytoken, tripwire, upstashRateLimitStore, webBotAuth };
|