{"slug": "our-robots-txt-check-could-never-fail-because-disallow-contains-allow", "title": "Our robots.txt check could never fail, because \"disallow: /\" contains \"allow: /\"", "summary": "A developer behind the free SEO audit tool StitchSEO found and fixed two bugs in its robots.txt parsing, both of which caused the check to report sites as crawlable when they actually blocked bots. The first bug let a regex for an Allow: / line match inside Disallow: /, cancelling the block detection, while the second let a per-bot regex run past a bot's own user-agent group and misreport GPTBot as blocked. The developer published a rewritten parser that groups consecutive User-agent lines and applies only the matching bot's rules, plus ten test cases covering both failure modes.", "body_md": "We launched StitchSEO, our free one-page SEO audit, on Product Hunt today. While checking our own launch claims we found two bugs in how it read robots.txt.\n\nThe check looked like this:\n\n``` js\nconst blocksAll = /user-agent:\\s*\\*[\\s\\S]*?disallow:\\s*\\/\\s*(\\n|$)/i.test(robotsTxt)\n  && !/allow:\\s*\\//i.test(robotsTxt);\n```\n\nThe second test was meant to spot an `Allow: /` line. But the string `Disallow: /` contains `allow: /`. So whenever the first half matched, the second half cancelled it, and a site that blocked every crawler still passed.\n\nFor AI crawlers we built a regex per bot:\n\n```\nnew RegExp(`user-agent:\\\\s*${bot}[\\\\s\\\\S]*?disallow:\\\\s*/\\\\s*(\\\\n|$)`, 'i')\n```\n\nThe lazy `[\\s\\S]*?` happily runs past the end of the bot's own group. With this file, GPTBot was reported as blocked:\n\n```\nUser-agent: GPTBot\nAllow: /\n\nUser-agent: BadBot\nDisallow: /\n```\n\nRead the file the way a crawler does: use the group that names you, or the `*` group if none does, and remember that consecutive `User-agent` lines share the rules below them.\n\n```\nexport function blockedFromSite(robotsTxt: string, bot: string): boolean {\n  const groups: { agents: string[]; rules: string[] }[] = [];\n  let readingAgents = false;\n  for (const line of robotsTxt.split(/\\r?\\n/)) {\n    const m = /^\\s*([a-z-]+)\\s*:\\s*([^#]*)/i.exec(line);\n    if (!m) continue;\n    const key = m[1].toLowerCase();\n    const value = m[2].trim();\n    if (key === 'user-agent') {\n      if (!readingAgents) groups.push({ agents: [], rules: [] });\n      groups[groups.length - 1].agents.push(value.toLowerCase());\n      readingAgents = true;\n    } else if (key === 'allow' || key === 'disallow') {\n      groups[groups.length - 1]?.rules.push(`${key}:${value.replace(/^\\/\\*$/, '/')}`);\n      readingAgents = false;\n    }\n  }\n  const own = groups.filter((g) => g.agents.includes(bot.toLowerCase()));\n  const rules = (own.length ? own : groups.filter((g) => g.agents.includes('*'))).flatMap((g) => g.rules);\n  return rules.includes('disallow:/') && !rules.includes('allow:/');\n}\n```\n\nIt only answers one question, whether a bot is shut out of the whole site. It doesn't evaluate path rules.\n\nWe added ten small test cases, including both files above. If you have a robots.txt check of your own, try them on it.\n\nThe tool is at [saraswatistitch.com/seo-audit](https://www.saraswatistitch.com/seo-audit) if you want to break it.\n\n*Written with AI assistance. Code and behaviour checked against our repository.*", "url": "https://wpnews.pro/news/our-robots-txt-check-could-never-fail-because-disallow-contains-allow", "canonical_source": "https://dev.to/saraswati_stitch/our-robotstxt-check-could-never-fail-because-disallow-contains-allow--4jlb", "published_at": "2026-12-03 08:41:18+00:00", "updated_at": "2026-12-03 08:47:01.005972+00:00", "lang": "en", "topics": ["ai-crawlers", "generative-engine-optimization", "ai-search"], "entities": ["StitchSEO", "Product Hunt", "GPTBot"], "also_reported_by": [], "takeaway": "A robots.txt parser must scope rules to the matching user-agent group and match Allow/Disallow directives as whole tokens, since a substring test for 'allow: /' also matches inside 'Disallow: /' and a lazy regex can run past a bot's own group.", "recommendation": {"advice": "Parse robots.txt into per-user-agent groups and match Allow/Disallow as whole directives rather than substrings, then run the source's ten test cases against your own crawler check.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/our-robots-txt-check-could-never-fail-because-disallow-contains-allow", "markdown": "https://wpnews.pro/news/our-robots-txt-check-could-never-fail-because-disallow-contains-allow.md", "text": "https://wpnews.pro/news/our-robots-txt-check-could-never-fail-because-disallow-contains-allow.txt", "jsonld": "https://wpnews.pro/news/our-robots-txt-check-could-never-fail-because-disallow-contains-allow.jsonld"}}