aicrawlers 1.0.0 → 1.1.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/CHANGELOG.md +10 -0
- package/README.md +249 -51
- package/dist/chunk-UCVDZUSO.js +150 -0
- package/dist/cli.js +345 -28
- package/dist/crawlers-eCgm_1OB.d.cts +30 -0
- package/dist/crawlers-eCgm_1OB.d.ts +30 -0
- package/dist/index.cjs +146 -20
- package/dist/index.d.cts +27 -28
- package/dist/index.d.ts +27 -28
- package/dist/index.js +88 -91
- package/dist/verify.cjs +349 -0
- package/dist/verify.d.cts +55 -0
- package/dist/verify.d.ts +55 -0
- package/dist/verify.js +184 -0
- package/package.json +32 -5
package/dist/cli.js
CHANGED
|
@@ -7,12 +7,16 @@ var LIST = [
|
|
|
7
7
|
{ name: "GPTBot", operator: "OpenAI", purpose: "training", ipRanges: "https://openai.com/gptbot.json" },
|
|
8
8
|
{ name: "OAI-SearchBot", operator: "OpenAI", purpose: "search", ipRanges: "https://openai.com/searchbot.json" },
|
|
9
9
|
{ name: "ChatGPT-User", operator: "OpenAI", purpose: "user", ipRanges: "https://openai.com/chatgpt-user.json" },
|
|
10
|
+
{ name: "ChatGPT Agent", operator: "OpenAI", purpose: "user" },
|
|
11
|
+
{ name: "OAI-AdsBot", operator: "OpenAI", purpose: "other" },
|
|
10
12
|
// Anthropic
|
|
11
13
|
{ name: "ClaudeBot", operator: "Anthropic", purpose: "training" },
|
|
12
14
|
{ name: "Claude-SearchBot", operator: "Anthropic", purpose: "search" },
|
|
13
15
|
{ name: "Claude-User", operator: "Anthropic", purpose: "user" },
|
|
14
16
|
{ name: "Claude-Web", operator: "Anthropic", purpose: "other" },
|
|
15
17
|
{ name: "anthropic-ai", operator: "Anthropic", purpose: "training" },
|
|
18
|
+
{ name: "Claude-Code", operator: "Anthropic", purpose: "user" },
|
|
19
|
+
{ name: "Claude-Agent", operator: "Anthropic", purpose: "user" },
|
|
16
20
|
// Perplexity
|
|
17
21
|
{ name: "PerplexityBot", operator: "Perplexity", purpose: "search", ipRanges: "https://www.perplexity.com/perplexitybot.json" },
|
|
18
22
|
{ name: "Perplexity-User", operator: "Perplexity", purpose: "user", ipRanges: "https://www.perplexity.com/perplexity-user.json" },
|
|
@@ -20,6 +24,12 @@ var LIST = [
|
|
|
20
24
|
{ name: "Google-Extended", operator: "Google", purpose: "training", robotsOnly: true },
|
|
21
25
|
{ name: "Google-CloudVertexBot", operator: "Google", purpose: "other", rdns: GOOGLE_RDNS },
|
|
22
26
|
{ name: "GoogleOther", operator: "Google", purpose: "other", rdns: GOOGLE_RDNS },
|
|
27
|
+
{ name: "GoogleOther-Image", operator: "Google", purpose: "other", rdns: GOOGLE_RDNS },
|
|
28
|
+
{ name: "GoogleOther-Video", operator: "Google", purpose: "other", rdns: GOOGLE_RDNS },
|
|
29
|
+
{ name: "Gemini-Deep-Research", operator: "Google", purpose: "user" },
|
|
30
|
+
{ name: "Google-NotebookLM", operator: "Google", purpose: "user" },
|
|
31
|
+
{ name: "GoogleAgent-Mariner", operator: "Google", purpose: "user" },
|
|
32
|
+
{ name: "Google-Agent", operator: "Google", purpose: "user" },
|
|
23
33
|
// Apple
|
|
24
34
|
{ name: "Applebot", operator: "Apple", purpose: "search", rdns: ["applebot.apple.com"] },
|
|
25
35
|
{ name: "Applebot-Extended", operator: "Apple", purpose: "training", robotsOnly: true },
|
|
@@ -27,17 +37,53 @@ var LIST = [
|
|
|
27
37
|
{ name: "Meta-ExternalAgent", operator: "Meta", purpose: "training" },
|
|
28
38
|
{ name: "Meta-ExternalFetcher", operator: "Meta", purpose: "user" },
|
|
29
39
|
{ name: "FacebookBot", operator: "Meta", purpose: "training" },
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
{ name: "meta-webindexer", operator: "Meta", purpose: "search" },
|
|
41
|
+
// Amazon
|
|
42
|
+
{ name: "Amazonbot", operator: "Amazon", purpose: "search", rdns: ["crawl.amazonbot.amazon"] },
|
|
43
|
+
{ name: "Amzn-SearchBot", operator: "Amazon", purpose: "search" },
|
|
44
|
+
{ name: "Amzn-User", operator: "Amazon", purpose: "user" },
|
|
45
|
+
{ name: "NovaAct", operator: "Amazon", purpose: "user" },
|
|
46
|
+
{ name: "bedrockbot", operator: "Amazon", purpose: "other" },
|
|
47
|
+
// Microsoft
|
|
48
|
+
{ name: "AzureAI-SearchBot", operator: "Microsoft", purpose: "search" },
|
|
49
|
+
// Mistral
|
|
50
|
+
{ name: "MistralAI-Training", operator: "Mistral", purpose: "training" },
|
|
51
|
+
{ name: "MistralAI-Index", operator: "Mistral", purpose: "search" },
|
|
52
|
+
{ name: "MistralAI-User", operator: "Mistral", purpose: "user" },
|
|
53
|
+
// xAI
|
|
54
|
+
{ name: "xAI-Grok", operator: "xAI", purpose: "training" },
|
|
55
|
+
{ name: "GrokBot", operator: "xAI", purpose: "other" },
|
|
56
|
+
// ByteDance
|
|
32
57
|
{ name: "Bytespider", operator: "ByteDance", purpose: "training" },
|
|
58
|
+
{ name: "TikTokSpider", operator: "ByteDance", purpose: "training" },
|
|
59
|
+
{ name: "DoubaoBot", operator: "ByteDance", purpose: "other" },
|
|
60
|
+
// Other AI companies
|
|
61
|
+
{ name: "DeepSeekBot", operator: "DeepSeek", purpose: "training" },
|
|
62
|
+
{ name: "QwenBot", operator: "Alibaba", purpose: "training" },
|
|
63
|
+
{ name: "KimiBot", operator: "Moonshot AI", purpose: "training" },
|
|
64
|
+
{ name: "MoonshotBot", operator: "Moonshot AI", purpose: "training" },
|
|
65
|
+
{ name: "Kimi-SearchBot", operator: "Moonshot AI", purpose: "search" },
|
|
66
|
+
{ name: "Kimi-User", operator: "Moonshot AI", purpose: "user" },
|
|
67
|
+
{ name: "TongyiBot", operator: "Alibaba", purpose: "user" },
|
|
68
|
+
{ name: "Hunyuan", operator: "Tencent", purpose: "training" },
|
|
69
|
+
{ name: "ERNIEBot", operator: "Baidu", purpose: "training" },
|
|
70
|
+
{ name: "YiyanBot", operator: "Baidu", purpose: "user" },
|
|
71
|
+
{ name: "YiBot", operator: "01.AI", purpose: "training" },
|
|
33
72
|
{ name: "CCBot", operator: "Common Crawl", purpose: "training" },
|
|
34
73
|
{ name: "DuckAssistBot", operator: "DuckDuckGo", purpose: "search" },
|
|
35
|
-
{ name: "MistralAI-User", operator: "Mistral", purpose: "user" },
|
|
36
74
|
{ name: "cohere-training-data-crawler", operator: "Cohere", purpose: "training" },
|
|
37
75
|
{ name: "cohere-ai", operator: "Cohere", purpose: "other" },
|
|
38
76
|
{ name: "AI2Bot", operator: "Allen Institute for AI", purpose: "training" },
|
|
39
77
|
{ name: "Ai2Bot-Dolma", operator: "Allen Institute for AI", purpose: "training" },
|
|
40
78
|
{ name: "PanguBot", operator: "Huawei", purpose: "training" },
|
|
79
|
+
{ name: "PetalBot", operator: "Huawei", purpose: "search" },
|
|
80
|
+
{ name: "YandexAdditional", operator: "Yandex", purpose: "other", match: ["yandexadditionalbot"] },
|
|
81
|
+
{ name: "Bravebot", operator: "Brave", purpose: "search" },
|
|
82
|
+
{ name: "kagi-fetcher", operator: "Kagi", purpose: "user" },
|
|
83
|
+
{ name: "ExaBot", operator: "Exa", purpose: "search" },
|
|
84
|
+
{ name: "TavilyBot", operator: "Tavily", purpose: "search" },
|
|
85
|
+
{ name: "LinerBot", operator: "Liner", purpose: "other" },
|
|
86
|
+
{ name: "Manus-User", operator: "Manus", purpose: "user" },
|
|
41
87
|
{ name: "Diffbot", operator: "Diffbot", purpose: "training" },
|
|
42
88
|
{ name: "YouBot", operator: "You.com", purpose: "search" },
|
|
43
89
|
{ name: "PhindBot", operator: "Phind", purpose: "search" },
|
|
@@ -47,22 +93,30 @@ var LIST = [
|
|
|
47
93
|
{ name: "Kangaroo Bot", operator: "Kangaroo LLM", purpose: "training" },
|
|
48
94
|
{ name: "img2dataset", operator: "img2dataset", purpose: "training" },
|
|
49
95
|
{ name: "FirecrawlAgent", operator: "Firecrawl", purpose: "other" },
|
|
96
|
+
{ name: "Crawl4AI", operator: "Crawl4AI (open source)", purpose: "other" },
|
|
97
|
+
{ name: "Brightbot", operator: "Bright Data", purpose: "other" },
|
|
98
|
+
{ name: "Cloudflare-AutoRAG", operator: "Cloudflare", purpose: "search" },
|
|
99
|
+
{ name: "LAIONDownloader", operator: "LAION", purpose: "training" },
|
|
100
|
+
{ name: "SemrushBot-OCOB", operator: "Semrush", purpose: "other" },
|
|
101
|
+
{ name: "Cotoyogi", operator: "ROIS (Japan)", purpose: "training" },
|
|
102
|
+
{ name: "ICC-Crawler", operator: "NICT (Japan)", purpose: "training" },
|
|
50
103
|
{ name: "omgili", operator: "Webz.io", purpose: "training", match: ["omgilibot"] },
|
|
51
104
|
{ name: "Webzio-Extended", operator: "Webz.io", purpose: "training", robotsOnly: true }
|
|
52
105
|
];
|
|
106
|
+
var listUpdated = "2026-12-01";
|
|
53
107
|
var aiCrawlers = Object.freeze(LIST.map((c) => Object.freeze(c)));
|
|
54
108
|
var PURPOSES = ["training", "search", "user", "other"];
|
|
55
109
|
function isPurpose(value) {
|
|
56
110
|
return PURPOSES.includes(value);
|
|
57
111
|
}
|
|
58
112
|
|
|
59
|
-
// src/
|
|
60
|
-
var version = true ? "1.
|
|
61
|
-
var
|
|
113
|
+
// src/match.ts
|
|
114
|
+
var version = true ? "1.1.0" : "0.0.0-dev";
|
|
115
|
+
var escapeRegex = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
62
116
|
var tokensOf = (c) => [c.name.toLowerCase(), ...c.match ?? []];
|
|
63
117
|
var BY_TOKEN = /* @__PURE__ */ new Map();
|
|
64
118
|
for (const c of aiCrawlers) if (!c.robotsOnly) for (const t of tokensOf(c)) BY_TOKEN.set(t, c);
|
|
65
|
-
var ALTERNATION = [...BY_TOKEN.keys()].sort((a, b) => b.length - a.length).map(
|
|
119
|
+
var ALTERNATION = [...BY_TOKEN.keys()].sort((a, b) => b.length - a.length).map(escapeRegex).join("|");
|
|
66
120
|
var aiCrawlerPattern = new RegExp(`(?<![a-z0-9])(?:${ALTERNATION})(?![a-z0-9])`, "i");
|
|
67
121
|
function purposeFilter(purpose) {
|
|
68
122
|
if (purpose === void 0) return () => true;
|
|
@@ -74,51 +128,299 @@ function getAiCrawler(userAgent, options = {}) {
|
|
|
74
128
|
if (!userAgent) return void 0;
|
|
75
129
|
const found = aiCrawlerPattern.exec(userAgent);
|
|
76
130
|
const crawler = found ? BY_TOKEN.get(found[0].toLowerCase()) : void 0;
|
|
77
|
-
|
|
131
|
+
if (!crawler || !purposeFilter(options.purpose)(crawler)) return void 0;
|
|
132
|
+
if (options.allow?.some((n) => n.toLowerCase() === crawler.name.toLowerCase())) return void 0;
|
|
133
|
+
return crawler;
|
|
78
134
|
}
|
|
135
|
+
|
|
136
|
+
// src/rules.ts
|
|
79
137
|
function blockedCrawlers(options = {}) {
|
|
80
138
|
const block = options.block ?? ["training"];
|
|
81
139
|
const inPurpose = block === "all" ? () => true : purposeFilter(block);
|
|
82
140
|
const allow = new Set((options.allow ?? []).map((n) => n.toLowerCase()));
|
|
83
141
|
return aiCrawlers.filter((c) => inPurpose(c) && !allow.has(c.name.toLowerCase()));
|
|
84
142
|
}
|
|
85
|
-
function
|
|
143
|
+
function header(options, comment = "#") {
|
|
86
144
|
const block = options.block ?? ["training"];
|
|
87
145
|
const what = block === "all" ? "all AI crawlers" : block.length ? block.join(", ") : "nothing";
|
|
88
146
|
const allowed = options.allow?.length ? ` \xB7 Allowed anyway: ${options.allow.join(", ")}` : "";
|
|
89
|
-
return
|
|
147
|
+
return `${comment} AI crawler rules, generated by aicrawlers ${version}
|
|
148
|
+
${comment} Blocked: ${what}${allowed}
|
|
149
|
+
`;
|
|
150
|
+
}
|
|
151
|
+
function blockedTokens(options) {
|
|
152
|
+
return blockedCrawlers(options).filter((c) => !c.robotsOnly).flatMap(tokensOf).sort((a, b) => b.length - a.length);
|
|
153
|
+
}
|
|
154
|
+
function portableRegex(tokens, space) {
|
|
155
|
+
return `(^|[^a-z0-9])(${tokens.map((t) => escapeRegex(t).replace(/ /g, space)).join("|")})([^a-z0-9]|$)`;
|
|
90
156
|
}
|
|
91
157
|
function robotsTxt(options = {}) {
|
|
92
158
|
const crawlers = blockedCrawlers(options);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
`;
|
|
96
|
-
if (!crawlers.length) return head;
|
|
97
|
-
return `${head}${crawlers.map((c) => `User-agent: ${c.name}`).join("\n")}
|
|
159
|
+
if (!crawlers.length) return header(options);
|
|
160
|
+
return `${header(options)}${crawlers.map((c) => `User-agent: ${c.name}`).join("\n")}
|
|
98
161
|
Disallow: /
|
|
99
162
|
`;
|
|
100
163
|
}
|
|
101
164
|
function nginxMap(options = {}) {
|
|
102
|
-
const tokens =
|
|
103
|
-
const head = `# AI crawler rules, generated by aicrawlers ${version}
|
|
104
|
-
# ${describe(options)}
|
|
105
|
-
`;
|
|
165
|
+
const tokens = blockedTokens(options).map((t) => escapeRegex(t).replace(/ /g, "\\s"));
|
|
106
166
|
const rule = tokens.length ? ` "~*(?<![a-z0-9])(?:${tokens.join("|")})(?![a-z0-9])" 1;
|
|
107
167
|
` : "";
|
|
108
|
-
return `${
|
|
168
|
+
return `${header(options)}map $http_user_agent $ai_crawler {
|
|
109
169
|
default 0;
|
|
110
170
|
${rule}}
|
|
111
171
|
`;
|
|
112
172
|
}
|
|
173
|
+
function apacheRules(options = {}) {
|
|
174
|
+
const tokens = blockedTokens(options);
|
|
175
|
+
if (!tokens.length) return header(options);
|
|
176
|
+
return `${header(options)}<IfModule mod_rewrite.c>
|
|
177
|
+
RewriteEngine On
|
|
178
|
+
RewriteCond %{HTTP_USER_AGENT} ${portableRegex(tokens, "\\s")} [NC]
|
|
179
|
+
RewriteRule ^ - [F,L]
|
|
180
|
+
</IfModule>
|
|
181
|
+
`;
|
|
182
|
+
}
|
|
183
|
+
function caddyRules(options = {}) {
|
|
184
|
+
const tokens = blockedTokens(options);
|
|
185
|
+
if (!tokens.length) return header(options);
|
|
186
|
+
return `${header(options)}@aicrawlers header_regexp User-Agent "(?i)${portableRegex(tokens, " ")}"
|
|
187
|
+
respond @aicrawlers 403
|
|
188
|
+
`;
|
|
189
|
+
}
|
|
190
|
+
var CLOUDFLARE_MAX = 4096;
|
|
191
|
+
var cloudflareChecks = (options) => blockedTokens(options).map((t) => `(lower(http.user_agent) contains "${t.replace(/["\\]/g, "\\$&")}")`);
|
|
192
|
+
function cloudflareExpressions(options = {}) {
|
|
193
|
+
const out = [];
|
|
194
|
+
let current = "";
|
|
195
|
+
for (const check of cloudflareChecks(options)) {
|
|
196
|
+
const next = current ? `${current} or ${check}` : check;
|
|
197
|
+
if (next.length > CLOUDFLARE_MAX && current) {
|
|
198
|
+
out.push(current);
|
|
199
|
+
current = check;
|
|
200
|
+
} else current = next;
|
|
201
|
+
}
|
|
202
|
+
if (current) out.push(current);
|
|
203
|
+
return out;
|
|
204
|
+
}
|
|
205
|
+
function nextProxy(options = {}) {
|
|
206
|
+
const block = options.block ?? ["training"];
|
|
207
|
+
const opts = [];
|
|
208
|
+
if (block !== "all") opts.push(`purpose: ${JSON.stringify(block)}`);
|
|
209
|
+
if (options.allow?.length) opts.push(`allow: ${JSON.stringify(options.allow)}`);
|
|
210
|
+
const args = opts.length ? `, { ${opts.join(", ")} }` : "";
|
|
211
|
+
return `${header(options, "//")}// Save as proxy.ts in your project root (Next.js 16+). For Next.js 15 and earlier, save it
|
|
212
|
+
// as middleware.ts and rename the function to middleware. Run: npm install aicrawlers
|
|
213
|
+
import { NextResponse, type NextRequest } from "next/server";
|
|
214
|
+
import { isAiCrawler } from "aicrawlers";
|
|
215
|
+
|
|
216
|
+
export function proxy(request: NextRequest) {
|
|
217
|
+
if (isAiCrawler(request.headers.get("user-agent")${args})) {
|
|
218
|
+
return new NextResponse("Forbidden", { status: 403 });
|
|
219
|
+
}
|
|
220
|
+
return NextResponse.next();
|
|
221
|
+
}
|
|
222
|
+
`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/cidr.ts
|
|
226
|
+
function parseV4(ip) {
|
|
227
|
+
const parts = ip.split(".");
|
|
228
|
+
if (parts.length !== 4) return null;
|
|
229
|
+
let value = 0n;
|
|
230
|
+
for (const part of parts) {
|
|
231
|
+
if (!/^\d{1,3}$/.test(part) || Number(part) > 255) return null;
|
|
232
|
+
value = value << 8n | BigInt(Number(part));
|
|
233
|
+
}
|
|
234
|
+
return value;
|
|
235
|
+
}
|
|
236
|
+
function parseV6(raw) {
|
|
237
|
+
let ip = raw.toLowerCase().replace(/%.*$/, "");
|
|
238
|
+
const v4 = /(\d+\.\d+\.\d+\.\d+)$/.exec(ip);
|
|
239
|
+
if (v4) {
|
|
240
|
+
const n = parseV4(v4[1]);
|
|
241
|
+
if (n === null) return null;
|
|
242
|
+
ip = `${ip.slice(0, v4.index)}${(n >> 16n).toString(16)}:${(n & 0xffffn).toString(16)}`;
|
|
243
|
+
}
|
|
244
|
+
const halves = ip.split("::");
|
|
245
|
+
if (halves.length > 2) return null;
|
|
246
|
+
const head = halves[0] ? halves[0].split(":") : [];
|
|
247
|
+
const tail = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
|
|
248
|
+
const fill = 8 - head.length - tail.length;
|
|
249
|
+
if (halves.length === 1 ? fill !== 0 : fill < 1) return null;
|
|
250
|
+
const groups = [...head, ...Array(halves.length === 2 ? fill : 0).fill("0"), ...tail];
|
|
251
|
+
let value = 0n;
|
|
252
|
+
for (const g of groups) {
|
|
253
|
+
if (!/^[0-9a-f]{1,4}$/.test(g)) return null;
|
|
254
|
+
value = value << 16n | BigInt(parseInt(g, 16));
|
|
255
|
+
}
|
|
256
|
+
return value;
|
|
257
|
+
}
|
|
258
|
+
function parseIp(ip) {
|
|
259
|
+
const trimmed = ip.trim().replace(/^\[|\]$/g, "");
|
|
260
|
+
const v4 = parseV4(trimmed);
|
|
261
|
+
if (v4 !== null) return { v6: false, value: v4 };
|
|
262
|
+
const v6 = trimmed.includes(":") ? parseV6(trimmed) : null;
|
|
263
|
+
if (v6 === null) return null;
|
|
264
|
+
if (v6 >> 32n === 0xffffn) return { v6: false, value: v6 & 0xffffffffn };
|
|
265
|
+
return { v6: true, value: v6 };
|
|
266
|
+
}
|
|
267
|
+
function parseCidr(cidr) {
|
|
268
|
+
const [addr = "", bitsText] = cidr.trim().split("/");
|
|
269
|
+
const ip = parseIp(addr);
|
|
270
|
+
if (!ip) return null;
|
|
271
|
+
const max = ip.v6 ? 128 : 32;
|
|
272
|
+
const bits = bitsText === void 0 ? max : Number(bitsText);
|
|
273
|
+
if (!Number.isInteger(bits) || bits < 0 || bits > max) return null;
|
|
274
|
+
const shift = BigInt(max - bits);
|
|
275
|
+
return { v6: ip.v6, base: ip.value >> shift << shift, bits };
|
|
276
|
+
}
|
|
277
|
+
function inRanges(ip, ranges) {
|
|
278
|
+
const parsed = parseIp(ip);
|
|
279
|
+
if (!parsed) return false;
|
|
280
|
+
return ranges.some((r) => {
|
|
281
|
+
if (r.v6 !== parsed.v6) return false;
|
|
282
|
+
const shift = BigInt((r.v6 ? 128 : 32) - r.bits);
|
|
283
|
+
return parsed.value >> shift << shift === r.base;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// src/verify.ts
|
|
288
|
+
var DAY = 864e5;
|
|
289
|
+
var rangeCache = /* @__PURE__ */ new Map();
|
|
290
|
+
function cidrsFromJson(data) {
|
|
291
|
+
const out = [];
|
|
292
|
+
const walk = (v) => {
|
|
293
|
+
if (typeof v === "string") {
|
|
294
|
+
if (v.includes("/")) {
|
|
295
|
+
const c = parseCidr(v);
|
|
296
|
+
if (c) out.push(c);
|
|
297
|
+
}
|
|
298
|
+
} else if (Array.isArray(v)) v.forEach(walk);
|
|
299
|
+
else if (v && typeof v === "object") Object.values(v).forEach(walk);
|
|
300
|
+
};
|
|
301
|
+
walk(data);
|
|
302
|
+
return out;
|
|
303
|
+
}
|
|
304
|
+
async function download(url, options) {
|
|
305
|
+
try {
|
|
306
|
+
const res = await (options.fetch ?? fetch)(url, { signal: AbortSignal.timeout(options.timeout ?? 1e4) });
|
|
307
|
+
if (!res.ok) return void 0;
|
|
308
|
+
const ranges = cidrsFromJson(JSON.parse(await res.text()));
|
|
309
|
+
return ranges.length ? ranges : void 0;
|
|
310
|
+
} catch {
|
|
311
|
+
return void 0;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function loadRanges(url, options) {
|
|
315
|
+
const ttl = options.cacheTtl ?? DAY;
|
|
316
|
+
const hit = rangeCache.get(url);
|
|
317
|
+
if (hit && Date.now() - hit.at < ttl) return hit.ranges;
|
|
318
|
+
const ranges = download(url, options).then((r) => {
|
|
319
|
+
if (!r) rangeCache.delete(url);
|
|
320
|
+
return r;
|
|
321
|
+
});
|
|
322
|
+
rangeCache.set(url, { at: Date.now(), ranges });
|
|
323
|
+
return ranges;
|
|
324
|
+
}
|
|
325
|
+
async function nodeResolver() {
|
|
326
|
+
try {
|
|
327
|
+
const dns = await import("node:dns/promises");
|
|
328
|
+
return {
|
|
329
|
+
reverse: (ip) => dns.reverse(ip),
|
|
330
|
+
lookup: async (host) => (await dns.lookup(host, { all: true })).map((r) => r.address)
|
|
331
|
+
};
|
|
332
|
+
} catch {
|
|
333
|
+
return void 0;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function withTimeout(promise, ms) {
|
|
337
|
+
return new Promise((resolve, reject) => {
|
|
338
|
+
const timer = setTimeout(() => reject(Object.assign(new Error("timeout"), { code: "ETIMEOUT" })), ms);
|
|
339
|
+
promise.then(
|
|
340
|
+
(v) => (clearTimeout(timer), resolve(v)),
|
|
341
|
+
(e) => (clearTimeout(timer), reject(e))
|
|
342
|
+
);
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
var same = (a, b) => {
|
|
346
|
+
const x = parseIp(a);
|
|
347
|
+
const y = parseIp(b);
|
|
348
|
+
return x !== null && y !== null && x.v6 === y.v6 && x.value === y.value;
|
|
349
|
+
};
|
|
350
|
+
async function checkDns(ip, suffixes, options) {
|
|
351
|
+
const resolver = options.resolver ?? await nodeResolver();
|
|
352
|
+
if (!resolver) return { verified: null, reason: "no DNS resolver here: pass options.resolver" };
|
|
353
|
+
const ms = options.timeout ?? 1e4;
|
|
354
|
+
let hosts;
|
|
355
|
+
try {
|
|
356
|
+
hosts = await withTimeout(resolver.reverse(ip), ms);
|
|
357
|
+
} catch (error) {
|
|
358
|
+
const code = error.code;
|
|
359
|
+
return code === "ENOTFOUND" || code === "ENODATA" ? { verified: false, reason: `${ip} has no reverse DNS name` } : { verified: null, reason: `reverse DNS lookup failed (${code ?? "error"})` };
|
|
360
|
+
}
|
|
361
|
+
const host = hosts.map((h) => h.toLowerCase().replace(/\.$/, "")).find((h) => suffixes.some((s) => h === s || h.endsWith(`.${s}`)));
|
|
362
|
+
if (!host) return { verified: false, reason: `${ip} resolves to ${hosts[0] ?? "nothing"}, not ${suffixes.join(" or ")}` };
|
|
363
|
+
try {
|
|
364
|
+
const addresses = await withTimeout(resolver.lookup(host), ms);
|
|
365
|
+
return addresses.some((a) => same(a, ip)) ? { verified: true, reason: `${ip} is ${host}, which resolves back to it` } : { verified: false, reason: `${host} doesn't resolve back to ${ip}` };
|
|
366
|
+
} catch (error) {
|
|
367
|
+
return { verified: null, reason: `forward DNS lookup failed (${error.code ?? "error"})` };
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
async function verifyAiCrawler(request, options = {}) {
|
|
371
|
+
const crawler = getAiCrawler(request.userAgent);
|
|
372
|
+
if (!crawler) return { crawler, verified: null, method: null, reason: "not an AI crawler" };
|
|
373
|
+
const ip = request.ip.trim().replace(/^\[|\]$/g, "");
|
|
374
|
+
if (!parseIp(ip)) return { crawler, verified: null, method: null, reason: `"${request.ip}" is not an IP address` };
|
|
375
|
+
if (crawler.ipRanges) {
|
|
376
|
+
const ranges = await loadRanges(crawler.ipRanges, options);
|
|
377
|
+
if (!ranges) return { crawler, verified: null, method: "ip-ranges", reason: `couldn't download ${crawler.ipRanges}` };
|
|
378
|
+
const ok = inRanges(ip, ranges);
|
|
379
|
+
return {
|
|
380
|
+
crawler,
|
|
381
|
+
verified: ok,
|
|
382
|
+
method: "ip-ranges",
|
|
383
|
+
reason: ok ? `${ip} is in ${crawler.operator}'s published ranges for ${crawler.name}` : `${ip} is not in ${crawler.operator}'s published ranges for ${crawler.name}`
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
if (crawler.rdns?.length) {
|
|
387
|
+
const result = await checkDns(ip, crawler.rdns, options);
|
|
388
|
+
return { crawler, method: "rdns", ...result };
|
|
389
|
+
}
|
|
390
|
+
return { crawler, verified: null, method: null, reason: `${crawler.operator} doesn't publish a way to verify ${crawler.name}` };
|
|
391
|
+
}
|
|
113
392
|
|
|
114
393
|
// src/cli.ts
|
|
394
|
+
var GENERATORS = {
|
|
395
|
+
robots: robotsTxt,
|
|
396
|
+
nginx: nginxMap,
|
|
397
|
+
apache: apacheRules,
|
|
398
|
+
caddy: caddyRules,
|
|
399
|
+
cloudflare: (options) => {
|
|
400
|
+
const rules = cloudflareExpressions(options);
|
|
401
|
+
if (rules.length <= 1) return `${rules[0] ?? ""}
|
|
402
|
+
`;
|
|
403
|
+
return rules.map((r, i) => `# Rule ${i + 1} of ${rules.length}: create a custom rule with this expression and the Block action
|
|
404
|
+
${r}
|
|
405
|
+
`).join("\n");
|
|
406
|
+
},
|
|
407
|
+
next: nextProxy
|
|
408
|
+
};
|
|
115
409
|
var HELP = `aicrawlers ${version}: known AI crawlers, and rules to block them
|
|
410
|
+
${aiCrawlers.length} crawlers, list updated ${listUpdated}
|
|
116
411
|
|
|
117
412
|
Usage
|
|
118
|
-
aicrawlers check "<user agent>"
|
|
119
|
-
aicrawlers
|
|
120
|
-
aicrawlers
|
|
121
|
-
|
|
413
|
+
aicrawlers check "<user agent>" Is it an AI crawler? (exit code 0 yes, 1 no)
|
|
414
|
+
aicrawlers verify <ip> "<user agent>" Is it really that crawler? (0 real, 1 fake, 3 can't tell)
|
|
415
|
+
aicrawlers list [--json] Every known AI crawler
|
|
416
|
+
|
|
417
|
+
Blocking rules (take the rule options below)
|
|
418
|
+
aicrawlers robots robots.txt
|
|
419
|
+
aicrawlers nginx nginx map
|
|
420
|
+
aicrawlers apache Apache / .htaccess (mod_rewrite)
|
|
421
|
+
aicrawlers caddy Caddyfile
|
|
422
|
+
aicrawlers cloudflare Cloudflare WAF custom rule expression
|
|
423
|
+
aicrawlers next Next.js proxy.ts / middleware.ts
|
|
122
424
|
|
|
123
425
|
Rule options
|
|
124
426
|
--block <purposes> training, search, user, other, or all (default: training)
|
|
@@ -132,7 +434,9 @@ Options
|
|
|
132
434
|
|
|
133
435
|
Examples
|
|
134
436
|
npx aicrawlers robots --block training >> robots.txt
|
|
437
|
+
npx aicrawlers nginx --block all --allow OAI-SearchBot,PerplexityBot
|
|
135
438
|
npx aicrawlers check "Mozilla/5.0 (compatible; GPTBot/1.2; +https://openai.com/gptbot)"
|
|
439
|
+
npx aicrawlers verify 20.15.240.64 "GPTBot/1.2"
|
|
136
440
|
`;
|
|
137
441
|
function fail(message) {
|
|
138
442
|
process.stderr.write(`aicrawlers: ${message}
|
|
@@ -198,10 +502,23 @@ if (flags.version) {
|
|
|
198
502
|
`);
|
|
199
503
|
}
|
|
200
504
|
}
|
|
201
|
-
} else if (command === "
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
505
|
+
} else if (command === "verify") {
|
|
506
|
+
const [ip, ...ua] = rest;
|
|
507
|
+
if (!ip || !ua.length) fail("verify needs an IP and a user agent");
|
|
508
|
+
void verifyAiCrawler({ ip, userAgent: ua.join(" ") }).then((v) => {
|
|
509
|
+
if (flags.json) process.stdout.write(`${JSON.stringify(v, null, 2)}
|
|
510
|
+
`);
|
|
511
|
+
else {
|
|
512
|
+
const verdict = v.verified === true ? "Real" : v.verified === false ? "FAKE" : "Can't tell";
|
|
513
|
+
process.stdout.write(`${verdict}${v.crawler ? ` ${v.crawler.name}` : ""}: ${v.reason}
|
|
514
|
+
`);
|
|
515
|
+
}
|
|
516
|
+
process.exitCode = v.verified === true ? 0 : v.verified === false ? 1 : 3;
|
|
517
|
+
});
|
|
518
|
+
} else if (GENERATORS[command]) {
|
|
519
|
+
const options = ruleOptions(flags);
|
|
520
|
+
const out = GENERATORS[command](options);
|
|
521
|
+
process.stdout.write(out);
|
|
205
522
|
} else {
|
|
206
523
|
fail(`unknown command "${command}"`);
|
|
207
524
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type Purpose = "training" | "search" | "user" | "other";
|
|
2
|
+
interface AiCrawler {
|
|
3
|
+
/** Product token: what the crawler sends in its User-Agent and obeys in robots.txt. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Company or project that runs it. */
|
|
6
|
+
operator: string;
|
|
7
|
+
/**
|
|
8
|
+
* What it collects pages for, from the operator's documentation:
|
|
9
|
+
* - "training": data to train AI models
|
|
10
|
+
* - "search": an AI search or answer product
|
|
11
|
+
* - "user": fetches a page because a person asked an assistant about it
|
|
12
|
+
* - "other": anything else, or not documented
|
|
13
|
+
*/
|
|
14
|
+
purpose: Purpose;
|
|
15
|
+
/** Extra lowercase strings matched in the User-Agent. The name always matches. */
|
|
16
|
+
match?: string[];
|
|
17
|
+
/** Only used in robots.txt: it never appears in a User-Agent. */
|
|
18
|
+
robotsOnly?: boolean;
|
|
19
|
+
/** URL of the operator's official JSON list of IP ranges, to tell real requests from fakes. */
|
|
20
|
+
ipRanges?: string;
|
|
21
|
+
/** Reverse-DNS hostname suffixes of real requests, confirmed with a forward lookup. */
|
|
22
|
+
rdns?: string[];
|
|
23
|
+
}
|
|
24
|
+
/** The date the list was last reviewed against operators' documentation and the ai.robots.txt list. */
|
|
25
|
+
declare const listUpdated = "2026-12-01";
|
|
26
|
+
/** Known AI crawlers and fetchers. Frozen: copy it before changing anything. */
|
|
27
|
+
declare const aiCrawlers: readonly Readonly<AiCrawler>[];
|
|
28
|
+
declare const PURPOSES: readonly Purpose[];
|
|
29
|
+
|
|
30
|
+
export { type AiCrawler as A, type Purpose as P, aiCrawlers as a, PURPOSES as b, listUpdated as l };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type Purpose = "training" | "search" | "user" | "other";
|
|
2
|
+
interface AiCrawler {
|
|
3
|
+
/** Product token: what the crawler sends in its User-Agent and obeys in robots.txt. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Company or project that runs it. */
|
|
6
|
+
operator: string;
|
|
7
|
+
/**
|
|
8
|
+
* What it collects pages for, from the operator's documentation:
|
|
9
|
+
* - "training": data to train AI models
|
|
10
|
+
* - "search": an AI search or answer product
|
|
11
|
+
* - "user": fetches a page because a person asked an assistant about it
|
|
12
|
+
* - "other": anything else, or not documented
|
|
13
|
+
*/
|
|
14
|
+
purpose: Purpose;
|
|
15
|
+
/** Extra lowercase strings matched in the User-Agent. The name always matches. */
|
|
16
|
+
match?: string[];
|
|
17
|
+
/** Only used in robots.txt: it never appears in a User-Agent. */
|
|
18
|
+
robotsOnly?: boolean;
|
|
19
|
+
/** URL of the operator's official JSON list of IP ranges, to tell real requests from fakes. */
|
|
20
|
+
ipRanges?: string;
|
|
21
|
+
/** Reverse-DNS hostname suffixes of real requests, confirmed with a forward lookup. */
|
|
22
|
+
rdns?: string[];
|
|
23
|
+
}
|
|
24
|
+
/** The date the list was last reviewed against operators' documentation and the ai.robots.txt list. */
|
|
25
|
+
declare const listUpdated = "2026-12-01";
|
|
26
|
+
/** Known AI crawlers and fetchers. Frozen: copy it before changing anything. */
|
|
27
|
+
declare const aiCrawlers: readonly Readonly<AiCrawler>[];
|
|
28
|
+
declare const PURPOSES: readonly Purpose[];
|
|
29
|
+
|
|
30
|
+
export { type AiCrawler as A, type Purpose as P, aiCrawlers as a, PURPOSES as b, listUpdated as l };
|