Repository navigation
fix(python): honor Max-Age and apply the Secure and prefix rules when storing cookies - #633
Conversation
… storing cookies - `Max-Age` was ignored, so such cookies never expired and `Max-Age=0` did not remove a cookie. It now takes precedence over `Expires`, and an already expired cookie removes the stored one. - A `Set-Cookie` header that fails to parse was stored as a placeholder cookie. It is skipped now. - A `Secure` cookie is only stored from HTTPS or a loopback host, and a response from elsewhere can't replace one. - The `__Secure-` and `__Host-` name prefixes are checked.
barjin
left a comment
There was a problem hiding this comment.
Thank you @B4nan , there's some small nits (see below), but approving now, as it's not really blocking-level bad.
Once these fixes are merged and out, I'd love to simplify all this by delegating all the calls to the standard Python CookieJar implementations. Hopefully, that will save us quite a few LOCs.
| && attr("domain").eq_ignore_ascii_case(domain) | ||
| && attr("path") == path |
There was a problem hiding this comment.
the Domain and Path attributes should be compared using the Domain-Match and Path-Match algos.
Otherwise, HTTP servers can still store a cookie that already exists in the jar w/ Secure attribute (using, e.g., Path: "", while the original has Path: "/" or sth like that).
There was a problem hiding this comment.
Done, it uses domain-match (either direction) and path-match now, with an empty path treated as /.
…torage-rules # Conflicts: # impit-python/src/cookies.rs
…rotecting a secure cookie
Brings the custom cookie jar of the Python bindings closer to RFC 6265 and its current draft update when storing cookies:
Max-Agewas ignored, so such cookies never expired andMax-Age=0did not remove a cookie. It now takes precedence overExpires, and an already expired cookie removes the stored one, the same wayCookieJar.extract_cookiesdoes.Set-Cookieheader that fails to parse was stored as a<cookie-name>placeholder cookie. It is skipped now.Securecookie is only stored from HTTPS or a loopback host, and a response from anywhere else can't replace an existing one.__Secure-and__Host-name prefixes are checked.