Conversation
|
Still happy with this after sleeping on it. Just landing in LHR now to make the OHF summit in Dublin. While I've done everything I can think of to write tests for it, I'm thinking it would be best to do a 3.12.7rc0 with this and run it through Home Assistant CI and a few other projects before pushing 3.12.7. |
Backport to 3.12: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 8edec63 on top of patchback/backports/3.12/8edec635b65035ad819cd98abc7bfeb192f788a3/pr-11112 Backporting merged PR #11112 into master
🤖 @patchback |
Backport to 3.13: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 8edec63 on top of patchback/backports/3.13/8edec635b65035ad819cd98abc7bfeb192f788a3/pr-11112 Backporting merged PR #11112 into master
🤖 @patchback |
(cherry picked from commit 8edec63)
(cherry picked from commit 8edec63)
|
I've done all the production testing I can do with the RC. All looks good |
A change in aiohttp now accepts basically all invalid cookies and additionally stops failing on the ones left. The content-app will never fail the request based on cookies anymore. aio-libs/aiohttp#11112
A change in aiohttp now accepts basically all invalid cookies and additionally stops failing on the ones left. The content-app will never fail the request based on cookies anymore. aio-libs/aiohttp#11112
A change in aiohttp now accepts basically all invalid cookies and additionally stops failing on the ones left. The content-app will never fail the request based on cookies anymore. aio-libs/aiohttp#11112 (cherry picked from commit 375bf76)
A change in aiohttp now accepts basically all invalid cookies and additionally stops failing on the ones left. The content-app will never fail the request based on cookies anymore. aio-libs/aiohttp#11112 (cherry picked from commit 375bf76)
A change in aiohttp now accepts basically all invalid cookies and additionally stops failing on the ones left. The content-app will never fail the request based on cookies anymore. aio-libs/aiohttp#11112 (cherry picked from commit 375bf76)
A change in aiohttp now accepts basically all invalid cookies and additionally stops failing on the ones left. The content-app will never fail the request based on cookies anymore. aio-libs/aiohttp#11112 (cherry picked from commit 375bf76)
|
@bdraco We might be able to revert these changes in 3.15? |
|
Nice. I guess we can go back to the standard one in ~5.5 years 😄 |
What do these changes do?
Summary
This PR fixes multiple long-standing cookie parsing issues by implementing a more lenient cookie parser that handles real-world cookies while maintaining compatibility with the HTTP cookie specification.
Issues Fixed
expirescookie directive #4493Key Changes
1. Use
parse_cookie_headersfor parsing cookie headersReplaced Python's strict
SimpleCookiewith the more lenientparse_cookie_headersfunction in multiple places:Server-side (aiohttp/web_request.py):
{}[]()that are commonly used by real-world websitesClient-side:
parse_cookie_headersto handle malformed cookies gracefullyresponse.cookiesas aSimpleCookieobjectparse_cookie_headersfor the actual parsing, then updates the SimpleCookie with the resultsupdate_cookies()method to useparse_cookie_headerswhen parsing existing Cookie headersupdate_cookies_from_headers()in AbstractCookieJarparse_cookie_headershandles errors internally without raising exceptions2. Updated logger usage
client_loggertointernal_loggerinparse_cookie_headerssince the function is now used by both client and server code3. Fixed inconsistent cookie quoting behavior in CookieJar
quote_cookiesettingquote_cookie, but shared cookies were always sent unquoted_build_morsel()method for both shared and non-shared cookiesself._quote_cookiesetting consistently4. Refactored cookie morsel building in CookieJar
_build_morsel()method_cookie_helpersmodule:make_non_quoted_morsel()whenquote_cookie=Falsepreserve_morsel_with_coded_value()when cookie is already properly quotedmake_quoted_morsel()when cookie needs quotingBaseCookiefor the filtered result to ensure our quoting is always respected.5. Comprehensive test coverage
Added extensive tests to ensure:
Technical Details
The implementation aims to make aiohttp more robust when handling cookies from various web services and frameworks.
Are there changes in behavior for the user?
More lenient parser.
Is it a substantial burden for the maintainers to support this?
We have to maintain a cookie parser, however its not as bad as I was expecting since our use case is more narrow than everything
SimpleCookiedoes