Skip to content

Malicious robots.txt can trigger O(N²) parsing, waste CPU #163147

Backlog

Description

@brettcs

Bug report

This was originally reported by @VadimToptunov. If robots.txt contains repeated User-Agent lines for a rule, then urllib.robotparser.RobotFileParser.parse() can run in O(N²) and burn a lot of CPU parsing it. Specifically this line in _merge_into building two sets out of the same long list of agents on every line:

entry.useragents = list(filter(set(e2.useragents).__contains__, e1.useragents))

Normal robots.txt files shouldn't have many duplicate User-Agent lines, the only reason to do this would be specifically to cause trouble. This is a different issue from #149381 which is about optimizing path parsing which comes up more normally.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Activity

  1. added
    type-bug
    on Dec 4, 2026
  2. added
    stdlib
    on Dec 4, 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

    stdlibtype-bug

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions