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 rules are not applied to URLs that spell out the default port (https://example.com:443/...) #2532
With respect_robots_txt_file=True, a URL that spells out the default port is crawled even when robots.txt disallows it. With Disallow: /private/ on https://example.com, https://example.com/private/page is skipped but https://example.com:443/private/page is crawled.
BasicCrawler._get_robots_txt_file_for_url caches robots.txt files under str(URL(url).origin()), which drops the default port, so both URLs get the same RobotsTxtFile. Then RobotsTxtFile.is_allowed returns True for any URL whose origin is not equal to the robots.txt origin, and yarl's URL equality treats the two as different:
Through the crawler (BasicCrawler(respect_robots_txt_file=True), robots.txt fetch stubbed so the cache and check are the real code), _is_allowed_based_on_robots_txt_file returns False for https://example.com/private/a and True for https://example.com:443/private/a.
Expected behavior
https://example.com:443/... and https://example.com/... are the same origin (RFC 3986 section 6.2.3), so the same rules apply. A non-default port such as :8443 is still a different origin.
Notes
I found this by reading the robots.txt code and testing URL forms against it, not on a real crawl. Links with an explicit :443 do show up on pages, for example from sites behind some proxies or CMS setups. Same code on master (8dee0d0) and v2.
Activity
fix: Apply `robots.txt` rules to URLs with the default port (#2533)