http.cookiejar.domain_match() matches an interior substring instead of a suffix
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
domain_match(A, B) is documented to return True when A has the form NB, i.e. A ends with B (RFC 2965, section 1: "x.y.com domain-matches .Y.com but not Y.com"). It computes i = A.rfind(B) and only rejects i == -1 or i == 0, so a B that appears as an interior substring of A also matches:
>>> from http.cookiejar import domain_match
>>> domain_match("www.acme.com.evil.org", ".acme.com")
True
www.acme.com.evil.org does not end with .acme.com, so this should be False. The sibling helper user_domain_match() already uses A.endswith(B). This feeds the RFC 2965 (version > 0) cookie domain checks in set_ok_domain/return_ok_domain and is_third_party().
Linked PRs
- gh-150523
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with http.cookiejar.domain_match() and compare its behavior with the sibling user_domain_match() helper and the documented RFC 2965 rule. Verify the reported example no longer matches an interior substring, and check the related set_ok_domain, return_ok_domain, and is_third_party() paths; linked PR gh-150523 indicates the work is already underway.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- security
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100