You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
robots.txt with a byte that is not UTF-8 is ignored completely, so every URL is allowed #2530
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
fix: Keep `robots.txt` rules when the file is not valid UTF-8 (#2531)