Skip to content

robots.txt with a byte that is not UTF-8 is ignored completely, so every URL is allowed #2530

Description

@shlokbam

Description

RobotsTxtFile.load decodes the body with body.decode('utf-8-sig'). If the file has a single byte that is not valid UTF-8, for example a comment saved as Latin-1 or Windows-1252, this raises UnicodeDecodeError. BasicCrawler then retries the fetch (3 attempts) and falls back to allowing every URL of the site:

WARN  Failed to fetch from robots.txt from "http://127.0.0.1:49905/robots.txt" with error: "'utf-8' codec can't decode byte 0xe0 in position 34: invalid continuation byte"
(x3)
WARN  Fetching the robots.txt file of http://127.0.0.1:49905 failed with UnicodeDecodeError(...), so all its URLs are allowed.
crawler allows /private/a: True

The rules themselves were plain ASCII. The file was:

# Fichier robots.txt du site, mis à jour en été      <- Latin-1 bytes
User-agent: *
Disallow: /private

RFC 9309 says the file should be UTF-8, but these files exist. Google's parser skips invalid characters and keeps the rules, and Scrapy, which uses the same Protego parser, decodes with robotstxt_body.decode("utf-8-sig", errors="ignore").

Steps to reproduce

Serve the bytes above as /robots.txt and run await RobotsTxtFile.find(url, ImpitHttpClient()) (raises UnicodeDecodeError) or BasicCrawler(respect_robots_txt_file=True) (allows /private/a).

Expected behavior

The bytes that don't decode are skipped and /private/ stays disallowed.

Notes

I found this by reading RobotsTxtFile.load after #2350, not on a real crawl. Same code on master (8dee0d0) and v2.

Activity

  1. added
    t-tooling
    on Nov 26, 2026
  2. added a commit that references this issue on Nov 27, 2026
    fb26519
  3. self-assigned this
    on Nov 27, 2026
  4. added theissue type on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

t-tooling

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions