Skip to content

utils/robots-txt: stacked user-agent lines, empty Disallow groups and inline comments are misparsed #1078

Closed

Description

@nc9

parseRobotsTxt in packages/utils/src/robots-txt.ts (used by the crawler for RobotsTxtData, so by ax/ai-crawlers, ax/content-signals and the indexability rules) reads three common robots.txt shapes differently from RFC 9309 and from how crawlers read them.

  1. Stacked user-agent lines lose all but the last. RFC 9309 section 2.1: consecutive user-agent lines start one group. The parser flushes on every user-agent line and only keeps a group that has rules, so

    User-agent: GPTBot
    User-agent: ClaudeBot
    Disallow: /
    

    parses to one group for ClaudeBot. GPTBot falls through to *, and ax/ai-crawlers reports it as allowed. This is the format our own robots.txt generator (/tools/robots-txt-generator) writes, so a file made there is misread by the audit.

  2. A group with an empty Disallow: is dropped. User-agent: GPTBot + Disallow: (allow everything) yields no group, so GPTBot inherits a User-agent: * / Disallow: / group and is reported as blocked.

  3. Inline comments stay in the path. Disallow: / # no training stores the path / # no training, which is not a root block, so the bot is reported as allowed.

Repro (from the private monorepo root, apps/web):

import { parseRobotsTxt } from "@squirrelscan/utils/robots-txt";
parseRobotsTxt("User-agent: GPTBot\nUser-agent: ClaudeBot\nDisallow: /\n", "https://x/robots.txt").rules;
// [{ userAgent: "ClaudeBot", rules: [{ type: "disallow", path: "/" }] }]

Found while building the AI crawler access checker (squirrelscan/repo#3127), which parses groups per RFC 9309 and carries a parity test that flips when this is fixed.

Acceptance Criteria

  • Consecutive User-agent lines share the rules that follow them; ax/ai-crawlers reports both GPTBot and ClaudeBot blocked for the stacked example above
  • A group whose only rule is an empty Disallow: is kept, so the named bot is allowed even when * is blocked
  • # and everything after it on a line is ignored, so Disallow: / # comment is a root block
  • Unit tests in packages/utils cover all three shapes, and isRobotsTxtDisallowed gives the same answers for them

Activity

  1. added
    bug
    size: S
    rules
    on Oct 23, 2026
  2. WilliamK112 commented on Oct 23, 2026

    @WilliamK112
    Contributor

    I’d like to work on this. I’ll keep the change scoped to the three acceptance cases: stacked User-agent lines sharing the following rules, retaining an explicit empty Disallow: group, and stripping inline comments. I’ll add focused parser and isRobotsTxtDisallowed coverage in packages/utils and run the relevant package tests and checks.

  3. added
    P1
    on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1bugrulessize: S

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions