Repository navigation
fix(python): follow RFC 6265 domain and path rules in the custom cookie jar - #636
Merged
Merged
Conversation
A custom cookie jar received every `Set-Cookie` as it was. A cookie with a `Domain` attribute is now stored only when that domain matches the host that sent it, an empty `Domain` is ignored, and a cookie without `Domain` is sent back only to the host that set it, not to its subdomains.
A cookie path was compared as a plain string prefix, so a cookie for `/foo` was also sent to `/foobar`. The path now has to match up to a segment boundary, as described in RFC 6265.
A `Domain` of `..` was stored as `.` and matched every host, and a bare suffix like `com` was accepted from any host under it. Both are now ignored, the second the same way Python's `DefaultCookiePolicy` does it.
The dotless check let suffixes like `co.uk` or `github.io` through. The domain is now checked against the Public Suffix List instead.
A host whose name is itself a public suffix can set a cookie for that name. Browsers then store it as a host-only cookie, so it is not sent to the sites below it.
File cookie jars of `http.cookiejar` derive `domain_specified` from a leading dot when saving, so a cookie with a `Domain` turned into a host-only one after a save and load.
barjin
approved these changes
Nov 20, 2026
barjin
left a comment
Member
There was a problem hiding this comment.
since my https://github.com/apify/impit-ghsa-g2m3-vx8j-88cw/pull/1 review has been addressed, I don't have anything to add.
thanks @B4nan !
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.
The custom cookie jar in the Python bindings stored every
Set-Cookieas it came in. It now follows the RFC 6265 domain rules: a cookie with aDomainis only stored when that domain matches the host that sent it, an emptyDomainis ignored, and a cookie withoutDomainis only sent back to the host that set it, not to its subdomains.A
Domainmade only of dots is ignored too. Public suffixes (com,co.uk,github.io) are handled the way browsers do it, using both sections of the Public Suffix List through thepslcrate: such a cookie is dropped, unless it comes from the host of that exact name, where it is stored as host-only.Cookie paths were compared as a plain string prefix, so a cookie for
/foowas also sent to/foobar. They now have to match up to a segment boundary.test_complex_cookiesusedDomain=.127.0.0.1against httpbin, which is no longer stored, so it uses the httpbin host now.A cookie with a
Domainis stored with a leading dot, likehttp.cookiejardoes it. File cookie jars such asMozillaCookieJaronly keepdomain_specifiedfor those, so without the dot the cookie became host-only after a save and load.