@rebilder/agent-readability 0.4.0 → 0.5.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.
@@ -644,10 +644,9 @@ function parseStartTag(html, start) {
644
644
  }
645
645
  return { tag, attrs, selfClosing, end: i };
646
646
  }
647
- function findRawTextEnd(html, from, tag) {
647
+ function findRawTextEnd(lowerHtml, from, tag) {
648
648
  const needle = `</${tag}`;
649
- const lower = html.toLowerCase();
650
- const at = lower.indexOf(needle, from);
649
+ const at = lowerHtml.indexOf(needle, from);
651
650
  return at === -1 ? -1 : at;
652
651
  }
653
652
  function ownExclusion(tag, attrs) {
@@ -711,6 +710,7 @@ function tokenizeHtml(html) {
711
710
  };
712
711
  let i = 0;
713
712
  let textStart = 0;
713
+ let lowerHtml = null;
714
714
  while (i < html.length) {
715
715
  const lt = html.indexOf("<", i);
716
716
  if (lt === -1) break;
@@ -762,7 +762,8 @@ function tokenizeHtml(html) {
762
762
  const isRcdata = RCDATA_ELEMENTS.has(parsed.tag);
763
763
  if (isRawText || isRcdata) {
764
764
  const contentStart = i;
765
- const close = findRawTextEnd(html, contentStart, parsed.tag);
765
+ lowerHtml ??= html.toLowerCase();
766
+ const close = findRawTextEnd(lowerHtml, contentStart, parsed.tag);
766
767
  const contentEnd = close === -1 ? html.length : close;
767
768
  if (contentEnd > contentStart) {
768
769
  const wasTop = stack.length;
@@ -994,7 +995,10 @@ function parseRobots(text) {
994
995
  else current.disallow.push(value);
995
996
  continue;
996
997
  }
997
- if (field === "crawl-delay" || field === "host" || field === "clean-param") continue;
998
+ if (field === "crawl-delay" || field === "host" || field === "clean-param" || field === "content-signal") {
999
+ if (field === "content-signal" && current !== null) openingGroup = false;
1000
+ continue;
1001
+ }
998
1002
  malformedLines++;
999
1003
  }
1000
1004
  return { groups, sitemaps, malformedLines, orphanRules };
@@ -1336,6 +1340,82 @@ function markdownAlternateTarget(agent, browser, origin) {
1336
1340
  }
1337
1341
  return null;
1338
1342
  }
1343
+
1344
+ // src/site-signals.ts
1345
+ var BODY_SCAN_CHARS = 256 * 1024;
1346
+ function headerValues(input, name) {
1347
+ const direct = input.headers[name];
1348
+ if (direct !== void 0) return direct.map((value) => value.toLowerCase());
1349
+ const target = name.toLowerCase();
1350
+ const out = [];
1351
+ for (const [key, values] of Object.entries(input.headers)) {
1352
+ if (key.toLowerCase() === target) {
1353
+ for (const value of values) out.push(value.toLowerCase());
1354
+ }
1355
+ }
1356
+ return out;
1357
+ }
1358
+ function hasToken(values, token) {
1359
+ return values.some(
1360
+ (value) => value.split(",").map((part) => part.trim()).includes(token)
1361
+ );
1362
+ }
1363
+ function isRobotsTxtTarget(input) {
1364
+ for (const raw of [input.requestedUrl, input.finalUrl]) {
1365
+ if (typeof raw !== "string" || raw.length === 0) continue;
1366
+ try {
1367
+ if (new URL(raw).pathname.toLowerCase() === "/robots.txt") return true;
1368
+ } catch {
1369
+ const path = (raw.split("#")[0]?.split("?")[0] ?? "").toLowerCase();
1370
+ if (path === "/robots.txt" || path.endsWith("/robots.txt")) return true;
1371
+ }
1372
+ }
1373
+ return false;
1374
+ }
1375
+ function detectEdgeChallenge(input) {
1376
+ const status = input.status;
1377
+ const body = typeof input.body === "string" ? input.body.slice(0, BODY_SCAN_CHARS) : "";
1378
+ const server = headerValues(input, "server");
1379
+ const contentTypes = headerValues(input, "content-type");
1380
+ const isHtmlContent = contentTypes.some(
1381
+ (value) => value.includes("text/html") || value.includes("application/xhtml+xml")
1382
+ );
1383
+ const lowerBodyHead = body.slice(0, 4096).toLowerCase();
1384
+ const isPlainTextWithoutMarkup = contentTypes.some((value) => value.includes("text/plain")) && !lowerBodyHead.includes("<html") && !lowerBodyHead.includes("<script") && !lowerBodyHead.includes("<!doctype html");
1385
+ const isRobotsHtmlChallenge = isRobotsTxtTarget(input) && isHtmlContent;
1386
+ if (hasToken(headerValues(input, "cf-mitigated"), "challenge")) {
1387
+ return { vendor: "cloudflare", signal: "cf-mitigated: challenge", status };
1388
+ }
1389
+ if ((status === 403 || status === 429 || status === 503 || isRobotsHtmlChallenge && status === 200) && !isPlainTextWithoutMarkup && server.some((value) => value.includes("cloudflare")) && body.includes("/cdn-cgi/challenge-platform/")) {
1390
+ return { vendor: "cloudflare", signal: "Cloudflare challenge page", status };
1391
+ }
1392
+ if (hasToken(headerValues(input, "x-vercel-mitigated"), "challenge")) {
1393
+ return { vendor: "vercel", signal: "x-vercel-mitigated: challenge", status };
1394
+ }
1395
+ if ((status < 200 || status >= 300 || isRobotsHtmlChallenge && status === 200) && !isPlainTextWithoutMarkup && server.some((value) => value.includes("vercel")) && body.includes("Vercel Security Checkpoint")) {
1396
+ return { vendor: "vercel", signal: "Vercel Security Checkpoint page", status };
1397
+ }
1398
+ if ((status === 401 || status === 403) && headerValues(input, "x-datadome").length > 0) {
1399
+ return { vendor: "datadome", signal: `x-datadome with HTTP ${status}`, status };
1400
+ }
1401
+ if ((status === 403 || status === 429 || isRobotsHtmlChallenge && status === 200) && !isPlainTextWithoutMarkup && body.includes("px-captcha") && body.includes("_pxAppId")) {
1402
+ return { vendor: "human", signal: "HUMAN block page", status };
1403
+ }
1404
+ return null;
1405
+ }
1406
+ var DETAIL_PREFIX = "edge-challenge";
1407
+ function challengeDetail(challenge) {
1408
+ return `${DETAIL_PREFIX}; vendor=${challenge.vendor}; status=${challenge.status}; signal=${challenge.signal.slice(0, 120)}`;
1409
+ }
1410
+ new Set(
1411
+ [
1412
+ ...DEFAULT_RULESET.audienceTokens.assistant,
1413
+ ...DEFAULT_RULESET.audienceTokens.training,
1414
+ ...DEFAULT_RULESET.audienceTokens.search,
1415
+ "googlebot",
1416
+ "bingbot"
1417
+ ].map((token) => token.toLowerCase())
1418
+ );
1339
1419
  var ALLOW_PRIVATE_HOSTS = /* @__PURE__ */ Symbol("rebilder.ars.probe.allow-private-hosts");
1340
1420
  var allowsPrivateHosts = (policy) => policy === ALLOW_PRIVATE_HOSTS;
1341
1421
  var NOT_AN_IP = { family: null, reserved: false, label: "hostname" };
@@ -1429,6 +1509,9 @@ function classifyIpv6Groups(groups) {
1429
1509
  const allZeroThrough = (upTo) => groups.slice(0, upTo).every((x) => x === 0);
1430
1510
  if (groups.every((x) => x === 0)) return v6("unspecified (::)", true);
1431
1511
  if (allZeroThrough(7) && g(7) === 1) return v6("loopback (::1)", true);
1512
+ if (allZeroThrough(4) && g(4) === 65535 && g(5) === 0) {
1513
+ return v6("IPv4-translated (::ffff:0:0:0/96)", true);
1514
+ }
1432
1515
  if (allZeroThrough(5) && g(5) === 65535) {
1433
1516
  const inner = classifyIpv4Octets(embeddedV4(g(6), g(7)));
1434
1517
  return v6(`IPv4-mapped \u2192 ${inner.label}`, inner.reserved);
@@ -1437,10 +1520,16 @@ function classifyIpv6Groups(groups) {
1437
1520
  const inner = classifyIpv4Octets(embeddedV4(g(6), g(7)));
1438
1521
  return v6(`IPv4-compatible \u2192 ${inner.label}`, true);
1439
1522
  }
1523
+ if (g(0) === 100 && g(1) === 65435 && g(2) === 1) {
1524
+ return v6("NAT64 local-use (64:ff9b:1::/48)", true);
1525
+ }
1440
1526
  if (g(0) === 100 && g(1) === 65435 && g(2) === 0 && g(3) === 0 && g(4) === 0 && g(5) === 0) {
1441
1527
  const inner = classifyIpv4Octets(embeddedV4(g(6), g(7)));
1442
1528
  return v6(`NAT64 64:ff9b::/96 \u2192 ${inner.label}`, inner.reserved);
1443
1529
  }
1530
+ if (g(0) === 8193 && g(1) === 0) {
1531
+ return v6("Teredo (2001::/32)", true);
1532
+ }
1444
1533
  if (g(0) === 8194) {
1445
1534
  const inner = classifyIpv4Octets(embeddedV4(g(1), g(2)));
1446
1535
  return v6(`6to4 2002::/16 \u2192 ${inner.label}`, inner.reserved);
@@ -1450,6 +1539,7 @@ function classifyIpv6Groups(groups) {
1450
1539
  if (g(0) === 8193 && g(1) === 3512) return v6("documentation (2001:db8::/32)", true);
1451
1540
  if ((g(0) & 65024) === 64512) return v6("unique local (fc00::/7)", true);
1452
1541
  if ((g(0) & 65472) === 65152) return v6("link-local (fe80::/10)", true);
1542
+ if ((g(0) & 65472) === 65216) return v6("site-local (fec0::/10)", true);
1453
1543
  if ((g(0) & 65280) === 65280) return v6("multicast (ff00::/8)", true);
1454
1544
  return v6("public", false);
1455
1545
  }
@@ -1492,8 +1582,10 @@ function guardUrl(input, policy) {
1492
1582
  if (url.username !== "" || url.password !== "") {
1493
1583
  return { ok: false, reason: "URLs with embedded credentials cannot be fetched." };
1494
1584
  }
1495
- let hostname = url.hostname.toLowerCase();
1496
- if (hostname.endsWith(".") && hostname.length > 1) hostname = hostname.slice(0, -1);
1585
+ const hostname = url.hostname.toLowerCase().replace(/\.+$/, "");
1586
+ if (hostname === "") {
1587
+ return { ok: false, reason: "That URL has no hostname." };
1588
+ }
1497
1589
  const permissive = allowsPrivateHosts(policy.hostPolicy);
1498
1590
  if (!permissive && (hostname === "localhost" || hostname.endsWith(".localhost"))) {
1499
1591
  return { ok: false, reason: "localhost cannot be fetched." };
@@ -2077,6 +2169,16 @@ async function probeWithHostPolicy(target, policy, hostPolicy, options = {}) {
2077
2169
  };
2078
2170
  }
2079
2171
  };
2172
+ const runPage = async (href, headers) => {
2173
+ const record = await run(href, headers);
2174
+ if (!record.result.ok) return record;
2175
+ const challenge = detectEdgeChallenge(record.result.capture);
2176
+ if (challenge === null) return record;
2177
+ return {
2178
+ requestHeaders: headers,
2179
+ result: { ok: false, error: "challenge", detail: challengeDetail(challenge) }
2180
+ };
2181
+ };
2080
2182
  const evidenceOf = (probes) => ({
2081
2183
  ok: true,
2082
2184
  evidence: {
@@ -2121,8 +2223,8 @@ async function probeWithHostPolicy(target, policy, hostPolicy, options = {}) {
2121
2223
  wellKnownUcp: null
2122
2224
  });
2123
2225
  }
2124
- const agent = await run(url.toString(), agentHeaders);
2125
- const browser = await run(url.toString(), browserHeaders);
2226
+ const agent = await runPage(url.toString(), agentHeaders);
2227
+ const browser = await runPage(url.toString(), browserHeaders);
2126
2228
  const linked = markdownAlternateTarget(
2127
2229
  agent.result.ok ? agent.result.capture : null,
2128
2230
  browser.result.ok ? browser.result.capture : null,
@@ -2131,7 +2233,7 @@ async function probeWithHostPolicy(target, policy, hostPolicy, options = {}) {
2131
2233
  let markdownAlternate = null;
2132
2234
  if (linked !== null) {
2133
2235
  const rule = disallowedFor(new URL(linked).pathname);
2134
- markdownAlternate = rule !== null ? skipped(agentHeaders, `robots.txt disallows ${ARS_ROBOTS_TOKEN} for ${linked}`) : await run(linked, agentHeaders);
2236
+ markdownAlternate = rule !== null ? skipped(agentHeaders, `robots.txt disallows ${ARS_ROBOTS_TOKEN} for ${linked}`) : await runPage(linked, agentHeaders);
2135
2237
  }
2136
2238
  const fetchAsset = async (path) => {
2137
2239
  const rule = disallowedFor(path);
@@ -1,5 +1,5 @@
1
- import { F as ArsVantage, f as ArsEvidence, c as ArsRuleset } from '../robots-policy-BeffrTf0.cjs';
2
- export { j as AGENT_ACCEPT, k as ARS_ROBOTS_TOKEN, m as ASSET_ACCEPT, G as BROWSER_ACCEPT } from '../robots-policy-BeffrTf0.cjs';
1
+ import { F as ArsVantage, f as ArsEvidence, c as ArsRuleset } from '../robots-policy-C7cfPpu2.cjs';
2
+ export { l as AGENT_ACCEPT, m as ARS_ROBOTS_TOKEN, o as ASSET_ACCEPT, G as BROWSER_ACCEPT } from '../robots-policy-C7cfPpu2.cjs';
3
3
 
4
4
  /**
5
5
  * probe/ssrf.ts — the network-side host policy for `@rebilder/agent-readability`.
@@ -1,5 +1,5 @@
1
- import { F as ArsVantage, f as ArsEvidence, c as ArsRuleset } from '../robots-policy-BeffrTf0.js';
2
- export { j as AGENT_ACCEPT, k as ARS_ROBOTS_TOKEN, m as ASSET_ACCEPT, G as BROWSER_ACCEPT } from '../robots-policy-BeffrTf0.js';
1
+ import { F as ArsVantage, f as ArsEvidence, c as ArsRuleset } from '../robots-policy-C7cfPpu2.js';
2
+ export { l as AGENT_ACCEPT, m as ARS_ROBOTS_TOKEN, o as ASSET_ACCEPT, G as BROWSER_ACCEPT } from '../robots-policy-C7cfPpu2.js';
3
3
 
4
4
  /**
5
5
  * probe/ssrf.ts — the network-side host policy for `@rebilder/agent-readability`.
@@ -621,10 +621,9 @@ function parseStartTag(html, start) {
621
621
  }
622
622
  return { tag, attrs, selfClosing, end: i };
623
623
  }
624
- function findRawTextEnd(html, from, tag) {
624
+ function findRawTextEnd(lowerHtml, from, tag) {
625
625
  const needle = `</${tag}`;
626
- const lower = html.toLowerCase();
627
- const at = lower.indexOf(needle, from);
626
+ const at = lowerHtml.indexOf(needle, from);
628
627
  return at === -1 ? -1 : at;
629
628
  }
630
629
  function ownExclusion(tag, attrs) {
@@ -688,6 +687,7 @@ function tokenizeHtml(html) {
688
687
  };
689
688
  let i = 0;
690
689
  let textStart = 0;
690
+ let lowerHtml = null;
691
691
  while (i < html.length) {
692
692
  const lt = html.indexOf("<", i);
693
693
  if (lt === -1) break;
@@ -739,7 +739,8 @@ function tokenizeHtml(html) {
739
739
  const isRcdata = RCDATA_ELEMENTS.has(parsed.tag);
740
740
  if (isRawText || isRcdata) {
741
741
  const contentStart = i;
742
- const close = findRawTextEnd(html, contentStart, parsed.tag);
742
+ lowerHtml ??= html.toLowerCase();
743
+ const close = findRawTextEnd(lowerHtml, contentStart, parsed.tag);
743
744
  const contentEnd = close === -1 ? html.length : close;
744
745
  if (contentEnd > contentStart) {
745
746
  const wasTop = stack.length;
@@ -971,7 +972,10 @@ function parseRobots(text) {
971
972
  else current.disallow.push(value);
972
973
  continue;
973
974
  }
974
- if (field === "crawl-delay" || field === "host" || field === "clean-param") continue;
975
+ if (field === "crawl-delay" || field === "host" || field === "clean-param" || field === "content-signal") {
976
+ if (field === "content-signal" && current !== null) openingGroup = false;
977
+ continue;
978
+ }
975
979
  malformedLines++;
976
980
  }
977
981
  return { groups, sitemaps, malformedLines, orphanRules };
@@ -1313,6 +1317,82 @@ function markdownAlternateTarget(agent, browser, origin) {
1313
1317
  }
1314
1318
  return null;
1315
1319
  }
1320
+
1321
+ // src/site-signals.ts
1322
+ var BODY_SCAN_CHARS = 256 * 1024;
1323
+ function headerValues(input, name) {
1324
+ const direct = input.headers[name];
1325
+ if (direct !== void 0) return direct.map((value) => value.toLowerCase());
1326
+ const target = name.toLowerCase();
1327
+ const out = [];
1328
+ for (const [key, values] of Object.entries(input.headers)) {
1329
+ if (key.toLowerCase() === target) {
1330
+ for (const value of values) out.push(value.toLowerCase());
1331
+ }
1332
+ }
1333
+ return out;
1334
+ }
1335
+ function hasToken(values, token) {
1336
+ return values.some(
1337
+ (value) => value.split(",").map((part) => part.trim()).includes(token)
1338
+ );
1339
+ }
1340
+ function isRobotsTxtTarget(input) {
1341
+ for (const raw of [input.requestedUrl, input.finalUrl]) {
1342
+ if (typeof raw !== "string" || raw.length === 0) continue;
1343
+ try {
1344
+ if (new URL(raw).pathname.toLowerCase() === "/robots.txt") return true;
1345
+ } catch {
1346
+ const path = (raw.split("#")[0]?.split("?")[0] ?? "").toLowerCase();
1347
+ if (path === "/robots.txt" || path.endsWith("/robots.txt")) return true;
1348
+ }
1349
+ }
1350
+ return false;
1351
+ }
1352
+ function detectEdgeChallenge(input) {
1353
+ const status = input.status;
1354
+ const body = typeof input.body === "string" ? input.body.slice(0, BODY_SCAN_CHARS) : "";
1355
+ const server = headerValues(input, "server");
1356
+ const contentTypes = headerValues(input, "content-type");
1357
+ const isHtmlContent = contentTypes.some(
1358
+ (value) => value.includes("text/html") || value.includes("application/xhtml+xml")
1359
+ );
1360
+ const lowerBodyHead = body.slice(0, 4096).toLowerCase();
1361
+ const isPlainTextWithoutMarkup = contentTypes.some((value) => value.includes("text/plain")) && !lowerBodyHead.includes("<html") && !lowerBodyHead.includes("<script") && !lowerBodyHead.includes("<!doctype html");
1362
+ const isRobotsHtmlChallenge = isRobotsTxtTarget(input) && isHtmlContent;
1363
+ if (hasToken(headerValues(input, "cf-mitigated"), "challenge")) {
1364
+ return { vendor: "cloudflare", signal: "cf-mitigated: challenge", status };
1365
+ }
1366
+ if ((status === 403 || status === 429 || status === 503 || isRobotsHtmlChallenge && status === 200) && !isPlainTextWithoutMarkup && server.some((value) => value.includes("cloudflare")) && body.includes("/cdn-cgi/challenge-platform/")) {
1367
+ return { vendor: "cloudflare", signal: "Cloudflare challenge page", status };
1368
+ }
1369
+ if (hasToken(headerValues(input, "x-vercel-mitigated"), "challenge")) {
1370
+ return { vendor: "vercel", signal: "x-vercel-mitigated: challenge", status };
1371
+ }
1372
+ if ((status < 200 || status >= 300 || isRobotsHtmlChallenge && status === 200) && !isPlainTextWithoutMarkup && server.some((value) => value.includes("vercel")) && body.includes("Vercel Security Checkpoint")) {
1373
+ return { vendor: "vercel", signal: "Vercel Security Checkpoint page", status };
1374
+ }
1375
+ if ((status === 401 || status === 403) && headerValues(input, "x-datadome").length > 0) {
1376
+ return { vendor: "datadome", signal: `x-datadome with HTTP ${status}`, status };
1377
+ }
1378
+ if ((status === 403 || status === 429 || isRobotsHtmlChallenge && status === 200) && !isPlainTextWithoutMarkup && body.includes("px-captcha") && body.includes("_pxAppId")) {
1379
+ return { vendor: "human", signal: "HUMAN block page", status };
1380
+ }
1381
+ return null;
1382
+ }
1383
+ var DETAIL_PREFIX = "edge-challenge";
1384
+ function challengeDetail(challenge) {
1385
+ return `${DETAIL_PREFIX}; vendor=${challenge.vendor}; status=${challenge.status}; signal=${challenge.signal.slice(0, 120)}`;
1386
+ }
1387
+ new Set(
1388
+ [
1389
+ ...DEFAULT_RULESET.audienceTokens.assistant,
1390
+ ...DEFAULT_RULESET.audienceTokens.training,
1391
+ ...DEFAULT_RULESET.audienceTokens.search,
1392
+ "googlebot",
1393
+ "bingbot"
1394
+ ].map((token) => token.toLowerCase())
1395
+ );
1316
1396
  var ALLOW_PRIVATE_HOSTS = /* @__PURE__ */ Symbol("rebilder.ars.probe.allow-private-hosts");
1317
1397
  var allowsPrivateHosts = (policy) => policy === ALLOW_PRIVATE_HOSTS;
1318
1398
  var NOT_AN_IP = { family: null, reserved: false, label: "hostname" };
@@ -1406,6 +1486,9 @@ function classifyIpv6Groups(groups) {
1406
1486
  const allZeroThrough = (upTo) => groups.slice(0, upTo).every((x) => x === 0);
1407
1487
  if (groups.every((x) => x === 0)) return v6("unspecified (::)", true);
1408
1488
  if (allZeroThrough(7) && g(7) === 1) return v6("loopback (::1)", true);
1489
+ if (allZeroThrough(4) && g(4) === 65535 && g(5) === 0) {
1490
+ return v6("IPv4-translated (::ffff:0:0:0/96)", true);
1491
+ }
1409
1492
  if (allZeroThrough(5) && g(5) === 65535) {
1410
1493
  const inner = classifyIpv4Octets(embeddedV4(g(6), g(7)));
1411
1494
  return v6(`IPv4-mapped \u2192 ${inner.label}`, inner.reserved);
@@ -1414,10 +1497,16 @@ function classifyIpv6Groups(groups) {
1414
1497
  const inner = classifyIpv4Octets(embeddedV4(g(6), g(7)));
1415
1498
  return v6(`IPv4-compatible \u2192 ${inner.label}`, true);
1416
1499
  }
1500
+ if (g(0) === 100 && g(1) === 65435 && g(2) === 1) {
1501
+ return v6("NAT64 local-use (64:ff9b:1::/48)", true);
1502
+ }
1417
1503
  if (g(0) === 100 && g(1) === 65435 && g(2) === 0 && g(3) === 0 && g(4) === 0 && g(5) === 0) {
1418
1504
  const inner = classifyIpv4Octets(embeddedV4(g(6), g(7)));
1419
1505
  return v6(`NAT64 64:ff9b::/96 \u2192 ${inner.label}`, inner.reserved);
1420
1506
  }
1507
+ if (g(0) === 8193 && g(1) === 0) {
1508
+ return v6("Teredo (2001::/32)", true);
1509
+ }
1421
1510
  if (g(0) === 8194) {
1422
1511
  const inner = classifyIpv4Octets(embeddedV4(g(1), g(2)));
1423
1512
  return v6(`6to4 2002::/16 \u2192 ${inner.label}`, inner.reserved);
@@ -1427,6 +1516,7 @@ function classifyIpv6Groups(groups) {
1427
1516
  if (g(0) === 8193 && g(1) === 3512) return v6("documentation (2001:db8::/32)", true);
1428
1517
  if ((g(0) & 65024) === 64512) return v6("unique local (fc00::/7)", true);
1429
1518
  if ((g(0) & 65472) === 65152) return v6("link-local (fe80::/10)", true);
1519
+ if ((g(0) & 65472) === 65216) return v6("site-local (fec0::/10)", true);
1430
1520
  if ((g(0) & 65280) === 65280) return v6("multicast (ff00::/8)", true);
1431
1521
  return v6("public", false);
1432
1522
  }
@@ -1469,8 +1559,10 @@ function guardUrl(input, policy) {
1469
1559
  if (url.username !== "" || url.password !== "") {
1470
1560
  return { ok: false, reason: "URLs with embedded credentials cannot be fetched." };
1471
1561
  }
1472
- let hostname = url.hostname.toLowerCase();
1473
- if (hostname.endsWith(".") && hostname.length > 1) hostname = hostname.slice(0, -1);
1562
+ const hostname = url.hostname.toLowerCase().replace(/\.+$/, "");
1563
+ if (hostname === "") {
1564
+ return { ok: false, reason: "That URL has no hostname." };
1565
+ }
1474
1566
  const permissive = allowsPrivateHosts(policy.hostPolicy);
1475
1567
  if (!permissive && (hostname === "localhost" || hostname.endsWith(".localhost"))) {
1476
1568
  return { ok: false, reason: "localhost cannot be fetched." };
@@ -2054,6 +2146,16 @@ async function probeWithHostPolicy(target, policy, hostPolicy, options = {}) {
2054
2146
  };
2055
2147
  }
2056
2148
  };
2149
+ const runPage = async (href, headers) => {
2150
+ const record = await run(href, headers);
2151
+ if (!record.result.ok) return record;
2152
+ const challenge = detectEdgeChallenge(record.result.capture);
2153
+ if (challenge === null) return record;
2154
+ return {
2155
+ requestHeaders: headers,
2156
+ result: { ok: false, error: "challenge", detail: challengeDetail(challenge) }
2157
+ };
2158
+ };
2057
2159
  const evidenceOf = (probes) => ({
2058
2160
  ok: true,
2059
2161
  evidence: {
@@ -2098,8 +2200,8 @@ async function probeWithHostPolicy(target, policy, hostPolicy, options = {}) {
2098
2200
  wellKnownUcp: null
2099
2201
  });
2100
2202
  }
2101
- const agent = await run(url.toString(), agentHeaders);
2102
- const browser = await run(url.toString(), browserHeaders);
2203
+ const agent = await runPage(url.toString(), agentHeaders);
2204
+ const browser = await runPage(url.toString(), browserHeaders);
2103
2205
  const linked = markdownAlternateTarget(
2104
2206
  agent.result.ok ? agent.result.capture : null,
2105
2207
  browser.result.ok ? browser.result.capture : null,
@@ -2108,7 +2210,7 @@ async function probeWithHostPolicy(target, policy, hostPolicy, options = {}) {
2108
2210
  let markdownAlternate = null;
2109
2211
  if (linked !== null) {
2110
2212
  const rule = disallowedFor(new URL(linked).pathname);
2111
- markdownAlternate = rule !== null ? skipped(agentHeaders, `robots.txt disallows ${ARS_ROBOTS_TOKEN} for ${linked}`) : await run(linked, agentHeaders);
2213
+ markdownAlternate = rule !== null ? skipped(agentHeaders, `robots.txt disallows ${ARS_ROBOTS_TOKEN} for ${linked}`) : await runPage(linked, agentHeaders);
2112
2214
  }
2113
2215
  const fetchAsset = async (path) => {
2114
2216
  const rule = disallowedFor(path);