Skip to content

robots.txt rules are not applied to URLs that spell out the default port (https://example.com:443/...) #2532

Description

@shlokbam

Description

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:

>>> from yarl import URL
>>> URL('https://example.com:443/x').origin() == URL('https://example.com/robots.txt').origin()
False
>>> str(URL('https://example.com:443/x').origin())
'https://example.com'

It goes the other way too: if the first URL of a site had :443, the cached file is bound to that form and the plain URLs skip its rules.

Steps to reproduce

import asyncio
from crawlee._utils.robots import RobotsTxtFile

async def main():
    robots = await RobotsTxtFile.from_content('https://example.com/robots.txt', 'User-agent: *\nDisallow: /private\n')
    print(robots.is_allowed('https://example.com/private/a'))      # False
    print(robots.is_allowed('https://example.com:443/private/a'))  # True, expected False

asyncio.run(main())

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

  1. added
    t-tooling
    on Nov 26, 2026
  2. self-assigned this
    on Nov 27, 2026
  3. added theissue type on Nov 27, 2026
  4. added a commit that references this issue on Nov 27, 2026
    4d50067
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