@profullstack/x402-gateway 0.2.1 → 0.2.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/edge.js +12 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@profullstack/x402-gateway",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "description": "Sell crawl access to AI training crawlers by the day over x402, settled by CoinPay. One middleware: 402 with an offer, a sales page with CLI instructions, signed passes, and a robots.txt that keeps search crawlers welcome.",
6
6
  "keywords": [
package/src/edge.js CHANGED
@@ -84,6 +84,17 @@ export function clientIp(request) {
84
84
 
85
85
  const CLAIMS_CHROMIUM = /\bChrome\/\d+/;
86
86
 
87
+ /**
88
+ * A crawler that says so. Googlebot's evergreen string is
89
+ * "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible;
90
+ * Googlebot/2.1; +http://www.google.com/bot.html) Chrome/W.X.Y.Z Safari/537.36"
91
+ * -- it claims Chrome, it sends no Sec-Fetch-Mode, and it is the last thing
92
+ * on earth to charge. Bingbot is built the same way. Anything that declares
93
+ * itself is judged by the lists, never by this check: the whole point of the
94
+ * check is the client that declares nothing.
95
+ */
96
+ const DECLARES_ITSELF = /compatible;|\bbot\b|bot\/|crawler|spider|slurp/i;
97
+
87
98
  /**
88
99
  * A request that claims a Chromium user agent but carries none of the
89
100
  * fetch-metadata headers Chromium cannot omit.
@@ -97,5 +108,6 @@ const CLAIMS_CHROMIUM = /\bChrome\/\d+/;
97
108
  export function isSpoofedBrowser(request) {
98
109
  const ua = request.headers.get('user-agent') ?? '';
99
110
  if (!CLAIMS_CHROMIUM.test(ua)) return false;
111
+ if (DECLARES_ITSELF.test(ua)) return false;
100
112
  return !request.headers.has('sec-fetch-mode');
101
113
  }