Repository navigation
fix: Apply robots.txt rules to URLs with the default port - #2533
Merged
Merged
Conversation
`RobotsTxtFile.is_allowed` allowed any URL whose origin is not equal to the robots.txt origin. yarl's `URL` equality treats `https://example.com:443` and `https://example.com` as different origins, while `BasicCrawler` caches robots.txt files under the string form of the origin, which drops the default port. So with `Disallow: /private/`, `https://example.com:443/private/page` was allowed. Compare the string forms of the origins instead.
vdusek
approved these changes
Nov 27, 2026
robots.txt rules to URLs with an explicit default port
robots.txt rules to URLs with an explicit default portrobots.txt rules to URLs with the default port
# Conflicts: # tests/unit/_utils/test_robots.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
RobotsTxtFile.is_allowedreturnsTruewhen the URL's origin is not equal to the robots.txt origin. yarl'sURLequality treatshttps://example.com:443andhttps://example.comas different, whileBasicCrawlercaches robots.txt files under the string form of the origin, which drops the default port. So a URL that spelled out the default port skipped the rules: withDisallow: /private/,https://example.com:443/private/pagewas allowed.tests/unit/_utils/test_robots.py, like fix: Keeprobots.txtrules when the file is not valid UTF-8 #2531, so a small rebase may be needed after one of them is merged.Issues
https://example.com:443/...) #2532Testing
tests/unit/_utils/test_robots.py: the default port in the URL (https and http) and in the robots.txt URL is disallowed (3 cases, fail onmasterand pass with the fix), and a non-default port (:8443) is still treated as another origin (passes on both).pytest tests/unit/_utils/test_robots.py test_urls.py test_requests.py test_sitemap.py: 113 passed.pytest tests/unit/crawlers/_basic -k robots: 8 passed.str(URL(...).origin())drops the default port on yarl 1.18.0, the lowest version inpyproject.toml.ruff check,ruff format --check(0.17.6) andty check(0.0.109) pass on the changed files.Checklist