@webdecoy/node 0.22.2 → 0.23.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 CHANGED
@@ -1,12 +1,18 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/WebDecoy/node/main/docs/assets/node-banner.png" alt="WebDecoy for Node.js: bot detection, AI agent verification and local rules" width="100%">
3
+ </p>
4
+
1
5
  # @webdecoy/node
2
6
 
3
- The core WebDecoy SDK for Node.js and edge runtimes: tripwires, rate limits and other local rules, plus optional server-side bot detection reported to your WebDecoy dashboard.
7
+ TypeScript bot detection and protection for Node.js and edge runtimes. Run honeypot tripwires, rate limits, AI crawler policies and signed-agent verification locally without an account or API key. Add optional hosted analysis and WebDecoy dashboard reporting when you need them.
4
8
 
5
9
  [![npm version](https://img.shields.io/npm/v/@webdecoy/node.svg)](https://www.npmjs.com/package/@webdecoy/node)
6
10
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
11
 
8
12
  Full documentation: [docs.webdecoy.com/sdk-plugins/node-sdk](https://docs.webdecoy.com/sdk-plugins/node-sdk/). Copy-paste install snippets for every stack: [docs.webdecoy.com/installation/install-with-ai](https://docs.webdecoy.com/installation/install-with-ai/).
9
13
 
14
+ **[Try the Express playground in your browser](https://stackblitz.com/github/WebDecoy/node/tree/main/playgrounds/express?file=app.mjs)** · [Watch the 30-second demo](https://youtu.be/4jeuH3tKeos)
15
+
10
16
  ## Using a framework? Install its adapter
11
17
 
12
18
  Most apps should install a framework adapter alongside this package. The adapters handle request mapping, client IP, monitor mode and honeytoken injection for you. Install `@webdecoy/node` too: it is where `tripwire()`, `rateLimit()` and the other rules are imported from.
@@ -45,6 +45,7 @@ var BOT_REGISTRY = [
45
45
  { id: "isscyberriskcrawler", name: "ISSCyberRiskCrawler", category: "training_crawler", organization: "ISS", baseScore: 65, respectsRobots: false, uaPatterns: ["isscyberriskcrawler"] },
46
46
  { id: "friendlycrawler", name: "FriendlyCrawler", category: "training_crawler", organization: "Unknown", baseScore: 65, respectsRobots: true, uaPatterns: ["friendlycrawler"] },
47
47
  { id: "elevenlabscrawler", name: "ElevenlabsCrawler", category: "training_crawler", organization: "ElevenLabs", baseScore: 80, respectsRobots: true, uaPatterns: ["elevenlabscrawler"] },
48
+ { id: "riverbot", name: "RiverBot", category: "training_crawler", organization: "River", baseScore: 80, respectsRobots: true, uaPatterns: ["riverbot"] },
48
49
  { id: "kimibot", name: "KimiBot", category: "training_crawler", organization: "Moonshot AI", baseScore: 80, respectsRobots: true, uaPatterns: ["kimibot"] },
49
50
  { id: "moonshotbot", name: "MoonshotBot", category: "training_crawler", organization: "Moonshot AI", baseScore: 80, respectsRobots: false, uaPatterns: ["moonshotbot"] },
50
51
  { id: "chatglm-spider", name: "ChatGLM-Spider", category: "training_crawler", organization: "Zhipu AI", baseScore: 80, respectsRobots: false, uaPatterns: ["chatglm-spider"] },
@@ -66,6 +67,7 @@ var BOT_REGISTRY = [
66
67
  { id: "brave-search", name: "BraveSearch", category: "ai_search_crawler", organization: "Brave", baseScore: 65, respectsRobots: true, uaPatterns: ["bravesearch"] },
67
68
  { id: "neeva", name: "NeevaBot", category: "ai_search_crawler", organization: "Neeva", baseScore: 65, respectsRobots: true, uaPatterns: ["neevabot"] },
68
69
  { id: "kimi-searchbot", name: "Kimi-SearchBot", category: "ai_search_crawler", organization: "Moonshot AI", baseScore: 65, respectsRobots: true, uaPatterns: ["kimi-searchbot"] },
70
+ { id: "isonsearchbot", name: "IsonSearchBot", category: "ai_search_crawler", organization: "Ison Search", baseScore: 65, respectsRobots: true, uaPatterns: ["isonsearchbot"] },
69
71
  { id: "keenablebot", name: "KeenableBot", category: "ai_search_crawler", organization: "Keenable", baseScore: 65, respectsRobots: true, uaPatterns: ["keenablebot"] },
70
72
  { id: "azureai-searchbot", name: "AzureAI-SearchBot", category: "ai_search_crawler", organization: "Microsoft", baseScore: 65, respectsRobots: false, uaPatterns: ["azureai-searchbot"] },
71
73
  { id: "grokbot", name: "GrokBot", category: "ai_search_crawler", organization: "xAI", baseScore: 70, respectsRobots: false, uaPatterns: ["grokbot"] },
@@ -116,6 +118,9 @@ var BOT_REGISTRY = [
116
118
  { id: "spyfu", name: "SpyFu", category: "seo_crawler", organization: "SpyFu", baseScore: 50, respectsRobots: true, uaPatterns: ["spyfu"] },
117
119
  { id: "meta-externalads", name: "meta-externalads", category: "seo_crawler", organization: "Meta", baseScore: 40, respectsRobots: true, uaPatterns: ["meta-externalads"] },
118
120
  { id: "dataforseobot", name: "DataForSeoBot", category: "seo_crawler", organization: "DataForSEO", baseScore: 50, respectsRobots: true, uaPatterns: ["dataforseobot"] },
121
+ { id: "barkrowler", name: "Barkrowler", category: "seo_crawler", organization: "Babbar", baseScore: 50, respectsRobots: true, uaPatterns: ["barkrowler"] },
122
+ { id: "scrunchbot", name: "Scrunchbot", category: "seo_crawler", organization: "Scrunch", baseScore: 50, respectsRobots: true, uaPatterns: ["scrunchbot"] },
123
+ { id: "webxtrendbot", name: "webXtrendBot", category: "seo_crawler", organization: "webXtrend", baseScore: 50, respectsRobots: true, uaPatterns: ["webxtrendbot"] },
119
124
  { id: "serankingbacklinksbot", name: "SERankingBacklinksBot", category: "seo_crawler", organization: "SE Ranking", baseScore: 50, respectsRobots: true, uaPatterns: ["serankingbacklinksbot"] },
120
125
  { id: "awariobot", name: "AwarioBot", category: "seo_crawler", organization: "Awario", baseScore: 50, respectsRobots: true, uaPatterns: ["awariobot", "awariosmartbot"] },
121
126
  { id: "seojuice-searchbot", name: "SEOJuice-SearchBot", category: "seo_crawler", organization: "SEOJuice", baseScore: 50, respectsRobots: true, uaPatterns: ["seojuice-searchbot"] },
@@ -133,6 +138,10 @@ var BOT_REGISTRY = [
133
138
  { id: "acunetix", name: "Acunetix", category: "security_scanner", organization: "Invicti", baseScore: 70, respectsRobots: false, uaPatterns: ["acunetix"] },
134
139
  { id: "netsparker", name: "Netsparker", category: "security_scanner", organization: "Invicti", baseScore: 70, respectsRobots: false, uaPatterns: ["netsparker"] },
135
140
  { id: "detectify", name: "Detectify", category: "security_scanner", organization: "Detectify", baseScore: 65, respectsRobots: false, uaPatterns: ["detectify"] },
141
+ { id: "paloalto-xpanse", name: "Palo Alto Networks Cortex Xpanse", category: "security_scanner", organization: "Palo Alto Networks", baseScore: 65, respectsRobots: false, uaPatterns: ["palo alto networks"] },
142
+ { id: "recordedfuture", name: "Recorded Future Crawler", category: "security_scanner", organization: "Recorded Future", baseScore: 65, respectsRobots: false, uaPatterns: ["recordedfuture"] },
143
+ { id: "cloudflare-security-center", name: "Cloudflare Security Center", category: "security_scanner", organization: "Cloudflare", baseScore: 40, respectsRobots: false, uaPatterns: ["developers.cloudflare.com/security-center"] },
144
+ { id: "virustotal-cloud", name: "VirusTotal", category: "security_scanner", organization: "Google", baseScore: 40, respectsRobots: false, uaPatterns: ["virustotalcloud"] },
136
145
  { id: "intruder", name: "Intruder", category: "security_scanner", organization: "Intruder", baseScore: 65, respectsRobots: false, uaPatterns: ["intruder"] },
137
146
  { id: "python-requests", name: "Python-Requests", category: "generic_scraper", organization: "Open Source", baseScore: 55, respectsRobots: false, uaPatterns: ["python-requests"] },
138
147
  { id: "python-urllib", name: "Python-urllib", category: "generic_scraper", organization: "Python", baseScore: 55, respectsRobots: false, uaPatterns: ["python-urllib"] },
@@ -183,6 +192,7 @@ var BOT_REGISTRY = [
183
192
  { id: "embedly", name: "Embedly", category: "fetcher", organization: "Medium", baseScore: 30, respectsRobots: true, uaPatterns: ["embedly"] },
184
193
  { id: "iframely", name: "Iframely", category: "fetcher", organization: "Iframely", baseScore: 30, respectsRobots: true, uaPatterns: ["iframely"] },
185
194
  { id: "adsbot-google", name: "AdsBot-Google", category: "fetcher", organization: "Google", baseScore: 25, respectsRobots: true, uaPatterns: ["adsbot-google"] },
195
+ { id: "stripebot", name: "Stripebot", category: "fetcher", organization: "Stripe", baseScore: 25, respectsRobots: true, uaPatterns: ["stripebot"] },
186
196
  { id: "google-read-aloud", name: "Google-Read-Aloud", category: "fetcher", organization: "Google", baseScore: 25, respectsRobots: false, uaPatterns: ["google-read-aloud"] },
187
197
  { id: "google-safety", name: "Google-Safety", category: "fetcher", organization: "Google", baseScore: 25, respectsRobots: false, uaPatterns: ["google-safety"] },
188
198
  { id: "oai-adsbot", name: "OAI-AdsBot", category: "fetcher", organization: "OpenAI", baseScore: 30, respectsRobots: true, uaPatterns: ["oai-adsbot"] },
@@ -206,6 +216,7 @@ var BOT_REGISTRY = [
206
216
  { id: "gtmetrix", name: "GTmetrix", category: "monitoring", organization: "GTmetrix", baseScore: 20, respectsRobots: true, uaPatterns: ["gtmetrix"] },
207
217
  { id: "chrome-lighthouse", name: "Lighthouse", category: "monitoring", organization: "Google", baseScore: 20, respectsRobots: true, uaPatterns: ["chrome-lighthouse", "google page speed"] },
208
218
  { id: "feedly", name: "Feedly", category: "feed_reader", organization: "Feedly", baseScore: 25, respectsRobots: true, uaPatterns: ["feedly"] },
219
+ { id: "livelapbot", name: "LivelapBot", category: "feed_reader", organization: "Livelap", baseScore: 30, respectsRobots: true, uaPatterns: ["livelapbot"] },
209
220
  { id: "feedfetcher-google", name: "Feedfetcher-Google", category: "feed_reader", organization: "Google", baseScore: 25, respectsRobots: true, uaPatterns: ["feedfetcher"] },
210
221
  { id: "newsblur", name: "NewsBlur", category: "feed_reader", organization: "NewsBlur", baseScore: 25, respectsRobots: true, uaPatterns: ["newsblur"] },
211
222
  { id: "inoreader", name: "Inoreader", category: "feed_reader", organization: "Inoreader", baseScore: 25, respectsRobots: true, uaPatterns: ["inoreader"] },
@@ -217,6 +228,9 @@ var BOT_REGISTRY = [
217
228
  { id: "diffbot", name: "Diffbot", category: "commercial_scraper", organization: "Diffbot", baseScore: 70, respectsRobots: true, uaPatterns: ["diffbot"] },
218
229
  { id: "import-io", name: "Import.io", category: "commercial_scraper", organization: "Import.io", baseScore: 65, respectsRobots: true, uaPatterns: ["import.io"] },
219
230
  { id: "bright-data", name: "Bright Data", category: "commercial_scraper", organization: "Bright Data", baseScore: 70, respectsRobots: false, uaPatterns: ["brightdata", "luminati"] },
231
+ { id: "brightbot", name: "Brightbot", category: "commercial_scraper", organization: "Bright Data", baseScore: 60, respectsRobots: true, uaPatterns: ["brightbot"] },
232
+ { id: "cloudflare-crawl", name: "Cloudflare Browser Rendering Crawler", category: "commercial_scraper", organization: "Cloudflare", baseScore: 55, respectsRobots: true, uaPatterns: ["cloudflarebrowserrenderingcrawler"] },
233
+ { id: "ev-crawler", name: "ev-crawler", category: "commercial_scraper", organization: "Headline", baseScore: 55, respectsRobots: true, uaPatterns: ["ev-crawler"] },
220
234
  { id: "oxylabs", name: "Oxylabs", category: "commercial_scraper", organization: "Oxylabs", baseScore: 70, respectsRobots: false, uaPatterns: ["oxylabs"] },
221
235
  { id: "scrapingbee", name: "ScrapingBee", category: "commercial_scraper", organization: "ScrapingBee", baseScore: 65, respectsRobots: true, uaPatterns: ["scrapingbee"] },
222
236
  { id: "scrapingant", name: "ScrapingAnt", category: "commercial_scraper", organization: "ScrapingAnt", baseScore: 65, respectsRobots: true, uaPatterns: ["scrapingant"] },
@@ -1741,8 +1755,31 @@ function base64urlBytes(bytes) {
1741
1755
  return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1742
1756
  }
1743
1757
 
1758
+ // src/agent/identity.ts
1759
+ var WELL_KNOWN_DIRECTORY = "/.well-known/http-message-signatures-directory";
1760
+ function resolveSignatureAgent(value) {
1761
+ if (!/^https:\/\/[^/\\]/i.test(value)) throw new Error("signature-agent must be an https URL");
1762
+ const url = new URL(value);
1763
+ if (url.protocol !== "https:" || !url.hostname || url.username || url.password) {
1764
+ throw new Error("signature-agent must be an https URL");
1765
+ }
1766
+ url.hash = "";
1767
+ const hasQuery = url.href.includes("?");
1768
+ const authority = canonicalAuthority(url);
1769
+ if (url.pathname === "/" && !hasQuery) {
1770
+ const wellKnown = `https://${authority}${WELL_KNOWN_DIRECTORY}`;
1771
+ return { fetch: wellKnown, identifier: wellKnown };
1772
+ }
1773
+ const path = url.pathname.replace(/%[0-9a-f]{2}/gi, (m) => m.toUpperCase());
1774
+ return { fetch: url.href, identifier: `https://${authority}${path}` };
1775
+ }
1776
+ function canonicalAuthority(url) {
1777
+ const host = url.hostname.toLowerCase();
1778
+ if (!url.port || url.port === "443") return host;
1779
+ return `${host}:${url.port}`;
1780
+ }
1781
+
1744
1782
  // src/agent/directory.ts
1745
- var WELL_KNOWN = "/.well-known/http-message-signatures-directory";
1746
1783
  var COLD_RETRY_BACKOFF_MS = 3e4;
1747
1784
  var DEFAULT_SIGNED_AGENT_DIRECTORIES = [
1748
1785
  { name: "OpenAI ChatGPT", category: "ai_crawlers", directory: "https://chatgpt.com" },
@@ -1755,10 +1792,14 @@ var DirectoryCache = class {
1755
1792
  this.refreshedAt = 0;
1756
1793
  this.nextColdRetryAt = 0;
1757
1794
  this.inflight = null;
1758
- /** Resolve a keyid to a verification key, fetching/refreshing as needed. */
1759
- this.resolveKey = async (keyId) => {
1795
+ /**
1796
+ * Resolve a keyid published by one agent identity (a resolved
1797
+ * Signature-Agent URL) to a verification key, fetching/refreshing as
1798
+ * needed. A key is only ever attributed to the directory that published it.
1799
+ */
1800
+ this.resolveKey = async (keyId, agent) => {
1760
1801
  await this.ensureFresh();
1761
- return this.keys.get(keyId);
1802
+ return this.keys.get(cacheKey(agent, keyId));
1762
1803
  };
1763
1804
  this.opts = opts;
1764
1805
  }
@@ -1797,7 +1838,7 @@ var DirectoryCache = class {
1797
1838
  for (const keys of results) {
1798
1839
  if (keys === null) continue;
1799
1840
  fetchedAny = true;
1800
- for (const k of keys) next.set(k.thumbprint, k.key);
1841
+ for (const k of keys) next.set(cacheKey(k.identifier, k.thumbprint), k.key);
1801
1842
  }
1802
1843
  if (fetchedAny) {
1803
1844
  this.keys = next;
@@ -1810,7 +1851,14 @@ var DirectoryCache = class {
1810
1851
  }
1811
1852
  }
1812
1853
  async fetchDirectory(src) {
1813
- const url = directoryUrl(src.directory);
1854
+ let url;
1855
+ let identifier;
1856
+ try {
1857
+ ({ fetch: url, identifier } = resolveSignatureAgent(src.directory));
1858
+ } catch {
1859
+ this.debug(`${src.name}: directory is not an https URL`);
1860
+ return null;
1861
+ }
1814
1862
  const controller = new AbortController();
1815
1863
  const timer = setTimeout(() => controller.abort(), this.opts.fetchTimeoutMs);
1816
1864
  try {
@@ -1819,7 +1867,8 @@ var DirectoryCache = class {
1819
1867
  headers: {
1820
1868
  Accept: "application/http-message-signatures-directory+json, application/jwk-set+json, application/json"
1821
1869
  },
1822
- redirect: "follow"
1870
+ // Web Bot Auth draft 01 §5.5: redirects are a discovery failure.
1871
+ redirect: "error"
1823
1872
  });
1824
1873
  if (!res.ok) {
1825
1874
  this.debug(`${src.name}: HTTP ${res.status}`);
@@ -1833,7 +1882,7 @@ var DirectoryCache = class {
1833
1882
  const out = [];
1834
1883
  for (const jwk of body.keys) {
1835
1884
  const resolved = await importKey(jwk, src);
1836
- if (resolved) out.push(resolved);
1885
+ if (resolved) out.push({ identifier, ...resolved });
1837
1886
  }
1838
1887
  this.debug(`${src.name}: ${out.length} key(s)`);
1839
1888
  return out;
@@ -1848,11 +1897,8 @@ var DirectoryCache = class {
1848
1897
  if (this.opts.debug) console.log(`[WebDecoy][web-bot-auth] ${msg}`);
1849
1898
  }
1850
1899
  };
1851
- function directoryUrl(directory) {
1852
- const u = new URL(directory);
1853
- if (u.pathname && u.pathname !== "/") return u.toString();
1854
- u.pathname = WELL_KNOWN;
1855
- return u.toString();
1900
+ function cacheKey(agent, keyId) {
1901
+ return `${agent} ${keyId}`;
1856
1902
  }
1857
1903
  async function importKey(jwk, src) {
1858
1904
  try {
@@ -1922,6 +1968,14 @@ var Cursor = class {
1922
1968
  while (!this.eof() && (this.peek() === " " || this.peek() === " ")) this.i++;
1923
1969
  }
1924
1970
  };
1971
+ function parseBareString(input) {
1972
+ const p = new Cursor(input);
1973
+ p.skipSP();
1974
+ const value = parseString(p);
1975
+ p.skipSP();
1976
+ if (!p.eof()) throw new Error("trailing data after string");
1977
+ return value;
1978
+ }
1925
1979
  function parseDictionary(input) {
1926
1980
  const p = new Cursor(input);
1927
1981
  const out = [];
@@ -2089,7 +2143,14 @@ async function verifyWebBotAuth(req, resolveKey, toleranceSec) {
2089
2143
  const keyid = m.params.get("keyid");
2090
2144
  if (typeof keyid !== "string") continue;
2091
2145
  if (!m.components.some((c) => c.name === "@authority" || c.name === "@target-uri")) continue;
2092
- const key = await resolveKey(keyid);
2146
+ let agent;
2147
+ try {
2148
+ agent = coveredSignatureAgent(req, m);
2149
+ } catch {
2150
+ best = higher(best, { outcome: "claimed", keyId: keyid, reason: "unbound-agent" });
2151
+ continue;
2152
+ }
2153
+ const key = await resolveKey(keyid, agent);
2093
2154
  if (!key) {
2094
2155
  best = higher(best, { outcome: "claimed", keyId: keyid, reason: "unknown-key" });
2095
2156
  continue;
@@ -2162,11 +2223,11 @@ function componentValue(req, c) {
2162
2223
  case "@method":
2163
2224
  return req.method.toUpperCase();
2164
2225
  case "@authority":
2165
- return canonicalAuthority(req.url);
2226
+ return canonicalAuthority2(req.url);
2166
2227
  case "@scheme":
2167
2228
  return req.url.protocol.replace(/:$/, "").toLowerCase();
2168
2229
  case "@target-uri":
2169
- return `${req.url.protocol}//${canonicalAuthority(req.url)}${req.url.pathname}${req.url.search}`;
2230
+ return `${req.url.protocol}//${canonicalAuthority2(req.url)}${req.url.pathname}${req.url.search}`;
2170
2231
  case "@path":
2171
2232
  return req.url.pathname;
2172
2233
  case "@query":
@@ -2185,7 +2246,7 @@ function componentValue(req, c) {
2185
2246
  }
2186
2247
  }
2187
2248
  }
2188
- function canonicalAuthority(url) {
2249
+ function canonicalAuthority2(url) {
2189
2250
  const host = url.hostname.toLowerCase();
2190
2251
  const port = url.port;
2191
2252
  if (!port) return host;
@@ -2200,6 +2261,28 @@ function dictMemberValue(header2, key) {
2200
2261
  if (!found) throw new Error(`signature-agent has no member ${key}`);
2201
2262
  return found.raw;
2202
2263
  }
2264
+ function coveredSignatureAgent(req, m) {
2265
+ const header2 = req.headers.get("signature-agent");
2266
+ if (header2 === null) throw new Error("missing signature-agent");
2267
+ const component = m.components.find((c) => c.name.toLowerCase() === "signature-agent");
2268
+ if (!component) throw new Error("signature-agent is not covered");
2269
+ const trimmed = header2.trim();
2270
+ let value;
2271
+ if (trimmed.startsWith('"')) {
2272
+ if (component.keyParam !== void 0) throw new Error("legacy string cannot select a member");
2273
+ value = parseBareString(trimmed);
2274
+ } else {
2275
+ if (component.keyParam === void 0) throw new Error("dictionary member is not covered");
2276
+ const member = parseDictionary(trimmed).find((d) => d.key === component.keyParam);
2277
+ const item = member?.items[0];
2278
+ if (!member || member.isList || member.items.length !== 1 || typeof item?.value !== "string") {
2279
+ throw new Error("signature-agent member is not a string");
2280
+ }
2281
+ if (item.params.size > 0) throw new Error("signature-agent member carries parameters");
2282
+ value = item.value;
2283
+ }
2284
+ return resolveSignatureAgent(value).identifier;
2285
+ }
2203
2286
  function parseSignatureInput(value) {
2204
2287
  return parseDictionary(value).map((d) => {
2205
2288
  if (!d.isList) throw new Error(`Signature-Input member ${d.key} is not an inner list`);