@webdecoy/node 0.15.1 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-T6MX62T5.mjs → chunk-MHCY2FDT.mjs} +188 -16
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +195 -23
- package/dist/index.mjs +1 -1
- package/dist/{sdk-qUjMf8ZX.d.mts → sdk-BTqYTW4I.d.mts} +40 -1
- package/dist/{sdk-qUjMf8ZX.d.ts → sdk-BTqYTW4I.d.ts} +40 -1
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +188 -16
- package/dist/testing.mjs +1 -1
- package/package.json +2 -2
|
@@ -865,10 +865,9 @@ var BOT_CATEGORIES = [
|
|
|
865
865
|
var BOT_REGISTRY = [
|
|
866
866
|
{ id: "reflectionbot", name: "Reflectionbot", category: "training_crawler", organization: "Reflection AI", baseScore: 70, respectsRobots: true, uaPatterns: ["reflectionbot"] },
|
|
867
867
|
{ id: "gptbot", name: "GPTBot", category: "training_crawler", organization: "OpenAI", baseScore: 85, respectsRobots: true, uaPatterns: ["gptbot"] },
|
|
868
|
-
{ id: "chatgpt-user", name: "ChatGPT-User", category: "training_crawler", organization: "OpenAI", baseScore: 85, respectsRobots: true, uaPatterns: ["chatgpt-user", "chatgpt"] },
|
|
869
|
-
{ id: "oai-searchbot", name: "OAI-SearchBot", category: "training_crawler", organization: "OpenAI", baseScore: 80, respectsRobots: true, uaPatterns: ["oai-searchbot"] },
|
|
870
868
|
{ id: "claudebot", name: "ClaudeBot", category: "training_crawler", organization: "Anthropic", baseScore: 85, respectsRobots: true, uaPatterns: ["claudebot"] },
|
|
871
|
-
{ id: "anthropic", name: "Anthropic", category: "training_crawler", organization: "Anthropic", baseScore: 85, respectsRobots: true, uaPatterns: ["anthropic"] },
|
|
869
|
+
{ id: "anthropic", name: "Anthropic", category: "training_crawler", organization: "Anthropic", baseScore: 85, respectsRobots: true, uaPatterns: ["anthropic-ai"] },
|
|
870
|
+
{ id: "claude-web", name: "Claude-Web", category: "training_crawler", organization: "Anthropic", baseScore: 85, respectsRobots: true, uaPatterns: ["claude-web"] },
|
|
872
871
|
{ id: "ccbot", name: "CCBot", category: "training_crawler", organization: "Common Crawl", baseScore: 80, respectsRobots: true, uaPatterns: ["ccbot"] },
|
|
873
872
|
{ id: "google-extended", name: "Google-Extended", category: "training_crawler", organization: "Google", baseScore: 80, respectsRobots: true, uaPatterns: ["google-extended"] },
|
|
874
873
|
{ id: "bytespider", name: "ByteSpider", category: "training_crawler", organization: "ByteDance", baseScore: 75, respectsRobots: false, uaPatterns: ["bytespider"] },
|
|
@@ -876,10 +875,9 @@ var BOT_REGISTRY = [
|
|
|
876
875
|
{ id: "facebookbot", name: "FacebookBot", category: "training_crawler", organization: "Meta", baseScore: 70, respectsRobots: true, uaPatterns: ["facebookbot"] },
|
|
877
876
|
{ id: "meta-externalagent", name: "Meta-ExternalAgent", category: "training_crawler", organization: "Meta", baseScore: 75, respectsRobots: true, uaPatterns: ["meta-externalagent"] },
|
|
878
877
|
{ id: "cohere-ai", name: "Cohere", category: "training_crawler", organization: "Cohere", baseScore: 80, respectsRobots: true, uaPatterns: ["cohere-ai", "cohere"] },
|
|
879
|
-
{ id: "perplexitybot", name: "PerplexityBot", category: "training_crawler", organization: "Perplexity AI", baseScore: 80, respectsRobots: true, uaPatterns: ["perplexitybot"] },
|
|
880
878
|
{ id: "applebot-extended", name: "Applebot-Extended", category: "training_crawler", organization: "Apple", baseScore: 75, respectsRobots: true, uaPatterns: ["applebot-extended"] },
|
|
881
879
|
{ id: "youbot", name: "YouBot", category: "training_crawler", organization: "You.com", baseScore: 75, respectsRobots: true, uaPatterns: ["youbot"] },
|
|
882
|
-
{ id: "mistral", name: "MistralBot", category: "training_crawler", organization: "Mistral AI", baseScore: 80, respectsRobots: true, uaPatterns: ["
|
|
880
|
+
{ id: "mistral", name: "MistralBot", category: "training_crawler", organization: "Mistral AI", baseScore: 80, respectsRobots: true, uaPatterns: ["mistralbot"] },
|
|
883
881
|
{ id: "gemini", name: "Gemini", category: "training_crawler", organization: "Google", baseScore: 80, respectsRobots: true, uaPatterns: ["gemini"] },
|
|
884
882
|
{ id: "ai2bot", name: "AI2Bot", category: "training_crawler", organization: "Allen Institute for AI", baseScore: 75, respectsRobots: true, uaPatterns: ["ai2bot"] },
|
|
885
883
|
{ id: "deepseek", name: "DeepSeek", category: "training_crawler", organization: "DeepSeek", baseScore: 80, respectsRobots: true, uaPatterns: ["deepseek"] },
|
|
@@ -896,6 +894,9 @@ var BOT_REGISTRY = [
|
|
|
896
894
|
{ id: "sofyabot", name: "SofyaBot", category: "ai_search_crawler", organization: "Sofya", baseScore: 65, respectsRobots: true, uaPatterns: ["sofyabot"] },
|
|
897
895
|
{ id: "xai-searchbot", name: "xAI-SearchBot", category: "ai_search_crawler", organization: "xAI", baseScore: 70, respectsRobots: true, uaPatterns: ["xai-searchbot"] },
|
|
898
896
|
{ id: "linkupbot", name: "LinkupBot", category: "ai_search_crawler", organization: "Linkup", baseScore: 65, respectsRobots: true, uaPatterns: ["linkupbot"] },
|
|
897
|
+
{ id: "perplexitybot", name: "PerplexityBot", category: "ai_search_crawler", organization: "Perplexity AI", baseScore: 80, respectsRobots: true, uaPatterns: ["perplexitybot"] },
|
|
898
|
+
{ id: "claude-searchbot", name: "Claude-SearchBot", category: "ai_search_crawler", organization: "Anthropic", baseScore: 75, respectsRobots: true, uaPatterns: ["claude-searchbot"] },
|
|
899
|
+
{ id: "oai-searchbot", name: "OAI-SearchBot", category: "ai_search_crawler", organization: "OpenAI", baseScore: 80, respectsRobots: true, uaPatterns: ["oai-searchbot"] },
|
|
899
900
|
{ id: "searchgpt", name: "SearchGPT", category: "ai_search_crawler", organization: "OpenAI", baseScore: 75, respectsRobots: true, uaPatterns: ["searchgpt"] },
|
|
900
901
|
{ id: "phind", name: "Phind", category: "ai_search_crawler", organization: "Phind", baseScore: 70, respectsRobots: true, uaPatterns: ["phind"] },
|
|
901
902
|
{ id: "kagi", name: "Kagi", category: "ai_search_crawler", organization: "Kagi", baseScore: 65, respectsRobots: true, uaPatterns: ["kagi"] },
|
|
@@ -914,7 +915,9 @@ var BOT_REGISTRY = [
|
|
|
914
915
|
{ id: "multion", name: "MultiOn", category: "ai_agent", organization: "MultiOn", baseScore: 70, respectsRobots: false, uaPatterns: ["multion"] },
|
|
915
916
|
{ id: "iboubot", name: "IbouBot", category: "search_crawler", organization: "Ibou", baseScore: 30, respectsRobots: true, uaPatterns: ["iboubot"] },
|
|
916
917
|
{ id: "googlebot", name: "Googlebot", category: "search_crawler", organization: "Google", baseScore: 30, respectsRobots: true, uaPatterns: ["googlebot"] },
|
|
918
|
+
{ id: "google-inspectiontool", name: "Google-InspectionTool", category: "search_crawler", organization: "Google", baseScore: 30, respectsRobots: true, uaPatterns: ["google-inspectiontool"] },
|
|
917
919
|
{ id: "bingbot", name: "Bingbot", category: "search_crawler", organization: "Microsoft", baseScore: 30, respectsRobots: true, uaPatterns: ["bingbot"] },
|
|
920
|
+
{ id: "msnbot", name: "MSNBot", category: "search_crawler", organization: "Microsoft", baseScore: 30, respectsRobots: true, uaPatterns: ["msnbot"] },
|
|
918
921
|
{ id: "yandexbot", name: "YandexBot", category: "search_crawler", organization: "Yandex", baseScore: 35, respectsRobots: true, uaPatterns: ["yandexbot"] },
|
|
919
922
|
{ id: "baiduspider", name: "Baiduspider", category: "search_crawler", organization: "Baidu", baseScore: 40, respectsRobots: true, uaPatterns: ["baiduspider"] },
|
|
920
923
|
{ id: "duckduckbot", name: "DuckDuckBot", category: "search_crawler", organization: "DuckDuckGo", baseScore: 30, respectsRobots: true, uaPatterns: ["duckduckbot"] },
|
|
@@ -989,6 +992,7 @@ var BOT_REGISTRY = [
|
|
|
989
992
|
{ id: "heritrix", name: "Heritrix", category: "archiver", organization: "Internet Archive", baseScore: 30, respectsRobots: true, uaPatterns: ["heritrix"] },
|
|
990
993
|
{ id: "brozzler", name: "Brozzler", category: "archiver", organization: "Internet Archive", baseScore: 30, respectsRobots: true, uaPatterns: ["brozzler"] },
|
|
991
994
|
{ id: "facebookexternalhit", name: "Facebook", category: "fetcher", organization: "Meta", baseScore: 25, respectsRobots: true, uaPatterns: ["facebookexternalhit"] },
|
|
995
|
+
{ id: "facebot", name: "Facebot", category: "fetcher", organization: "Meta", baseScore: 25, respectsRobots: true, uaPatterns: ["facebot"] },
|
|
992
996
|
{ id: "twitterbot", name: "Twitterbot", category: "fetcher", organization: "X Corp", baseScore: 25, respectsRobots: true, uaPatterns: ["twitterbot"] },
|
|
993
997
|
{ id: "linkedinbot", name: "LinkedInBot", category: "fetcher", organization: "LinkedIn", baseScore: 25, respectsRobots: true, uaPatterns: ["linkedinbot"] },
|
|
994
998
|
{ id: "slackbot", name: "Slackbot", category: "fetcher", organization: "Slack", baseScore: 25, respectsRobots: true, uaPatterns: ["slackbot"] },
|
|
@@ -1016,7 +1020,10 @@ var BOT_REGISTRY = [
|
|
|
1016
1020
|
{ id: "freshping", name: "Freshping", category: "monitoring", organization: "Freshworks", baseScore: 20, respectsRobots: true, uaPatterns: ["freshping"] },
|
|
1017
1021
|
{ id: "hetrixtools", name: "HetrixTools", category: "monitoring", organization: "HetrixTools", baseScore: 20, respectsRobots: true, uaPatterns: ["hetrixtools"] },
|
|
1018
1022
|
{ id: "nodeping", name: "NodePing", category: "monitoring", organization: "NodePing", baseScore: 20, respectsRobots: true, uaPatterns: ["nodeping"] },
|
|
1023
|
+
{ id: "gtmetrix", name: "GTmetrix", category: "monitoring", organization: "GTmetrix", baseScore: 20, respectsRobots: true, uaPatterns: ["gtmetrix"] },
|
|
1024
|
+
{ id: "chrome-lighthouse", name: "Lighthouse", category: "monitoring", organization: "Google", baseScore: 20, respectsRobots: true, uaPatterns: ["chrome-lighthouse", "google page speed"] },
|
|
1019
1025
|
{ id: "feedly", name: "Feedly", category: "feed_reader", organization: "Feedly", baseScore: 25, respectsRobots: true, uaPatterns: ["feedly"] },
|
|
1026
|
+
{ id: "feedfetcher-google", name: "Feedfetcher-Google", category: "feed_reader", organization: "Google", baseScore: 25, respectsRobots: true, uaPatterns: ["feedfetcher"] },
|
|
1020
1027
|
{ id: "newsblur", name: "NewsBlur", category: "feed_reader", organization: "NewsBlur", baseScore: 25, respectsRobots: true, uaPatterns: ["newsblur"] },
|
|
1021
1028
|
{ id: "inoreader", name: "Inoreader", category: "feed_reader", organization: "Inoreader", baseScore: 25, respectsRobots: true, uaPatterns: ["inoreader"] },
|
|
1022
1029
|
{ id: "theoldreader", name: "The Old Reader", category: "feed_reader", organization: "The Old Reader", baseScore: 25, respectsRobots: true, uaPatterns: ["theoldreader"] },
|
|
@@ -1034,6 +1041,10 @@ var BOT_REGISTRY = [
|
|
|
1034
1041
|
{ id: "apify", name: "Apify", category: "commercial_scraper", organization: "Apify", baseScore: 65, respectsRobots: true, uaPatterns: ["apify"] },
|
|
1035
1042
|
{ id: "crawlbase", name: "Crawlbase", category: "commercial_scraper", organization: "Crawlbase", baseScore: 65, respectsRobots: true, uaPatterns: ["crawlbase"] },
|
|
1036
1043
|
{ id: "webscrapingapi", name: "WebScrapingAPI", category: "commercial_scraper", organization: "WebScrapingAPI", baseScore: 65, respectsRobots: true, uaPatterns: ["webscrapingapi"] },
|
|
1044
|
+
{ id: "chatgpt-user", name: "ChatGPT-User", category: "ai_assistant", organization: "OpenAI", baseScore: 85, respectsRobots: true, uaPatterns: ["chatgpt-user"] },
|
|
1045
|
+
{ id: "perplexity-user", name: "Perplexity-User", category: "ai_assistant", organization: "Perplexity AI", baseScore: 75, respectsRobots: false, uaPatterns: ["perplexity-user"] },
|
|
1046
|
+
{ id: "mistralai-user", name: "MistralAI-User", category: "ai_assistant", organization: "Mistral AI", baseScore: 75, respectsRobots: true, uaPatterns: ["mistralai-user"] },
|
|
1047
|
+
{ id: "meta-externalfetcher", name: "Meta-ExternalFetcher", category: "ai_assistant", organization: "Meta", baseScore: 70, respectsRobots: false, uaPatterns: ["meta-externalfetcher"] },
|
|
1037
1048
|
{ id: "gemini-deep-research", name: "Gemini-Deep-Research", category: "ai_assistant", organization: "Google", baseScore: 65, respectsRobots: true, uaPatterns: ["gemini-deep-research"] },
|
|
1038
1049
|
{ id: "copilot", name: "Microsoft Copilot", category: "ai_assistant", organization: "Microsoft", baseScore: 65, respectsRobots: true, uaPatterns: ["copilot"] },
|
|
1039
1050
|
{ id: "cortana", name: "Cortana", category: "ai_assistant", organization: "Microsoft", baseScore: 60, respectsRobots: true, uaPatterns: ["cortana"] },
|
|
@@ -2074,16 +2085,16 @@ function componentValue(req, c) {
|
|
|
2074
2085
|
case "@query":
|
|
2075
2086
|
return req.url.search === "" ? "?" : req.url.search;
|
|
2076
2087
|
case "signature-agent": {
|
|
2077
|
-
const
|
|
2078
|
-
if (
|
|
2079
|
-
if (c.keyParam !== void 0) return dictMemberValue(
|
|
2080
|
-
return
|
|
2088
|
+
const header2 = req.headers.get("signature-agent");
|
|
2089
|
+
if (header2 === null) throw new Error("signature-agent covered but absent");
|
|
2090
|
+
if (c.keyParam !== void 0) return dictMemberValue(header2, c.keyParam);
|
|
2091
|
+
return header2.trim().replace(/\s+/g, " ");
|
|
2081
2092
|
}
|
|
2082
2093
|
default: {
|
|
2083
2094
|
if (name.startsWith("@")) throw new Error(`unsupported derived component ${name}`);
|
|
2084
|
-
const
|
|
2085
|
-
if (
|
|
2086
|
-
return
|
|
2095
|
+
const header2 = req.headers.get(name);
|
|
2096
|
+
if (header2 === null) throw new Error(`covered header ${name} absent`);
|
|
2097
|
+
return header2.trim().replace(/\s+/g, " ");
|
|
2087
2098
|
}
|
|
2088
2099
|
}
|
|
2089
2100
|
}
|
|
@@ -2096,8 +2107,8 @@ function canonicalAuthority(url) {
|
|
|
2096
2107
|
}
|
|
2097
2108
|
return `${host}:${port}`;
|
|
2098
2109
|
}
|
|
2099
|
-
function dictMemberValue(
|
|
2100
|
-
const dict = parseDictionary(
|
|
2110
|
+
function dictMemberValue(header2, key) {
|
|
2111
|
+
const dict = parseDictionary(header2);
|
|
2101
2112
|
const found = dict.find((d) => d.key === key);
|
|
2102
2113
|
if (!found) throw new Error(`signature-agent has no member ${key}`);
|
|
2103
2114
|
return found.raw;
|
|
@@ -2541,6 +2552,23 @@ var WebDecoyClient = class {
|
|
|
2541
2552
|
}
|
|
2542
2553
|
}
|
|
2543
2554
|
}
|
|
2555
|
+
/**
|
|
2556
|
+
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
2557
|
+
* accepted, or refused for a reason a retry cannot fix (a 4xx). Only a
|
|
2558
|
+
* server error or a network failure resolves false, so the caller retries
|
|
2559
|
+
* the same batch id.
|
|
2560
|
+
*/
|
|
2561
|
+
async sendAIReferrals(batch) {
|
|
2562
|
+
try {
|
|
2563
|
+
const response = await this.request("POST", "/api/v1/sdk/ai-referrals", batch);
|
|
2564
|
+
return response.status < 500;
|
|
2565
|
+
} catch (error) {
|
|
2566
|
+
if (this.config.debug) {
|
|
2567
|
+
console.error("[WebDecoy] Failed to send AI referrals:", error);
|
|
2568
|
+
}
|
|
2569
|
+
return false;
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2544
2572
|
/**
|
|
2545
2573
|
* Get IP enrichment data from the ingest service
|
|
2546
2574
|
*/
|
|
@@ -2655,7 +2683,7 @@ function hasSuspiciousHeaders(metadata) {
|
|
|
2655
2683
|
const headers = metadata.headers || {};
|
|
2656
2684
|
const hasBotUA = SUSPICIOUS_PATTERNS.userAgents.some((pattern) => pattern.test(userAgent));
|
|
2657
2685
|
const missingCommonHeaders = SUSPICIOUS_PATTERNS.missingHeaders.filter(
|
|
2658
|
-
(
|
|
2686
|
+
(header2) => !headers[header2] && !headers[header2.toLowerCase()]
|
|
2659
2687
|
);
|
|
2660
2688
|
return hasBotUA || missingCommonHeaders.length > 0;
|
|
2661
2689
|
}
|
|
@@ -2767,6 +2795,143 @@ var ViolationReporter = class {
|
|
|
2767
2795
|
}
|
|
2768
2796
|
};
|
|
2769
2797
|
|
|
2798
|
+
// src/referrals/llm-platforms.generated.ts
|
|
2799
|
+
var LLM_PLATFORMS = {
|
|
2800
|
+
"chat.deepseek.com": "DeepSeek",
|
|
2801
|
+
"chat.openai.com": "ChatGPT",
|
|
2802
|
+
"chatgpt.com": "ChatGPT",
|
|
2803
|
+
"claude.ai": "Claude",
|
|
2804
|
+
"copilot.microsoft.com": "Copilot",
|
|
2805
|
+
"deepseek.com": "DeepSeek",
|
|
2806
|
+
"gemini.google.com": "Gemini",
|
|
2807
|
+
"grok.com": "Grok",
|
|
2808
|
+
"kagi.com": "Kagi",
|
|
2809
|
+
"meta.ai": "Meta AI",
|
|
2810
|
+
"perplexity.ai": "Perplexity",
|
|
2811
|
+
"phind.com": "Phind",
|
|
2812
|
+
"www.deepseek.com": "DeepSeek",
|
|
2813
|
+
"www.grok.com": "Grok",
|
|
2814
|
+
"www.kagi.com": "Kagi",
|
|
2815
|
+
"www.meta.ai": "Meta AI",
|
|
2816
|
+
"www.perplexity.ai": "Perplexity",
|
|
2817
|
+
"www.phind.com": "Phind",
|
|
2818
|
+
"www.you.com": "You.com",
|
|
2819
|
+
"you.com": "You.com"
|
|
2820
|
+
};
|
|
2821
|
+
|
|
2822
|
+
// src/referrals/llm-referral.ts
|
|
2823
|
+
var TAG_KEYS = ["utm_source", "ref", "utm_medium"];
|
|
2824
|
+
function classifyReferral(referer, pageUrl) {
|
|
2825
|
+
const ref = (referer ?? "").trim();
|
|
2826
|
+
if (ref) {
|
|
2827
|
+
try {
|
|
2828
|
+
return LLM_PLATFORMS[new URL(ref).hostname.toLowerCase()] ?? "";
|
|
2829
|
+
} catch {
|
|
2830
|
+
return "";
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
let url;
|
|
2834
|
+
try {
|
|
2835
|
+
url = new URL(pageUrl);
|
|
2836
|
+
} catch {
|
|
2837
|
+
return "";
|
|
2838
|
+
}
|
|
2839
|
+
for (const key of TAG_KEYS) {
|
|
2840
|
+
for (const value of url.searchParams.getAll(key)) {
|
|
2841
|
+
const platform = platformForTag(value);
|
|
2842
|
+
if (platform) return platform;
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
return "";
|
|
2846
|
+
}
|
|
2847
|
+
var squash = (s) => s.replace(/[ \-_.]/g, "");
|
|
2848
|
+
function platformForTag(raw) {
|
|
2849
|
+
let value = raw.trim().toLowerCase();
|
|
2850
|
+
if (!value) return "";
|
|
2851
|
+
try {
|
|
2852
|
+
const host = new URL(value).hostname;
|
|
2853
|
+
if (host) value = host.toLowerCase();
|
|
2854
|
+
} catch {
|
|
2855
|
+
}
|
|
2856
|
+
value = value.replace(/\.$/, "");
|
|
2857
|
+
if (LLM_PLATFORMS[value]) return LLM_PLATFORMS[value];
|
|
2858
|
+
const normalized = squash(value);
|
|
2859
|
+
for (const [domain, name] of Object.entries(LLM_PLATFORMS)) {
|
|
2860
|
+
if (normalized === squash(name.toLowerCase()) || normalized === domain.replace(/^www\./, "").replace(/\./g, "")) {
|
|
2861
|
+
return name;
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2864
|
+
return "";
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2867
|
+
// src/referrals/referral-counter.ts
|
|
2868
|
+
var MAX_PATH = 500;
|
|
2869
|
+
var MAX_ENTRIES = 500;
|
|
2870
|
+
var header = (headers, name) => {
|
|
2871
|
+
const v = headers[name] ?? headers[name.toLowerCase()];
|
|
2872
|
+
if (v !== void 0) return v;
|
|
2873
|
+
for (const [k, value] of Object.entries(headers)) if (k.toLowerCase() === name) return value;
|
|
2874
|
+
return "";
|
|
2875
|
+
};
|
|
2876
|
+
var AIReferralCounter = class {
|
|
2877
|
+
constructor(sender, config = {}) {
|
|
2878
|
+
this.sender = sender;
|
|
2879
|
+
this.counts = /* @__PURE__ */ new Map();
|
|
2880
|
+
/** A batch that failed to send, retried under the same id so it counts once. */
|
|
2881
|
+
this.pending = null;
|
|
2882
|
+
this.flushing = false;
|
|
2883
|
+
this.timer = setInterval(() => void this.flush(), config.flushInterval ?? 6e4);
|
|
2884
|
+
this.timer.unref?.();
|
|
2885
|
+
}
|
|
2886
|
+
/** Count the request if it is a page visit an AI product sent. Never throws. */
|
|
2887
|
+
observe(metadata) {
|
|
2888
|
+
try {
|
|
2889
|
+
if ((metadata.method ?? "").toUpperCase() !== "GET") return;
|
|
2890
|
+
const headers = metadata.headers ?? {};
|
|
2891
|
+
if (header(headers, "sec-fetch-mode") !== "navigate") return;
|
|
2892
|
+
const dest = header(headers, "sec-fetch-dest");
|
|
2893
|
+
if (dest && dest !== "document") return;
|
|
2894
|
+
const path = (metadata.path || "/").split("?")[0] || "/";
|
|
2895
|
+
const query = metadata.query ? `?${metadata.query}` : "";
|
|
2896
|
+
const platform = classifyReferral(header(headers, "referer"), `https://site.invalid${path}${query}`);
|
|
2897
|
+
if (!platform) return;
|
|
2898
|
+
const landing = path.length > MAX_PATH ? path.slice(0, MAX_PATH) : path;
|
|
2899
|
+
const key = `${platform}
|
|
2900
|
+
${landing}`;
|
|
2901
|
+
const entry = this.counts.get(key);
|
|
2902
|
+
if (entry) {
|
|
2903
|
+
entry.count++;
|
|
2904
|
+
} else {
|
|
2905
|
+
this.counts.set(key, { platform, path: landing, count: 1 });
|
|
2906
|
+
if (this.counts.size >= MAX_ENTRIES) void this.flush();
|
|
2907
|
+
}
|
|
2908
|
+
} catch {
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
/** Send what has been counted. Never rejects. */
|
|
2912
|
+
async flush() {
|
|
2913
|
+
if (this.flushing) return;
|
|
2914
|
+
this.flushing = true;
|
|
2915
|
+
try {
|
|
2916
|
+
if (!this.pending && this.counts.size > 0) {
|
|
2917
|
+
this.pending = { report_id: crypto.randomUUID(), source: "sdk", referrals: [...this.counts.values()] };
|
|
2918
|
+
this.counts = /* @__PURE__ */ new Map();
|
|
2919
|
+
}
|
|
2920
|
+
if (this.pending && await this.sender.sendAIReferrals(this.pending)) {
|
|
2921
|
+
this.pending = null;
|
|
2922
|
+
}
|
|
2923
|
+
} catch {
|
|
2924
|
+
} finally {
|
|
2925
|
+
this.flushing = false;
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
/** Stop the timer and send what is left. */
|
|
2929
|
+
async destroy() {
|
|
2930
|
+
clearInterval(this.timer);
|
|
2931
|
+
await this.flush();
|
|
2932
|
+
}
|
|
2933
|
+
};
|
|
2934
|
+
|
|
2770
2935
|
// src/ip-enrichment.ts
|
|
2771
2936
|
var IPEnrichmentClient = class {
|
|
2772
2937
|
constructor(client, ttlMs = 36e5) {
|
|
@@ -2855,6 +3020,7 @@ function endSpan(span) {
|
|
|
2855
3020
|
// src/sdk.ts
|
|
2856
3021
|
var WebDecoy = class {
|
|
2857
3022
|
constructor(config) {
|
|
3023
|
+
this.referralCounter = null;
|
|
2858
3024
|
this.violationReporter = null;
|
|
2859
3025
|
this.ipEnrichmentClient = null;
|
|
2860
3026
|
this._hasFilterRules = false;
|
|
@@ -2876,7 +3042,8 @@ var WebDecoy = class {
|
|
|
2876
3042
|
threatScoreThreshold: config.threatScoreThreshold ?? 80,
|
|
2877
3043
|
timeout: config.timeout ?? 5e3,
|
|
2878
3044
|
debug: config.debug ?? false,
|
|
2879
|
-
tlsRejectUnauthorized: config.tlsRejectUnauthorized ?? true
|
|
3045
|
+
tlsRejectUnauthorized: config.tlsRejectUnauthorized ?? true,
|
|
3046
|
+
countAIReferrals: config.countAIReferrals ?? true
|
|
2880
3047
|
};
|
|
2881
3048
|
this.log = resolveLogger(config.logger, this.config.debug);
|
|
2882
3049
|
this.tracer = config.tracer;
|
|
@@ -2910,6 +3077,9 @@ var WebDecoy = class {
|
|
|
2910
3077
|
if (this.client && this._hasFilterRules) {
|
|
2911
3078
|
this.ipEnrichmentClient = new IPEnrichmentClient(this.client);
|
|
2912
3079
|
}
|
|
3080
|
+
if (this.client && this.config.countAIReferrals !== false) {
|
|
3081
|
+
this.referralCounter = new AIReferralCounter(this.client);
|
|
3082
|
+
}
|
|
2913
3083
|
if (this.client && this.ruleEngine) {
|
|
2914
3084
|
const reporter = new ViolationReporter(this.client, {
|
|
2915
3085
|
debug: this.config.debug
|
|
@@ -3081,6 +3251,7 @@ var WebDecoy = class {
|
|
|
3081
3251
|
*/
|
|
3082
3252
|
async protect(metadata, options = {}) {
|
|
3083
3253
|
const edge = readEdgeVerdict(metadata.headers);
|
|
3254
|
+
this.referralCounter?.observe(metadata);
|
|
3084
3255
|
const span = startSpan(this.tracer, "webdecoy.protect");
|
|
3085
3256
|
try {
|
|
3086
3257
|
const decision = (await this.decide(metadata, options)).withEdge(edge);
|
|
@@ -3342,6 +3513,7 @@ var WebDecoy = class {
|
|
|
3342
3513
|
if (this.violationReporter) {
|
|
3343
3514
|
await this.violationReporter.destroy();
|
|
3344
3515
|
}
|
|
3516
|
+
await this.referralCounter?.destroy();
|
|
3345
3517
|
}
|
|
3346
3518
|
};
|
|
3347
3519
|
function agentInputFromMetadata(metadata) {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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-
|
|
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-
|
|
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-BTqYTW4I.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-BTqYTW4I.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The reserved test trigger.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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-
|
|
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-
|
|
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-BTqYTW4I.js';
|
|
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-BTqYTW4I.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The reserved test trigger.
|
package/dist/index.js
CHANGED
|
@@ -204,6 +204,23 @@ var WebDecoyClient = class {
|
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
209
|
+
* accepted, or refused for a reason a retry cannot fix (a 4xx). Only a
|
|
210
|
+
* server error or a network failure resolves false, so the caller retries
|
|
211
|
+
* the same batch id.
|
|
212
|
+
*/
|
|
213
|
+
async sendAIReferrals(batch) {
|
|
214
|
+
try {
|
|
215
|
+
const response = await this.request("POST", "/api/v1/sdk/ai-referrals", batch);
|
|
216
|
+
return response.status < 500;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (this.config.debug) {
|
|
219
|
+
console.error("[WebDecoy] Failed to send AI referrals:", error);
|
|
220
|
+
}
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
207
224
|
/**
|
|
208
225
|
* Get IP enrichment data from the ingest service
|
|
209
226
|
*/
|
|
@@ -318,7 +335,7 @@ function hasSuspiciousHeaders(metadata) {
|
|
|
318
335
|
const headers = metadata.headers || {};
|
|
319
336
|
const hasBotUA = SUSPICIOUS_PATTERNS.userAgents.some((pattern) => pattern.test(userAgent));
|
|
320
337
|
const missingCommonHeaders = SUSPICIOUS_PATTERNS.missingHeaders.filter(
|
|
321
|
-
(
|
|
338
|
+
(header2) => !headers[header2] && !headers[header2.toLowerCase()]
|
|
322
339
|
);
|
|
323
340
|
return hasBotUA || missingCommonHeaders.length > 0;
|
|
324
341
|
}
|
|
@@ -1241,10 +1258,9 @@ var BOT_CATEGORIES = [
|
|
|
1241
1258
|
var BOT_REGISTRY = [
|
|
1242
1259
|
{ id: "reflectionbot", name: "Reflectionbot", category: "training_crawler", organization: "Reflection AI", baseScore: 70, respectsRobots: true, uaPatterns: ["reflectionbot"] },
|
|
1243
1260
|
{ id: "gptbot", name: "GPTBot", category: "training_crawler", organization: "OpenAI", baseScore: 85, respectsRobots: true, uaPatterns: ["gptbot"] },
|
|
1244
|
-
{ id: "chatgpt-user", name: "ChatGPT-User", category: "training_crawler", organization: "OpenAI", baseScore: 85, respectsRobots: true, uaPatterns: ["chatgpt-user", "chatgpt"] },
|
|
1245
|
-
{ id: "oai-searchbot", name: "OAI-SearchBot", category: "training_crawler", organization: "OpenAI", baseScore: 80, respectsRobots: true, uaPatterns: ["oai-searchbot"] },
|
|
1246
1261
|
{ id: "claudebot", name: "ClaudeBot", category: "training_crawler", organization: "Anthropic", baseScore: 85, respectsRobots: true, uaPatterns: ["claudebot"] },
|
|
1247
|
-
{ id: "anthropic", name: "Anthropic", category: "training_crawler", organization: "Anthropic", baseScore: 85, respectsRobots: true, uaPatterns: ["anthropic"] },
|
|
1262
|
+
{ id: "anthropic", name: "Anthropic", category: "training_crawler", organization: "Anthropic", baseScore: 85, respectsRobots: true, uaPatterns: ["anthropic-ai"] },
|
|
1263
|
+
{ id: "claude-web", name: "Claude-Web", category: "training_crawler", organization: "Anthropic", baseScore: 85, respectsRobots: true, uaPatterns: ["claude-web"] },
|
|
1248
1264
|
{ id: "ccbot", name: "CCBot", category: "training_crawler", organization: "Common Crawl", baseScore: 80, respectsRobots: true, uaPatterns: ["ccbot"] },
|
|
1249
1265
|
{ id: "google-extended", name: "Google-Extended", category: "training_crawler", organization: "Google", baseScore: 80, respectsRobots: true, uaPatterns: ["google-extended"] },
|
|
1250
1266
|
{ id: "bytespider", name: "ByteSpider", category: "training_crawler", organization: "ByteDance", baseScore: 75, respectsRobots: false, uaPatterns: ["bytespider"] },
|
|
@@ -1252,10 +1268,9 @@ var BOT_REGISTRY = [
|
|
|
1252
1268
|
{ id: "facebookbot", name: "FacebookBot", category: "training_crawler", organization: "Meta", baseScore: 70, respectsRobots: true, uaPatterns: ["facebookbot"] },
|
|
1253
1269
|
{ id: "meta-externalagent", name: "Meta-ExternalAgent", category: "training_crawler", organization: "Meta", baseScore: 75, respectsRobots: true, uaPatterns: ["meta-externalagent"] },
|
|
1254
1270
|
{ id: "cohere-ai", name: "Cohere", category: "training_crawler", organization: "Cohere", baseScore: 80, respectsRobots: true, uaPatterns: ["cohere-ai", "cohere"] },
|
|
1255
|
-
{ id: "perplexitybot", name: "PerplexityBot", category: "training_crawler", organization: "Perplexity AI", baseScore: 80, respectsRobots: true, uaPatterns: ["perplexitybot"] },
|
|
1256
1271
|
{ id: "applebot-extended", name: "Applebot-Extended", category: "training_crawler", organization: "Apple", baseScore: 75, respectsRobots: true, uaPatterns: ["applebot-extended"] },
|
|
1257
1272
|
{ id: "youbot", name: "YouBot", category: "training_crawler", organization: "You.com", baseScore: 75, respectsRobots: true, uaPatterns: ["youbot"] },
|
|
1258
|
-
{ id: "mistral", name: "MistralBot", category: "training_crawler", organization: "Mistral AI", baseScore: 80, respectsRobots: true, uaPatterns: ["
|
|
1273
|
+
{ id: "mistral", name: "MistralBot", category: "training_crawler", organization: "Mistral AI", baseScore: 80, respectsRobots: true, uaPatterns: ["mistralbot"] },
|
|
1259
1274
|
{ id: "gemini", name: "Gemini", category: "training_crawler", organization: "Google", baseScore: 80, respectsRobots: true, uaPatterns: ["gemini"] },
|
|
1260
1275
|
{ id: "ai2bot", name: "AI2Bot", category: "training_crawler", organization: "Allen Institute for AI", baseScore: 75, respectsRobots: true, uaPatterns: ["ai2bot"] },
|
|
1261
1276
|
{ id: "deepseek", name: "DeepSeek", category: "training_crawler", organization: "DeepSeek", baseScore: 80, respectsRobots: true, uaPatterns: ["deepseek"] },
|
|
@@ -1272,6 +1287,9 @@ var BOT_REGISTRY = [
|
|
|
1272
1287
|
{ id: "sofyabot", name: "SofyaBot", category: "ai_search_crawler", organization: "Sofya", baseScore: 65, respectsRobots: true, uaPatterns: ["sofyabot"] },
|
|
1273
1288
|
{ id: "xai-searchbot", name: "xAI-SearchBot", category: "ai_search_crawler", organization: "xAI", baseScore: 70, respectsRobots: true, uaPatterns: ["xai-searchbot"] },
|
|
1274
1289
|
{ id: "linkupbot", name: "LinkupBot", category: "ai_search_crawler", organization: "Linkup", baseScore: 65, respectsRobots: true, uaPatterns: ["linkupbot"] },
|
|
1290
|
+
{ id: "perplexitybot", name: "PerplexityBot", category: "ai_search_crawler", organization: "Perplexity AI", baseScore: 80, respectsRobots: true, uaPatterns: ["perplexitybot"] },
|
|
1291
|
+
{ id: "claude-searchbot", name: "Claude-SearchBot", category: "ai_search_crawler", organization: "Anthropic", baseScore: 75, respectsRobots: true, uaPatterns: ["claude-searchbot"] },
|
|
1292
|
+
{ id: "oai-searchbot", name: "OAI-SearchBot", category: "ai_search_crawler", organization: "OpenAI", baseScore: 80, respectsRobots: true, uaPatterns: ["oai-searchbot"] },
|
|
1275
1293
|
{ id: "searchgpt", name: "SearchGPT", category: "ai_search_crawler", organization: "OpenAI", baseScore: 75, respectsRobots: true, uaPatterns: ["searchgpt"] },
|
|
1276
1294
|
{ id: "phind", name: "Phind", category: "ai_search_crawler", organization: "Phind", baseScore: 70, respectsRobots: true, uaPatterns: ["phind"] },
|
|
1277
1295
|
{ id: "kagi", name: "Kagi", category: "ai_search_crawler", organization: "Kagi", baseScore: 65, respectsRobots: true, uaPatterns: ["kagi"] },
|
|
@@ -1290,7 +1308,9 @@ var BOT_REGISTRY = [
|
|
|
1290
1308
|
{ id: "multion", name: "MultiOn", category: "ai_agent", organization: "MultiOn", baseScore: 70, respectsRobots: false, uaPatterns: ["multion"] },
|
|
1291
1309
|
{ id: "iboubot", name: "IbouBot", category: "search_crawler", organization: "Ibou", baseScore: 30, respectsRobots: true, uaPatterns: ["iboubot"] },
|
|
1292
1310
|
{ id: "googlebot", name: "Googlebot", category: "search_crawler", organization: "Google", baseScore: 30, respectsRobots: true, uaPatterns: ["googlebot"] },
|
|
1311
|
+
{ id: "google-inspectiontool", name: "Google-InspectionTool", category: "search_crawler", organization: "Google", baseScore: 30, respectsRobots: true, uaPatterns: ["google-inspectiontool"] },
|
|
1293
1312
|
{ id: "bingbot", name: "Bingbot", category: "search_crawler", organization: "Microsoft", baseScore: 30, respectsRobots: true, uaPatterns: ["bingbot"] },
|
|
1313
|
+
{ id: "msnbot", name: "MSNBot", category: "search_crawler", organization: "Microsoft", baseScore: 30, respectsRobots: true, uaPatterns: ["msnbot"] },
|
|
1294
1314
|
{ id: "yandexbot", name: "YandexBot", category: "search_crawler", organization: "Yandex", baseScore: 35, respectsRobots: true, uaPatterns: ["yandexbot"] },
|
|
1295
1315
|
{ id: "baiduspider", name: "Baiduspider", category: "search_crawler", organization: "Baidu", baseScore: 40, respectsRobots: true, uaPatterns: ["baiduspider"] },
|
|
1296
1316
|
{ id: "duckduckbot", name: "DuckDuckBot", category: "search_crawler", organization: "DuckDuckGo", baseScore: 30, respectsRobots: true, uaPatterns: ["duckduckbot"] },
|
|
@@ -1365,6 +1385,7 @@ var BOT_REGISTRY = [
|
|
|
1365
1385
|
{ id: "heritrix", name: "Heritrix", category: "archiver", organization: "Internet Archive", baseScore: 30, respectsRobots: true, uaPatterns: ["heritrix"] },
|
|
1366
1386
|
{ id: "brozzler", name: "Brozzler", category: "archiver", organization: "Internet Archive", baseScore: 30, respectsRobots: true, uaPatterns: ["brozzler"] },
|
|
1367
1387
|
{ id: "facebookexternalhit", name: "Facebook", category: "fetcher", organization: "Meta", baseScore: 25, respectsRobots: true, uaPatterns: ["facebookexternalhit"] },
|
|
1388
|
+
{ id: "facebot", name: "Facebot", category: "fetcher", organization: "Meta", baseScore: 25, respectsRobots: true, uaPatterns: ["facebot"] },
|
|
1368
1389
|
{ id: "twitterbot", name: "Twitterbot", category: "fetcher", organization: "X Corp", baseScore: 25, respectsRobots: true, uaPatterns: ["twitterbot"] },
|
|
1369
1390
|
{ id: "linkedinbot", name: "LinkedInBot", category: "fetcher", organization: "LinkedIn", baseScore: 25, respectsRobots: true, uaPatterns: ["linkedinbot"] },
|
|
1370
1391
|
{ id: "slackbot", name: "Slackbot", category: "fetcher", organization: "Slack", baseScore: 25, respectsRobots: true, uaPatterns: ["slackbot"] },
|
|
@@ -1392,7 +1413,10 @@ var BOT_REGISTRY = [
|
|
|
1392
1413
|
{ id: "freshping", name: "Freshping", category: "monitoring", organization: "Freshworks", baseScore: 20, respectsRobots: true, uaPatterns: ["freshping"] },
|
|
1393
1414
|
{ id: "hetrixtools", name: "HetrixTools", category: "monitoring", organization: "HetrixTools", baseScore: 20, respectsRobots: true, uaPatterns: ["hetrixtools"] },
|
|
1394
1415
|
{ id: "nodeping", name: "NodePing", category: "monitoring", organization: "NodePing", baseScore: 20, respectsRobots: true, uaPatterns: ["nodeping"] },
|
|
1416
|
+
{ id: "gtmetrix", name: "GTmetrix", category: "monitoring", organization: "GTmetrix", baseScore: 20, respectsRobots: true, uaPatterns: ["gtmetrix"] },
|
|
1417
|
+
{ id: "chrome-lighthouse", name: "Lighthouse", category: "monitoring", organization: "Google", baseScore: 20, respectsRobots: true, uaPatterns: ["chrome-lighthouse", "google page speed"] },
|
|
1395
1418
|
{ id: "feedly", name: "Feedly", category: "feed_reader", organization: "Feedly", baseScore: 25, respectsRobots: true, uaPatterns: ["feedly"] },
|
|
1419
|
+
{ id: "feedfetcher-google", name: "Feedfetcher-Google", category: "feed_reader", organization: "Google", baseScore: 25, respectsRobots: true, uaPatterns: ["feedfetcher"] },
|
|
1396
1420
|
{ id: "newsblur", name: "NewsBlur", category: "feed_reader", organization: "NewsBlur", baseScore: 25, respectsRobots: true, uaPatterns: ["newsblur"] },
|
|
1397
1421
|
{ id: "inoreader", name: "Inoreader", category: "feed_reader", organization: "Inoreader", baseScore: 25, respectsRobots: true, uaPatterns: ["inoreader"] },
|
|
1398
1422
|
{ id: "theoldreader", name: "The Old Reader", category: "feed_reader", organization: "The Old Reader", baseScore: 25, respectsRobots: true, uaPatterns: ["theoldreader"] },
|
|
@@ -1410,6 +1434,10 @@ var BOT_REGISTRY = [
|
|
|
1410
1434
|
{ id: "apify", name: "Apify", category: "commercial_scraper", organization: "Apify", baseScore: 65, respectsRobots: true, uaPatterns: ["apify"] },
|
|
1411
1435
|
{ id: "crawlbase", name: "Crawlbase", category: "commercial_scraper", organization: "Crawlbase", baseScore: 65, respectsRobots: true, uaPatterns: ["crawlbase"] },
|
|
1412
1436
|
{ id: "webscrapingapi", name: "WebScrapingAPI", category: "commercial_scraper", organization: "WebScrapingAPI", baseScore: 65, respectsRobots: true, uaPatterns: ["webscrapingapi"] },
|
|
1437
|
+
{ id: "chatgpt-user", name: "ChatGPT-User", category: "ai_assistant", organization: "OpenAI", baseScore: 85, respectsRobots: true, uaPatterns: ["chatgpt-user"] },
|
|
1438
|
+
{ id: "perplexity-user", name: "Perplexity-User", category: "ai_assistant", organization: "Perplexity AI", baseScore: 75, respectsRobots: false, uaPatterns: ["perplexity-user"] },
|
|
1439
|
+
{ id: "mistralai-user", name: "MistralAI-User", category: "ai_assistant", organization: "Mistral AI", baseScore: 75, respectsRobots: true, uaPatterns: ["mistralai-user"] },
|
|
1440
|
+
{ id: "meta-externalfetcher", name: "Meta-ExternalFetcher", category: "ai_assistant", organization: "Meta", baseScore: 70, respectsRobots: false, uaPatterns: ["meta-externalfetcher"] },
|
|
1413
1441
|
{ id: "gemini-deep-research", name: "Gemini-Deep-Research", category: "ai_assistant", organization: "Google", baseScore: 65, respectsRobots: true, uaPatterns: ["gemini-deep-research"] },
|
|
1414
1442
|
{ id: "copilot", name: "Microsoft Copilot", category: "ai_assistant", organization: "Microsoft", baseScore: 65, respectsRobots: true, uaPatterns: ["copilot"] },
|
|
1415
1443
|
{ id: "cortana", name: "Cortana", category: "ai_assistant", organization: "Microsoft", baseScore: 60, respectsRobots: true, uaPatterns: ["cortana"] },
|
|
@@ -2046,6 +2074,143 @@ var ViolationReporter = class {
|
|
|
2046
2074
|
}
|
|
2047
2075
|
};
|
|
2048
2076
|
|
|
2077
|
+
// src/referrals/llm-platforms.generated.ts
|
|
2078
|
+
var LLM_PLATFORMS = {
|
|
2079
|
+
"chat.deepseek.com": "DeepSeek",
|
|
2080
|
+
"chat.openai.com": "ChatGPT",
|
|
2081
|
+
"chatgpt.com": "ChatGPT",
|
|
2082
|
+
"claude.ai": "Claude",
|
|
2083
|
+
"copilot.microsoft.com": "Copilot",
|
|
2084
|
+
"deepseek.com": "DeepSeek",
|
|
2085
|
+
"gemini.google.com": "Gemini",
|
|
2086
|
+
"grok.com": "Grok",
|
|
2087
|
+
"kagi.com": "Kagi",
|
|
2088
|
+
"meta.ai": "Meta AI",
|
|
2089
|
+
"perplexity.ai": "Perplexity",
|
|
2090
|
+
"phind.com": "Phind",
|
|
2091
|
+
"www.deepseek.com": "DeepSeek",
|
|
2092
|
+
"www.grok.com": "Grok",
|
|
2093
|
+
"www.kagi.com": "Kagi",
|
|
2094
|
+
"www.meta.ai": "Meta AI",
|
|
2095
|
+
"www.perplexity.ai": "Perplexity",
|
|
2096
|
+
"www.phind.com": "Phind",
|
|
2097
|
+
"www.you.com": "You.com",
|
|
2098
|
+
"you.com": "You.com"
|
|
2099
|
+
};
|
|
2100
|
+
|
|
2101
|
+
// src/referrals/llm-referral.ts
|
|
2102
|
+
var TAG_KEYS = ["utm_source", "ref", "utm_medium"];
|
|
2103
|
+
function classifyReferral(referer, pageUrl) {
|
|
2104
|
+
const ref = (referer ?? "").trim();
|
|
2105
|
+
if (ref) {
|
|
2106
|
+
try {
|
|
2107
|
+
return LLM_PLATFORMS[new URL(ref).hostname.toLowerCase()] ?? "";
|
|
2108
|
+
} catch {
|
|
2109
|
+
return "";
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
let url;
|
|
2113
|
+
try {
|
|
2114
|
+
url = new URL(pageUrl);
|
|
2115
|
+
} catch {
|
|
2116
|
+
return "";
|
|
2117
|
+
}
|
|
2118
|
+
for (const key of TAG_KEYS) {
|
|
2119
|
+
for (const value of url.searchParams.getAll(key)) {
|
|
2120
|
+
const platform = platformForTag(value);
|
|
2121
|
+
if (platform) return platform;
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
return "";
|
|
2125
|
+
}
|
|
2126
|
+
var squash = (s) => s.replace(/[ \-_.]/g, "");
|
|
2127
|
+
function platformForTag(raw) {
|
|
2128
|
+
let value = raw.trim().toLowerCase();
|
|
2129
|
+
if (!value) return "";
|
|
2130
|
+
try {
|
|
2131
|
+
const host = new URL(value).hostname;
|
|
2132
|
+
if (host) value = host.toLowerCase();
|
|
2133
|
+
} catch {
|
|
2134
|
+
}
|
|
2135
|
+
value = value.replace(/\.$/, "");
|
|
2136
|
+
if (LLM_PLATFORMS[value]) return LLM_PLATFORMS[value];
|
|
2137
|
+
const normalized = squash(value);
|
|
2138
|
+
for (const [domain, name] of Object.entries(LLM_PLATFORMS)) {
|
|
2139
|
+
if (normalized === squash(name.toLowerCase()) || normalized === domain.replace(/^www\./, "").replace(/\./g, "")) {
|
|
2140
|
+
return name;
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
return "";
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
// src/referrals/referral-counter.ts
|
|
2147
|
+
var MAX_PATH = 500;
|
|
2148
|
+
var MAX_ENTRIES = 500;
|
|
2149
|
+
var header = (headers, name) => {
|
|
2150
|
+
const v = headers[name] ?? headers[name.toLowerCase()];
|
|
2151
|
+
if (v !== void 0) return v;
|
|
2152
|
+
for (const [k, value] of Object.entries(headers)) if (k.toLowerCase() === name) return value;
|
|
2153
|
+
return "";
|
|
2154
|
+
};
|
|
2155
|
+
var AIReferralCounter = class {
|
|
2156
|
+
constructor(sender, config = {}) {
|
|
2157
|
+
this.sender = sender;
|
|
2158
|
+
this.counts = /* @__PURE__ */ new Map();
|
|
2159
|
+
/** A batch that failed to send, retried under the same id so it counts once. */
|
|
2160
|
+
this.pending = null;
|
|
2161
|
+
this.flushing = false;
|
|
2162
|
+
this.timer = setInterval(() => void this.flush(), config.flushInterval ?? 6e4);
|
|
2163
|
+
this.timer.unref?.();
|
|
2164
|
+
}
|
|
2165
|
+
/** Count the request if it is a page visit an AI product sent. Never throws. */
|
|
2166
|
+
observe(metadata) {
|
|
2167
|
+
try {
|
|
2168
|
+
if ((metadata.method ?? "").toUpperCase() !== "GET") return;
|
|
2169
|
+
const headers = metadata.headers ?? {};
|
|
2170
|
+
if (header(headers, "sec-fetch-mode") !== "navigate") return;
|
|
2171
|
+
const dest = header(headers, "sec-fetch-dest");
|
|
2172
|
+
if (dest && dest !== "document") return;
|
|
2173
|
+
const path = (metadata.path || "/").split("?")[0] || "/";
|
|
2174
|
+
const query = metadata.query ? `?${metadata.query}` : "";
|
|
2175
|
+
const platform = classifyReferral(header(headers, "referer"), `https://site.invalid${path}${query}`);
|
|
2176
|
+
if (!platform) return;
|
|
2177
|
+
const landing = path.length > MAX_PATH ? path.slice(0, MAX_PATH) : path;
|
|
2178
|
+
const key = `${platform}
|
|
2179
|
+
${landing}`;
|
|
2180
|
+
const entry = this.counts.get(key);
|
|
2181
|
+
if (entry) {
|
|
2182
|
+
entry.count++;
|
|
2183
|
+
} else {
|
|
2184
|
+
this.counts.set(key, { platform, path: landing, count: 1 });
|
|
2185
|
+
if (this.counts.size >= MAX_ENTRIES) void this.flush();
|
|
2186
|
+
}
|
|
2187
|
+
} catch {
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
/** Send what has been counted. Never rejects. */
|
|
2191
|
+
async flush() {
|
|
2192
|
+
if (this.flushing) return;
|
|
2193
|
+
this.flushing = true;
|
|
2194
|
+
try {
|
|
2195
|
+
if (!this.pending && this.counts.size > 0) {
|
|
2196
|
+
this.pending = { report_id: crypto.randomUUID(), source: "sdk", referrals: [...this.counts.values()] };
|
|
2197
|
+
this.counts = /* @__PURE__ */ new Map();
|
|
2198
|
+
}
|
|
2199
|
+
if (this.pending && await this.sender.sendAIReferrals(this.pending)) {
|
|
2200
|
+
this.pending = null;
|
|
2201
|
+
}
|
|
2202
|
+
} catch {
|
|
2203
|
+
} finally {
|
|
2204
|
+
this.flushing = false;
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
/** Stop the timer and send what is left. */
|
|
2208
|
+
async destroy() {
|
|
2209
|
+
clearInterval(this.timer);
|
|
2210
|
+
await this.flush();
|
|
2211
|
+
}
|
|
2212
|
+
};
|
|
2213
|
+
|
|
2049
2214
|
// src/ip-enrichment.ts
|
|
2050
2215
|
var IPEnrichmentClient = class {
|
|
2051
2216
|
constructor(client, ttlMs = 36e5) {
|
|
@@ -2554,16 +2719,16 @@ function componentValue(req, c) {
|
|
|
2554
2719
|
case "@query":
|
|
2555
2720
|
return req.url.search === "" ? "?" : req.url.search;
|
|
2556
2721
|
case "signature-agent": {
|
|
2557
|
-
const
|
|
2558
|
-
if (
|
|
2559
|
-
if (c.keyParam !== void 0) return dictMemberValue(
|
|
2560
|
-
return
|
|
2722
|
+
const header2 = req.headers.get("signature-agent");
|
|
2723
|
+
if (header2 === null) throw new Error("signature-agent covered but absent");
|
|
2724
|
+
if (c.keyParam !== void 0) return dictMemberValue(header2, c.keyParam);
|
|
2725
|
+
return header2.trim().replace(/\s+/g, " ");
|
|
2561
2726
|
}
|
|
2562
2727
|
default: {
|
|
2563
2728
|
if (name.startsWith("@")) throw new Error(`unsupported derived component ${name}`);
|
|
2564
|
-
const
|
|
2565
|
-
if (
|
|
2566
|
-
return
|
|
2729
|
+
const header2 = req.headers.get(name);
|
|
2730
|
+
if (header2 === null) throw new Error(`covered header ${name} absent`);
|
|
2731
|
+
return header2.trim().replace(/\s+/g, " ");
|
|
2567
2732
|
}
|
|
2568
2733
|
}
|
|
2569
2734
|
}
|
|
@@ -2576,8 +2741,8 @@ function canonicalAuthority(url) {
|
|
|
2576
2741
|
}
|
|
2577
2742
|
return `${host}:${port}`;
|
|
2578
2743
|
}
|
|
2579
|
-
function dictMemberValue(
|
|
2580
|
-
const dict = parseDictionary(
|
|
2744
|
+
function dictMemberValue(header2, key) {
|
|
2745
|
+
const dict = parseDictionary(header2);
|
|
2581
2746
|
const found = dict.find((d) => d.key === key);
|
|
2582
2747
|
if (!found) throw new Error(`signature-agent has no member ${key}`);
|
|
2583
2748
|
return found.raw;
|
|
@@ -2959,6 +3124,7 @@ function isTestTriggerUserAgent(userAgent) {
|
|
|
2959
3124
|
// src/sdk.ts
|
|
2960
3125
|
var WebDecoy = class {
|
|
2961
3126
|
constructor(config) {
|
|
3127
|
+
this.referralCounter = null;
|
|
2962
3128
|
this.violationReporter = null;
|
|
2963
3129
|
this.ipEnrichmentClient = null;
|
|
2964
3130
|
this._hasFilterRules = false;
|
|
@@ -2980,7 +3146,8 @@ var WebDecoy = class {
|
|
|
2980
3146
|
threatScoreThreshold: config.threatScoreThreshold ?? 80,
|
|
2981
3147
|
timeout: config.timeout ?? 5e3,
|
|
2982
3148
|
debug: config.debug ?? false,
|
|
2983
|
-
tlsRejectUnauthorized: config.tlsRejectUnauthorized ?? true
|
|
3149
|
+
tlsRejectUnauthorized: config.tlsRejectUnauthorized ?? true,
|
|
3150
|
+
countAIReferrals: config.countAIReferrals ?? true
|
|
2984
3151
|
};
|
|
2985
3152
|
this.log = resolveLogger(config.logger, this.config.debug);
|
|
2986
3153
|
this.tracer = config.tracer;
|
|
@@ -3014,6 +3181,9 @@ var WebDecoy = class {
|
|
|
3014
3181
|
if (this.client && this._hasFilterRules) {
|
|
3015
3182
|
this.ipEnrichmentClient = new IPEnrichmentClient(this.client);
|
|
3016
3183
|
}
|
|
3184
|
+
if (this.client && this.config.countAIReferrals !== false) {
|
|
3185
|
+
this.referralCounter = new AIReferralCounter(this.client);
|
|
3186
|
+
}
|
|
3017
3187
|
if (this.client && this.ruleEngine) {
|
|
3018
3188
|
const reporter = new ViolationReporter(this.client, {
|
|
3019
3189
|
debug: this.config.debug
|
|
@@ -3185,6 +3355,7 @@ var WebDecoy = class {
|
|
|
3185
3355
|
*/
|
|
3186
3356
|
async protect(metadata, options = {}) {
|
|
3187
3357
|
const edge = readEdgeVerdict(metadata.headers);
|
|
3358
|
+
this.referralCounter?.observe(metadata);
|
|
3188
3359
|
const span = startSpan(this.tracer, "webdecoy.protect");
|
|
3189
3360
|
try {
|
|
3190
3361
|
const decision = (await this.decide(metadata, options)).withEdge(edge);
|
|
@@ -3446,6 +3617,7 @@ var WebDecoy = class {
|
|
|
3446
3617
|
if (this.violationReporter) {
|
|
3447
3618
|
await this.violationReporter.destroy();
|
|
3448
3619
|
}
|
|
3620
|
+
await this.referralCounter?.destroy();
|
|
3449
3621
|
}
|
|
3450
3622
|
};
|
|
3451
3623
|
function agentInputFromMetadata(metadata) {
|
|
@@ -3655,8 +3827,8 @@ function readClientSession(headers) {
|
|
|
3655
3827
|
}
|
|
3656
3828
|
}
|
|
3657
3829
|
}
|
|
3658
|
-
const
|
|
3659
|
-
return
|
|
3830
|
+
const header2 = headers[CLIENT_SESSION_HEADER];
|
|
3831
|
+
return header2 || void 0;
|
|
3660
3832
|
}
|
|
3661
3833
|
var ClientSignalRule = class {
|
|
3662
3834
|
constructor(config) {
|
|
@@ -4706,8 +4878,8 @@ function analyzeHeaders(headers) {
|
|
|
4706
4878
|
headersLower[key.toLowerCase()] = value;
|
|
4707
4879
|
}
|
|
4708
4880
|
let missingCount = 0;
|
|
4709
|
-
for (const
|
|
4710
|
-
if (!(
|
|
4881
|
+
for (const header2 of EXPECTED_BROWSER_HEADERS) {
|
|
4882
|
+
if (!(header2 in headersLower)) missingCount++;
|
|
4711
4883
|
}
|
|
4712
4884
|
if (missingCount > 1) {
|
|
4713
4885
|
detections.push({
|
|
@@ -4717,13 +4889,13 @@ function analyzeHeaders(headers) {
|
|
|
4717
4889
|
reason: `Missing ${missingCount} expected browser headers`
|
|
4718
4890
|
});
|
|
4719
4891
|
}
|
|
4720
|
-
for (const
|
|
4721
|
-
if (SUSPICIOUS_HEADERS.has(
|
|
4892
|
+
for (const header2 of Object.keys(headersLower)) {
|
|
4893
|
+
if (SUSPICIOUS_HEADERS.has(header2)) {
|
|
4722
4894
|
detections.push({
|
|
4723
4895
|
category: "bot",
|
|
4724
4896
|
score: 0.3,
|
|
4725
4897
|
confidence: 0.4,
|
|
4726
|
-
reason: `Suspicious header present: ${
|
|
4898
|
+
reason: `Suspicious header present: ${header2}`
|
|
4727
4899
|
});
|
|
4728
4900
|
}
|
|
4729
4901
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -310,7 +310,7 @@ declare function readEdgeVerdict(headers: Record<string, string> | undefined): E
|
|
|
310
310
|
* agents share User-Agent substrings, so sorting this array changes how real
|
|
311
311
|
* traffic is classified.
|
|
312
312
|
*
|
|
313
|
-
*
|
|
313
|
+
* 186 agents across 15 categories.
|
|
314
314
|
*/
|
|
315
315
|
/**
|
|
316
316
|
* Classification categories, mirroring `agents.Category` in Go.
|
|
@@ -633,6 +633,15 @@ interface WebDecoyConfig {
|
|
|
633
633
|
* @default false
|
|
634
634
|
*/
|
|
635
635
|
debug?: boolean;
|
|
636
|
+
/**
|
|
637
|
+
* Count visits AI products send to this application (ChatGPT, Claude,
|
|
638
|
+
* Perplexity and others), for the AI Traffic page. Aggregate counts only:
|
|
639
|
+
* the AI platform, the landing path and a number, sent about once a
|
|
640
|
+
* minute. Nothing about a visitor is kept or sent. Needs an API key scoped
|
|
641
|
+
* to one site.
|
|
642
|
+
* @default true when an apiKey is set
|
|
643
|
+
*/
|
|
644
|
+
countAIReferrals?: boolean;
|
|
636
645
|
/**
|
|
637
646
|
* Whether to reject unauthorized TLS certificates
|
|
638
647
|
* Set to false for development/testing with self-signed certificates
|
|
@@ -1222,6 +1231,28 @@ interface RuleEngineResult {
|
|
|
1222
1231
|
results: RuleOutcome[];
|
|
1223
1232
|
}
|
|
1224
1233
|
|
|
1234
|
+
/**
|
|
1235
|
+
* Counts visits AI products send to this application, and reports the totals.
|
|
1236
|
+
*
|
|
1237
|
+
* Aggregate counts only: an AI platform, a landing path and a number, sent
|
|
1238
|
+
* about once a minute. Nothing about a visitor (no IP, user agent, cookie,
|
|
1239
|
+
* query string or full referrer) is kept or sent. Only a browser loading a
|
|
1240
|
+
* page counts: a GET whose fetch metadata says it is a document navigation.
|
|
1241
|
+
* Subresources, API calls and clients that send no fetch metadata are not
|
|
1242
|
+
* visits and are never counted.
|
|
1243
|
+
*/
|
|
1244
|
+
|
|
1245
|
+
interface AIReferralEntry {
|
|
1246
|
+
platform: string;
|
|
1247
|
+
path: string;
|
|
1248
|
+
count: number;
|
|
1249
|
+
}
|
|
1250
|
+
interface AIReferralBatch {
|
|
1251
|
+
report_id: string;
|
|
1252
|
+
source: 'sdk';
|
|
1253
|
+
referrals: AIReferralEntry[];
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1225
1256
|
/**
|
|
1226
1257
|
* Web Decoy API Client
|
|
1227
1258
|
* Handles communication with the ingest service.
|
|
@@ -1257,6 +1288,13 @@ declare class WebDecoyClient {
|
|
|
1257
1288
|
* Send violation events to the ingest service
|
|
1258
1289
|
*/
|
|
1259
1290
|
sendViolations(events: ViolationEvent[]): Promise<void>;
|
|
1291
|
+
/**
|
|
1292
|
+
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
1293
|
+
* accepted, or refused for a reason a retry cannot fix (a 4xx). Only a
|
|
1294
|
+
* server error or a network failure resolves false, so the caller retries
|
|
1295
|
+
* the same batch id.
|
|
1296
|
+
*/
|
|
1297
|
+
sendAIReferrals(batch: AIReferralBatch): Promise<boolean>;
|
|
1260
1298
|
/**
|
|
1261
1299
|
* Get IP enrichment data from the ingest service
|
|
1262
1300
|
*/
|
|
@@ -1271,6 +1309,7 @@ declare class WebDecoy {
|
|
|
1271
1309
|
private client;
|
|
1272
1310
|
private config;
|
|
1273
1311
|
private ruleEngine;
|
|
1312
|
+
private referralCounter;
|
|
1274
1313
|
private violationReporter;
|
|
1275
1314
|
private ipEnrichmentClient;
|
|
1276
1315
|
private _hasFilterRules;
|
|
@@ -310,7 +310,7 @@ declare function readEdgeVerdict(headers: Record<string, string> | undefined): E
|
|
|
310
310
|
* agents share User-Agent substrings, so sorting this array changes how real
|
|
311
311
|
* traffic is classified.
|
|
312
312
|
*
|
|
313
|
-
*
|
|
313
|
+
* 186 agents across 15 categories.
|
|
314
314
|
*/
|
|
315
315
|
/**
|
|
316
316
|
* Classification categories, mirroring `agents.Category` in Go.
|
|
@@ -633,6 +633,15 @@ interface WebDecoyConfig {
|
|
|
633
633
|
* @default false
|
|
634
634
|
*/
|
|
635
635
|
debug?: boolean;
|
|
636
|
+
/**
|
|
637
|
+
* Count visits AI products send to this application (ChatGPT, Claude,
|
|
638
|
+
* Perplexity and others), for the AI Traffic page. Aggregate counts only:
|
|
639
|
+
* the AI platform, the landing path and a number, sent about once a
|
|
640
|
+
* minute. Nothing about a visitor is kept or sent. Needs an API key scoped
|
|
641
|
+
* to one site.
|
|
642
|
+
* @default true when an apiKey is set
|
|
643
|
+
*/
|
|
644
|
+
countAIReferrals?: boolean;
|
|
636
645
|
/**
|
|
637
646
|
* Whether to reject unauthorized TLS certificates
|
|
638
647
|
* Set to false for development/testing with self-signed certificates
|
|
@@ -1222,6 +1231,28 @@ interface RuleEngineResult {
|
|
|
1222
1231
|
results: RuleOutcome[];
|
|
1223
1232
|
}
|
|
1224
1233
|
|
|
1234
|
+
/**
|
|
1235
|
+
* Counts visits AI products send to this application, and reports the totals.
|
|
1236
|
+
*
|
|
1237
|
+
* Aggregate counts only: an AI platform, a landing path and a number, sent
|
|
1238
|
+
* about once a minute. Nothing about a visitor (no IP, user agent, cookie,
|
|
1239
|
+
* query string or full referrer) is kept or sent. Only a browser loading a
|
|
1240
|
+
* page counts: a GET whose fetch metadata says it is a document navigation.
|
|
1241
|
+
* Subresources, API calls and clients that send no fetch metadata are not
|
|
1242
|
+
* visits and are never counted.
|
|
1243
|
+
*/
|
|
1244
|
+
|
|
1245
|
+
interface AIReferralEntry {
|
|
1246
|
+
platform: string;
|
|
1247
|
+
path: string;
|
|
1248
|
+
count: number;
|
|
1249
|
+
}
|
|
1250
|
+
interface AIReferralBatch {
|
|
1251
|
+
report_id: string;
|
|
1252
|
+
source: 'sdk';
|
|
1253
|
+
referrals: AIReferralEntry[];
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1225
1256
|
/**
|
|
1226
1257
|
* Web Decoy API Client
|
|
1227
1258
|
* Handles communication with the ingest service.
|
|
@@ -1257,6 +1288,13 @@ declare class WebDecoyClient {
|
|
|
1257
1288
|
* Send violation events to the ingest service
|
|
1258
1289
|
*/
|
|
1259
1290
|
sendViolations(events: ViolationEvent[]): Promise<void>;
|
|
1291
|
+
/**
|
|
1292
|
+
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
1293
|
+
* accepted, or refused for a reason a retry cannot fix (a 4xx). Only a
|
|
1294
|
+
* server error or a network failure resolves false, so the caller retries
|
|
1295
|
+
* the same batch id.
|
|
1296
|
+
*/
|
|
1297
|
+
sendAIReferrals(batch: AIReferralBatch): Promise<boolean>;
|
|
1260
1298
|
/**
|
|
1261
1299
|
* Get IP enrichment data from the ingest service
|
|
1262
1300
|
*/
|
|
@@ -1271,6 +1309,7 @@ declare class WebDecoy {
|
|
|
1271
1309
|
private client;
|
|
1272
1310
|
private config;
|
|
1273
1311
|
private ruleEngine;
|
|
1312
|
+
private referralCounter;
|
|
1274
1313
|
private violationReporter;
|
|
1275
1314
|
private ipEnrichmentClient;
|
|
1276
1315
|
private _hasFilterRules;
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { j as WebDecoyConfig, J as RequestMetadata, W as WebDecoy, P as ProtectResult, N as RuleState } from './sdk-
|
|
1
|
+
import { j as WebDecoyConfig, J as RequestMetadata, W as WebDecoy, P as ProtectResult, N as RuleState } from './sdk-BTqYTW4I.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 { j as WebDecoyConfig, J as RequestMetadata, W as WebDecoy, P as ProtectResult, N as RuleState } from './sdk-
|
|
1
|
+
import { j as WebDecoyConfig, J as RequestMetadata, W as WebDecoy, P as ProtectResult, N as RuleState } from './sdk-BTqYTW4I.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Testing utilities, for the application's test suite rather than ours.
|
package/dist/testing.js
CHANGED
|
@@ -134,6 +134,23 @@ var WebDecoyClient = class {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Send AI referral counts. Resolves true when the batch needs no retry:
|
|
139
|
+
* accepted, or refused for a reason a retry cannot fix (a 4xx). Only a
|
|
140
|
+
* server error or a network failure resolves false, so the caller retries
|
|
141
|
+
* the same batch id.
|
|
142
|
+
*/
|
|
143
|
+
async sendAIReferrals(batch) {
|
|
144
|
+
try {
|
|
145
|
+
const response = await this.request("POST", "/api/v1/sdk/ai-referrals", batch);
|
|
146
|
+
return response.status < 500;
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (this.config.debug) {
|
|
149
|
+
console.error("[WebDecoy] Failed to send AI referrals:", error);
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
137
154
|
/**
|
|
138
155
|
* Get IP enrichment data from the ingest service
|
|
139
156
|
*/
|
|
@@ -248,7 +265,7 @@ function hasSuspiciousHeaders(metadata) {
|
|
|
248
265
|
const headers = metadata.headers || {};
|
|
249
266
|
const hasBotUA = SUSPICIOUS_PATTERNS.userAgents.some((pattern) => pattern.test(userAgent));
|
|
250
267
|
const missingCommonHeaders = SUSPICIOUS_PATTERNS.missingHeaders.filter(
|
|
251
|
-
(
|
|
268
|
+
(header2) => !headers[header2] && !headers[header2.toLowerCase()]
|
|
252
269
|
);
|
|
253
270
|
return hasBotUA || missingCommonHeaders.length > 0;
|
|
254
271
|
}
|
|
@@ -449,10 +466,9 @@ var TripwireRule = class {
|
|
|
449
466
|
var BOT_REGISTRY = [
|
|
450
467
|
{ id: "reflectionbot", name: "Reflectionbot", category: "training_crawler", organization: "Reflection AI", baseScore: 70, respectsRobots: true, uaPatterns: ["reflectionbot"] },
|
|
451
468
|
{ id: "gptbot", name: "GPTBot", category: "training_crawler", organization: "OpenAI", baseScore: 85, respectsRobots: true, uaPatterns: ["gptbot"] },
|
|
452
|
-
{ id: "chatgpt-user", name: "ChatGPT-User", category: "training_crawler", organization: "OpenAI", baseScore: 85, respectsRobots: true, uaPatterns: ["chatgpt-user", "chatgpt"] },
|
|
453
|
-
{ id: "oai-searchbot", name: "OAI-SearchBot", category: "training_crawler", organization: "OpenAI", baseScore: 80, respectsRobots: true, uaPatterns: ["oai-searchbot"] },
|
|
454
469
|
{ id: "claudebot", name: "ClaudeBot", category: "training_crawler", organization: "Anthropic", baseScore: 85, respectsRobots: true, uaPatterns: ["claudebot"] },
|
|
455
|
-
{ id: "anthropic", name: "Anthropic", category: "training_crawler", organization: "Anthropic", baseScore: 85, respectsRobots: true, uaPatterns: ["anthropic"] },
|
|
470
|
+
{ id: "anthropic", name: "Anthropic", category: "training_crawler", organization: "Anthropic", baseScore: 85, respectsRobots: true, uaPatterns: ["anthropic-ai"] },
|
|
471
|
+
{ id: "claude-web", name: "Claude-Web", category: "training_crawler", organization: "Anthropic", baseScore: 85, respectsRobots: true, uaPatterns: ["claude-web"] },
|
|
456
472
|
{ id: "ccbot", name: "CCBot", category: "training_crawler", organization: "Common Crawl", baseScore: 80, respectsRobots: true, uaPatterns: ["ccbot"] },
|
|
457
473
|
{ id: "google-extended", name: "Google-Extended", category: "training_crawler", organization: "Google", baseScore: 80, respectsRobots: true, uaPatterns: ["google-extended"] },
|
|
458
474
|
{ id: "bytespider", name: "ByteSpider", category: "training_crawler", organization: "ByteDance", baseScore: 75, respectsRobots: false, uaPatterns: ["bytespider"] },
|
|
@@ -460,10 +476,9 @@ var BOT_REGISTRY = [
|
|
|
460
476
|
{ id: "facebookbot", name: "FacebookBot", category: "training_crawler", organization: "Meta", baseScore: 70, respectsRobots: true, uaPatterns: ["facebookbot"] },
|
|
461
477
|
{ id: "meta-externalagent", name: "Meta-ExternalAgent", category: "training_crawler", organization: "Meta", baseScore: 75, respectsRobots: true, uaPatterns: ["meta-externalagent"] },
|
|
462
478
|
{ id: "cohere-ai", name: "Cohere", category: "training_crawler", organization: "Cohere", baseScore: 80, respectsRobots: true, uaPatterns: ["cohere-ai", "cohere"] },
|
|
463
|
-
{ id: "perplexitybot", name: "PerplexityBot", category: "training_crawler", organization: "Perplexity AI", baseScore: 80, respectsRobots: true, uaPatterns: ["perplexitybot"] },
|
|
464
479
|
{ id: "applebot-extended", name: "Applebot-Extended", category: "training_crawler", organization: "Apple", baseScore: 75, respectsRobots: true, uaPatterns: ["applebot-extended"] },
|
|
465
480
|
{ id: "youbot", name: "YouBot", category: "training_crawler", organization: "You.com", baseScore: 75, respectsRobots: true, uaPatterns: ["youbot"] },
|
|
466
|
-
{ id: "mistral", name: "MistralBot", category: "training_crawler", organization: "Mistral AI", baseScore: 80, respectsRobots: true, uaPatterns: ["
|
|
481
|
+
{ id: "mistral", name: "MistralBot", category: "training_crawler", organization: "Mistral AI", baseScore: 80, respectsRobots: true, uaPatterns: ["mistralbot"] },
|
|
467
482
|
{ id: "gemini", name: "Gemini", category: "training_crawler", organization: "Google", baseScore: 80, respectsRobots: true, uaPatterns: ["gemini"] },
|
|
468
483
|
{ id: "ai2bot", name: "AI2Bot", category: "training_crawler", organization: "Allen Institute for AI", baseScore: 75, respectsRobots: true, uaPatterns: ["ai2bot"] },
|
|
469
484
|
{ id: "deepseek", name: "DeepSeek", category: "training_crawler", organization: "DeepSeek", baseScore: 80, respectsRobots: true, uaPatterns: ["deepseek"] },
|
|
@@ -480,6 +495,9 @@ var BOT_REGISTRY = [
|
|
|
480
495
|
{ id: "sofyabot", name: "SofyaBot", category: "ai_search_crawler", organization: "Sofya", baseScore: 65, respectsRobots: true, uaPatterns: ["sofyabot"] },
|
|
481
496
|
{ id: "xai-searchbot", name: "xAI-SearchBot", category: "ai_search_crawler", organization: "xAI", baseScore: 70, respectsRobots: true, uaPatterns: ["xai-searchbot"] },
|
|
482
497
|
{ id: "linkupbot", name: "LinkupBot", category: "ai_search_crawler", organization: "Linkup", baseScore: 65, respectsRobots: true, uaPatterns: ["linkupbot"] },
|
|
498
|
+
{ id: "perplexitybot", name: "PerplexityBot", category: "ai_search_crawler", organization: "Perplexity AI", baseScore: 80, respectsRobots: true, uaPatterns: ["perplexitybot"] },
|
|
499
|
+
{ id: "claude-searchbot", name: "Claude-SearchBot", category: "ai_search_crawler", organization: "Anthropic", baseScore: 75, respectsRobots: true, uaPatterns: ["claude-searchbot"] },
|
|
500
|
+
{ id: "oai-searchbot", name: "OAI-SearchBot", category: "ai_search_crawler", organization: "OpenAI", baseScore: 80, respectsRobots: true, uaPatterns: ["oai-searchbot"] },
|
|
483
501
|
{ id: "searchgpt", name: "SearchGPT", category: "ai_search_crawler", organization: "OpenAI", baseScore: 75, respectsRobots: true, uaPatterns: ["searchgpt"] },
|
|
484
502
|
{ id: "phind", name: "Phind", category: "ai_search_crawler", organization: "Phind", baseScore: 70, respectsRobots: true, uaPatterns: ["phind"] },
|
|
485
503
|
{ id: "kagi", name: "Kagi", category: "ai_search_crawler", organization: "Kagi", baseScore: 65, respectsRobots: true, uaPatterns: ["kagi"] },
|
|
@@ -498,7 +516,9 @@ var BOT_REGISTRY = [
|
|
|
498
516
|
{ id: "multion", name: "MultiOn", category: "ai_agent", organization: "MultiOn", baseScore: 70, respectsRobots: false, uaPatterns: ["multion"] },
|
|
499
517
|
{ id: "iboubot", name: "IbouBot", category: "search_crawler", organization: "Ibou", baseScore: 30, respectsRobots: true, uaPatterns: ["iboubot"] },
|
|
500
518
|
{ id: "googlebot", name: "Googlebot", category: "search_crawler", organization: "Google", baseScore: 30, respectsRobots: true, uaPatterns: ["googlebot"] },
|
|
519
|
+
{ id: "google-inspectiontool", name: "Google-InspectionTool", category: "search_crawler", organization: "Google", baseScore: 30, respectsRobots: true, uaPatterns: ["google-inspectiontool"] },
|
|
501
520
|
{ id: "bingbot", name: "Bingbot", category: "search_crawler", organization: "Microsoft", baseScore: 30, respectsRobots: true, uaPatterns: ["bingbot"] },
|
|
521
|
+
{ id: "msnbot", name: "MSNBot", category: "search_crawler", organization: "Microsoft", baseScore: 30, respectsRobots: true, uaPatterns: ["msnbot"] },
|
|
502
522
|
{ id: "yandexbot", name: "YandexBot", category: "search_crawler", organization: "Yandex", baseScore: 35, respectsRobots: true, uaPatterns: ["yandexbot"] },
|
|
503
523
|
{ id: "baiduspider", name: "Baiduspider", category: "search_crawler", organization: "Baidu", baseScore: 40, respectsRobots: true, uaPatterns: ["baiduspider"] },
|
|
504
524
|
{ id: "duckduckbot", name: "DuckDuckBot", category: "search_crawler", organization: "DuckDuckGo", baseScore: 30, respectsRobots: true, uaPatterns: ["duckduckbot"] },
|
|
@@ -573,6 +593,7 @@ var BOT_REGISTRY = [
|
|
|
573
593
|
{ id: "heritrix", name: "Heritrix", category: "archiver", organization: "Internet Archive", baseScore: 30, respectsRobots: true, uaPatterns: ["heritrix"] },
|
|
574
594
|
{ id: "brozzler", name: "Brozzler", category: "archiver", organization: "Internet Archive", baseScore: 30, respectsRobots: true, uaPatterns: ["brozzler"] },
|
|
575
595
|
{ id: "facebookexternalhit", name: "Facebook", category: "fetcher", organization: "Meta", baseScore: 25, respectsRobots: true, uaPatterns: ["facebookexternalhit"] },
|
|
596
|
+
{ id: "facebot", name: "Facebot", category: "fetcher", organization: "Meta", baseScore: 25, respectsRobots: true, uaPatterns: ["facebot"] },
|
|
576
597
|
{ id: "twitterbot", name: "Twitterbot", category: "fetcher", organization: "X Corp", baseScore: 25, respectsRobots: true, uaPatterns: ["twitterbot"] },
|
|
577
598
|
{ id: "linkedinbot", name: "LinkedInBot", category: "fetcher", organization: "LinkedIn", baseScore: 25, respectsRobots: true, uaPatterns: ["linkedinbot"] },
|
|
578
599
|
{ id: "slackbot", name: "Slackbot", category: "fetcher", organization: "Slack", baseScore: 25, respectsRobots: true, uaPatterns: ["slackbot"] },
|
|
@@ -600,7 +621,10 @@ var BOT_REGISTRY = [
|
|
|
600
621
|
{ id: "freshping", name: "Freshping", category: "monitoring", organization: "Freshworks", baseScore: 20, respectsRobots: true, uaPatterns: ["freshping"] },
|
|
601
622
|
{ id: "hetrixtools", name: "HetrixTools", category: "monitoring", organization: "HetrixTools", baseScore: 20, respectsRobots: true, uaPatterns: ["hetrixtools"] },
|
|
602
623
|
{ id: "nodeping", name: "NodePing", category: "monitoring", organization: "NodePing", baseScore: 20, respectsRobots: true, uaPatterns: ["nodeping"] },
|
|
624
|
+
{ id: "gtmetrix", name: "GTmetrix", category: "monitoring", organization: "GTmetrix", baseScore: 20, respectsRobots: true, uaPatterns: ["gtmetrix"] },
|
|
625
|
+
{ id: "chrome-lighthouse", name: "Lighthouse", category: "monitoring", organization: "Google", baseScore: 20, respectsRobots: true, uaPatterns: ["chrome-lighthouse", "google page speed"] },
|
|
603
626
|
{ id: "feedly", name: "Feedly", category: "feed_reader", organization: "Feedly", baseScore: 25, respectsRobots: true, uaPatterns: ["feedly"] },
|
|
627
|
+
{ id: "feedfetcher-google", name: "Feedfetcher-Google", category: "feed_reader", organization: "Google", baseScore: 25, respectsRobots: true, uaPatterns: ["feedfetcher"] },
|
|
604
628
|
{ id: "newsblur", name: "NewsBlur", category: "feed_reader", organization: "NewsBlur", baseScore: 25, respectsRobots: true, uaPatterns: ["newsblur"] },
|
|
605
629
|
{ id: "inoreader", name: "Inoreader", category: "feed_reader", organization: "Inoreader", baseScore: 25, respectsRobots: true, uaPatterns: ["inoreader"] },
|
|
606
630
|
{ id: "theoldreader", name: "The Old Reader", category: "feed_reader", organization: "The Old Reader", baseScore: 25, respectsRobots: true, uaPatterns: ["theoldreader"] },
|
|
@@ -618,6 +642,10 @@ var BOT_REGISTRY = [
|
|
|
618
642
|
{ id: "apify", name: "Apify", category: "commercial_scraper", organization: "Apify", baseScore: 65, respectsRobots: true, uaPatterns: ["apify"] },
|
|
619
643
|
{ id: "crawlbase", name: "Crawlbase", category: "commercial_scraper", organization: "Crawlbase", baseScore: 65, respectsRobots: true, uaPatterns: ["crawlbase"] },
|
|
620
644
|
{ id: "webscrapingapi", name: "WebScrapingAPI", category: "commercial_scraper", organization: "WebScrapingAPI", baseScore: 65, respectsRobots: true, uaPatterns: ["webscrapingapi"] },
|
|
645
|
+
{ id: "chatgpt-user", name: "ChatGPT-User", category: "ai_assistant", organization: "OpenAI", baseScore: 85, respectsRobots: true, uaPatterns: ["chatgpt-user"] },
|
|
646
|
+
{ id: "perplexity-user", name: "Perplexity-User", category: "ai_assistant", organization: "Perplexity AI", baseScore: 75, respectsRobots: false, uaPatterns: ["perplexity-user"] },
|
|
647
|
+
{ id: "mistralai-user", name: "MistralAI-User", category: "ai_assistant", organization: "Mistral AI", baseScore: 75, respectsRobots: true, uaPatterns: ["mistralai-user"] },
|
|
648
|
+
{ id: "meta-externalfetcher", name: "Meta-ExternalFetcher", category: "ai_assistant", organization: "Meta", baseScore: 70, respectsRobots: false, uaPatterns: ["meta-externalfetcher"] },
|
|
621
649
|
{ id: "gemini-deep-research", name: "Gemini-Deep-Research", category: "ai_assistant", organization: "Google", baseScore: 65, respectsRobots: true, uaPatterns: ["gemini-deep-research"] },
|
|
622
650
|
{ id: "copilot", name: "Microsoft Copilot", category: "ai_assistant", organization: "Microsoft", baseScore: 65, respectsRobots: true, uaPatterns: ["copilot"] },
|
|
623
651
|
{ id: "cortana", name: "Cortana", category: "ai_assistant", organization: "Microsoft", baseScore: 60, respectsRobots: true, uaPatterns: ["cortana"] },
|
|
@@ -801,6 +829,143 @@ var ViolationReporter = class {
|
|
|
801
829
|
}
|
|
802
830
|
};
|
|
803
831
|
|
|
832
|
+
// src/referrals/llm-platforms.generated.ts
|
|
833
|
+
var LLM_PLATFORMS = {
|
|
834
|
+
"chat.deepseek.com": "DeepSeek",
|
|
835
|
+
"chat.openai.com": "ChatGPT",
|
|
836
|
+
"chatgpt.com": "ChatGPT",
|
|
837
|
+
"claude.ai": "Claude",
|
|
838
|
+
"copilot.microsoft.com": "Copilot",
|
|
839
|
+
"deepseek.com": "DeepSeek",
|
|
840
|
+
"gemini.google.com": "Gemini",
|
|
841
|
+
"grok.com": "Grok",
|
|
842
|
+
"kagi.com": "Kagi",
|
|
843
|
+
"meta.ai": "Meta AI",
|
|
844
|
+
"perplexity.ai": "Perplexity",
|
|
845
|
+
"phind.com": "Phind",
|
|
846
|
+
"www.deepseek.com": "DeepSeek",
|
|
847
|
+
"www.grok.com": "Grok",
|
|
848
|
+
"www.kagi.com": "Kagi",
|
|
849
|
+
"www.meta.ai": "Meta AI",
|
|
850
|
+
"www.perplexity.ai": "Perplexity",
|
|
851
|
+
"www.phind.com": "Phind",
|
|
852
|
+
"www.you.com": "You.com",
|
|
853
|
+
"you.com": "You.com"
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
// src/referrals/llm-referral.ts
|
|
857
|
+
var TAG_KEYS = ["utm_source", "ref", "utm_medium"];
|
|
858
|
+
function classifyReferral(referer, pageUrl) {
|
|
859
|
+
const ref = (referer ?? "").trim();
|
|
860
|
+
if (ref) {
|
|
861
|
+
try {
|
|
862
|
+
return LLM_PLATFORMS[new URL(ref).hostname.toLowerCase()] ?? "";
|
|
863
|
+
} catch {
|
|
864
|
+
return "";
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
let url;
|
|
868
|
+
try {
|
|
869
|
+
url = new URL(pageUrl);
|
|
870
|
+
} catch {
|
|
871
|
+
return "";
|
|
872
|
+
}
|
|
873
|
+
for (const key of TAG_KEYS) {
|
|
874
|
+
for (const value of url.searchParams.getAll(key)) {
|
|
875
|
+
const platform = platformForTag(value);
|
|
876
|
+
if (platform) return platform;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
return "";
|
|
880
|
+
}
|
|
881
|
+
var squash = (s) => s.replace(/[ \-_.]/g, "");
|
|
882
|
+
function platformForTag(raw) {
|
|
883
|
+
let value = raw.trim().toLowerCase();
|
|
884
|
+
if (!value) return "";
|
|
885
|
+
try {
|
|
886
|
+
const host = new URL(value).hostname;
|
|
887
|
+
if (host) value = host.toLowerCase();
|
|
888
|
+
} catch {
|
|
889
|
+
}
|
|
890
|
+
value = value.replace(/\.$/, "");
|
|
891
|
+
if (LLM_PLATFORMS[value]) return LLM_PLATFORMS[value];
|
|
892
|
+
const normalized = squash(value);
|
|
893
|
+
for (const [domain, name] of Object.entries(LLM_PLATFORMS)) {
|
|
894
|
+
if (normalized === squash(name.toLowerCase()) || normalized === domain.replace(/^www\./, "").replace(/\./g, "")) {
|
|
895
|
+
return name;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return "";
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
// src/referrals/referral-counter.ts
|
|
902
|
+
var MAX_PATH = 500;
|
|
903
|
+
var MAX_ENTRIES = 500;
|
|
904
|
+
var header = (headers, name) => {
|
|
905
|
+
const v = headers[name] ?? headers[name.toLowerCase()];
|
|
906
|
+
if (v !== void 0) return v;
|
|
907
|
+
for (const [k, value] of Object.entries(headers)) if (k.toLowerCase() === name) return value;
|
|
908
|
+
return "";
|
|
909
|
+
};
|
|
910
|
+
var AIReferralCounter = class {
|
|
911
|
+
constructor(sender, config = {}) {
|
|
912
|
+
this.sender = sender;
|
|
913
|
+
this.counts = /* @__PURE__ */ new Map();
|
|
914
|
+
/** A batch that failed to send, retried under the same id so it counts once. */
|
|
915
|
+
this.pending = null;
|
|
916
|
+
this.flushing = false;
|
|
917
|
+
this.timer = setInterval(() => void this.flush(), config.flushInterval ?? 6e4);
|
|
918
|
+
this.timer.unref?.();
|
|
919
|
+
}
|
|
920
|
+
/** Count the request if it is a page visit an AI product sent. Never throws. */
|
|
921
|
+
observe(metadata) {
|
|
922
|
+
try {
|
|
923
|
+
if ((metadata.method ?? "").toUpperCase() !== "GET") return;
|
|
924
|
+
const headers = metadata.headers ?? {};
|
|
925
|
+
if (header(headers, "sec-fetch-mode") !== "navigate") return;
|
|
926
|
+
const dest = header(headers, "sec-fetch-dest");
|
|
927
|
+
if (dest && dest !== "document") return;
|
|
928
|
+
const path = (metadata.path || "/").split("?")[0] || "/";
|
|
929
|
+
const query = metadata.query ? `?${metadata.query}` : "";
|
|
930
|
+
const platform = classifyReferral(header(headers, "referer"), `https://site.invalid${path}${query}`);
|
|
931
|
+
if (!platform) return;
|
|
932
|
+
const landing = path.length > MAX_PATH ? path.slice(0, MAX_PATH) : path;
|
|
933
|
+
const key = `${platform}
|
|
934
|
+
${landing}`;
|
|
935
|
+
const entry = this.counts.get(key);
|
|
936
|
+
if (entry) {
|
|
937
|
+
entry.count++;
|
|
938
|
+
} else {
|
|
939
|
+
this.counts.set(key, { platform, path: landing, count: 1 });
|
|
940
|
+
if (this.counts.size >= MAX_ENTRIES) void this.flush();
|
|
941
|
+
}
|
|
942
|
+
} catch {
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
/** Send what has been counted. Never rejects. */
|
|
946
|
+
async flush() {
|
|
947
|
+
if (this.flushing) return;
|
|
948
|
+
this.flushing = true;
|
|
949
|
+
try {
|
|
950
|
+
if (!this.pending && this.counts.size > 0) {
|
|
951
|
+
this.pending = { report_id: crypto.randomUUID(), source: "sdk", referrals: [...this.counts.values()] };
|
|
952
|
+
this.counts = /* @__PURE__ */ new Map();
|
|
953
|
+
}
|
|
954
|
+
if (this.pending && await this.sender.sendAIReferrals(this.pending)) {
|
|
955
|
+
this.pending = null;
|
|
956
|
+
}
|
|
957
|
+
} catch {
|
|
958
|
+
} finally {
|
|
959
|
+
this.flushing = false;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
/** Stop the timer and send what is left. */
|
|
963
|
+
async destroy() {
|
|
964
|
+
clearInterval(this.timer);
|
|
965
|
+
await this.flush();
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
|
|
804
969
|
// src/ip-enrichment.ts
|
|
805
970
|
var IPEnrichmentClient = class {
|
|
806
971
|
constructor(client, ttlMs = 36e5) {
|
|
@@ -1309,16 +1474,16 @@ function componentValue(req, c) {
|
|
|
1309
1474
|
case "@query":
|
|
1310
1475
|
return req.url.search === "" ? "?" : req.url.search;
|
|
1311
1476
|
case "signature-agent": {
|
|
1312
|
-
const
|
|
1313
|
-
if (
|
|
1314
|
-
if (c.keyParam !== void 0) return dictMemberValue(
|
|
1315
|
-
return
|
|
1477
|
+
const header2 = req.headers.get("signature-agent");
|
|
1478
|
+
if (header2 === null) throw new Error("signature-agent covered but absent");
|
|
1479
|
+
if (c.keyParam !== void 0) return dictMemberValue(header2, c.keyParam);
|
|
1480
|
+
return header2.trim().replace(/\s+/g, " ");
|
|
1316
1481
|
}
|
|
1317
1482
|
default: {
|
|
1318
1483
|
if (name.startsWith("@")) throw new Error(`unsupported derived component ${name}`);
|
|
1319
|
-
const
|
|
1320
|
-
if (
|
|
1321
|
-
return
|
|
1484
|
+
const header2 = req.headers.get(name);
|
|
1485
|
+
if (header2 === null) throw new Error(`covered header ${name} absent`);
|
|
1486
|
+
return header2.trim().replace(/\s+/g, " ");
|
|
1322
1487
|
}
|
|
1323
1488
|
}
|
|
1324
1489
|
}
|
|
@@ -1331,8 +1496,8 @@ function canonicalAuthority(url) {
|
|
|
1331
1496
|
}
|
|
1332
1497
|
return `${host}:${port}`;
|
|
1333
1498
|
}
|
|
1334
|
-
function dictMemberValue(
|
|
1335
|
-
const dict = parseDictionary(
|
|
1499
|
+
function dictMemberValue(header2, key) {
|
|
1500
|
+
const dict = parseDictionary(header2);
|
|
1336
1501
|
const found = dict.find((d) => d.key === key);
|
|
1337
1502
|
if (!found) throw new Error(`signature-agent has no member ${key}`);
|
|
1338
1503
|
return found.raw;
|
|
@@ -1702,6 +1867,7 @@ function isTestTriggerUserAgent(userAgent) {
|
|
|
1702
1867
|
// src/sdk.ts
|
|
1703
1868
|
var WebDecoy = class {
|
|
1704
1869
|
constructor(config) {
|
|
1870
|
+
this.referralCounter = null;
|
|
1705
1871
|
this.violationReporter = null;
|
|
1706
1872
|
this.ipEnrichmentClient = null;
|
|
1707
1873
|
this._hasFilterRules = false;
|
|
@@ -1723,7 +1889,8 @@ var WebDecoy = class {
|
|
|
1723
1889
|
threatScoreThreshold: config.threatScoreThreshold ?? 80,
|
|
1724
1890
|
timeout: config.timeout ?? 5e3,
|
|
1725
1891
|
debug: config.debug ?? false,
|
|
1726
|
-
tlsRejectUnauthorized: config.tlsRejectUnauthorized ?? true
|
|
1892
|
+
tlsRejectUnauthorized: config.tlsRejectUnauthorized ?? true,
|
|
1893
|
+
countAIReferrals: config.countAIReferrals ?? true
|
|
1727
1894
|
};
|
|
1728
1895
|
this.log = resolveLogger(config.logger, this.config.debug);
|
|
1729
1896
|
this.tracer = config.tracer;
|
|
@@ -1757,6 +1924,9 @@ var WebDecoy = class {
|
|
|
1757
1924
|
if (this.client && this._hasFilterRules) {
|
|
1758
1925
|
this.ipEnrichmentClient = new IPEnrichmentClient(this.client);
|
|
1759
1926
|
}
|
|
1927
|
+
if (this.client && this.config.countAIReferrals !== false) {
|
|
1928
|
+
this.referralCounter = new AIReferralCounter(this.client);
|
|
1929
|
+
}
|
|
1760
1930
|
if (this.client && this.ruleEngine) {
|
|
1761
1931
|
const reporter = new ViolationReporter(this.client, {
|
|
1762
1932
|
debug: this.config.debug
|
|
@@ -1928,6 +2098,7 @@ var WebDecoy = class {
|
|
|
1928
2098
|
*/
|
|
1929
2099
|
async protect(metadata, options = {}) {
|
|
1930
2100
|
const edge = readEdgeVerdict(metadata.headers);
|
|
2101
|
+
this.referralCounter?.observe(metadata);
|
|
1931
2102
|
const span = startSpan(this.tracer, "webdecoy.protect");
|
|
1932
2103
|
try {
|
|
1933
2104
|
const decision = (await this.decide(metadata, options)).withEdge(edge);
|
|
@@ -2189,6 +2360,7 @@ var WebDecoy = class {
|
|
|
2189
2360
|
if (this.violationReporter) {
|
|
2190
2361
|
await this.violationReporter.destroy();
|
|
2191
2362
|
}
|
|
2363
|
+
await this.referralCounter?.destroy();
|
|
2192
2364
|
}
|
|
2193
2365
|
};
|
|
2194
2366
|
function agentInputFromMetadata(metadata) {
|
package/dist/testing.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdecoy/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Web Decoy SDK for Node.js - Bot detection with TLS fingerprinting",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"security",
|
|
37
37
|
"middleware"
|
|
38
38
|
],
|
|
39
|
-
"author": "
|
|
39
|
+
"author": "WebDecoy LLC",
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"homepage": "https://github.com/WebDecoy/node#readme",
|
|
42
42
|
"repository": {
|