From 9b70b0b2d3e8bd11a86ac536aac5b86a05f90c36 Mon Sep 17 00:00:00 2001 From: mandiau-matthias Date: Mon, 16 Nov 2026 15:05:53 +0100 Subject: [PATCH] Apply robots specificity to blanket allow rules The equivalent-allow fix treated every root-covering rule as equal. RFC 9309 chooses the most specific match, so Disallow: /* (2 octets) still blocks when paired with Allow: / (1 octet), while Allow: /** lifts it. Track the longest root-covering allow and disallow patterns, keep the allow-wins tie rule, and add wildcard cases to the probe harness. Narrow allows still do not lift a blanket disallow. --- CHANGELOG.md | 2 +- docs/API.md | 6 +++--- src/probe.mjs | 24 ++++++++++++++++-------- test/probe.test.mjs | 13 +++++++++++++ 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 177e580..60fe9ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ * Expanded the synthetic corpus to six cases: blog 100, legacy 60, shop 45, settings 40, sign-in 80 and invoice 40; mean 60.8/100, 2/6 at the 80 threshold. Each fixture records the contract fields inference cannot establish. * Recorded a maintainer-run Codex CLI 0.145.0 protocol check with synthetic data; an independent outside report remains open. * Audited the experiment by keyboard, fixed redundant live-region writes while preserving repeated error announcements, and added `npm run test:browser` with a Chrome CI workflow for playground tab order, focus, experiment journeys, film playback, reduced motion and narrow layouts. -* Inference now ignores inert template and textarea markup. The probe recognizes an equivalent root allow rule before capping a robots.txt disallow, and private-host screening rejects mapped, translated, NAT64, site-local and reserved IPv6 literals. +* Inference now ignores inert template and textarea markup. The probe applies RFC 9309 specificity to root allow/disallow rules before capping a robots.txt disallow, and private-host screening rejects mapped, translated, NAT64, site-local and reserved IPv6 literals. * Added a daily maintainer guide, a scoped work queue and standalone coding assistant instructions. * Added `npm run dev` and `npm run check:quick`; full package and bundle verification remains required before merging. * Configured weekly dependency update proposals and made independent first run completion explicit in the feedback form. diff --git a/docs/API.md b/docs/API.md index 20178e9..981aa36 100644 --- a/docs/API.md +++ b/docs/API.md @@ -101,9 +101,9 @@ untrusted multi-tenant URL-fetch service. The probe validates the Hardwire panel only. Other discovery markers are weak presence signals, not verified protocol implementations. The `webmcp` heuristic matches source text, including older API spellings; it cannot see tools registered -at runtime. `robots.txt` handling reports a blanket wildcard disallow, unless an -equivalent allow rule permits the root, and caps the score. It is not a complete -robots policy engine or authorization check. +at runtime. `robots.txt` handling reports a blanket wildcard disallow unless an +equally or more specific allow rule permits every path, and caps the score. It +is not a complete robots policy engine or authorization check. Scoring compares kind, confirmation, reversibility, endpoint and parameter structure with equal weight. It ignores prose, preconditions, result schemas, diff --git a/src/probe.mjs b/src/probe.mjs index 636b676..126deea 100644 --- a/src/probe.mjs +++ b/src/probe.mjs @@ -140,11 +140,18 @@ export async function fetchPage(url, { fetchImpl = globalThis.fetch, timeoutMs = } } +/** Length of a robots path that permits every URL, or 0 if it does not. */ +function rootCoveringLength(value) { + if (value === "/") return 1; + // /, /*, /**, /*$, /**$ and longer star runs match the root and every path. + return /^\/\*+\$?$/.test(value) ? value.length : 0; +} + function robotsBlocksAllAgents(body) { const lines = body.split(/\r?\n/).map((line) => line.replace(/#.*$/, "").trim()); let inAll = false; - let disallowsRoot = false; - let allowsRoot = false; + let disallowLength = 0; + let allowLength = 0; let seenRule = false; for (const line of lines) { const [rawKey, ...rest] = line.split(":"); @@ -156,14 +163,15 @@ function robotsBlocksAllAgents(body) { } else if (key === "allow" || key === "disallow") { seenRule = true; if (!inAll) continue; - // RFC 9309 section 2.2.2: an equivalent allow rule wins over disallow. - if (value === "/" || value === "/*") { - if (key === "disallow") disallowsRoot = true; - else allowsRoot = true; - } + const length = rootCoveringLength(value); + if (!length) continue; + // RFC 9309 section 2.2.2: the most specific match wins, and an equally + // specific allow wins. A narrower allow does not lift a blanket disallow. + if (key === "disallow") disallowLength = Math.max(disallowLength, length); + else allowLength = Math.max(allowLength, length); } } - return disallowsRoot && !allowsRoot; + return disallowLength > 0 && disallowLength > allowLength; } function htmlSignals(body) { diff --git a/test/probe.test.mjs b/test/probe.test.mjs index 1ff9532..e7ced71 100644 --- a/test/probe.test.mjs +++ b/test/probe.test.mjs @@ -86,6 +86,19 @@ test("an equivalent allow rule prevents a blanket-disallow cap", async () => { const report = await probeOrigin("https://shop.example.com", { fetchImpl: site(routes) }); assert.equal(report.blockedByRobots, true); assert.equal(report.score, 25); + + // A wildcard disallow is more specific than a root allow, so it still blocks. + for (const [body, blocked] of [ + ["User-agent: *\nDisallow: /*\nAllow: /\n", true], + ["User-agent: *\nDisallow: /*\nAllow: /*\n", false], + ["User-agent: *\nDisallow: /*\nAllow: /**\n", false], + ]) { + const wildcard = await probeOrigin("https://shop.example.com", { + fetchImpl: site({ ...cooperative(), "/robots.txt": { body, type: "text/plain" } }), + }); + assert.equal(wildcard.blockedByRobots, blocked, body); + assert.equal(wildcard.score, blocked ? 25 : 100, body); + } }); test("network failure is a finding, not an exception", async () => {