-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compliance with rfc6265 for cookie expires dates #4327
Comments
Seems like we have own datetime parser in cookiejar.py, the parser is used on the client side. |
That's fair enough. As I say I have replaced the server code that was generating these cookies so I'm not in any rush personally to have it fixed. These three various date formats are the current specs though not an old spec. Also I'm not sure what regexs you are referring to, as I see it the python standard library http.cookies parser needs to be replaced with a compliant parser; but there could be some other existing code in this lib im not aware of. A library like https://gitlab.com/sashahart/cookies has already done the heavy work of creating a valid parser. Sadly this library is old and unmaintained for a long time, pull requests and questions ignored. But as a proof of concept you can do something horrible like the below change to show library code is working. I didn't make a pull request as I am in no way advocating this change, I just spend a bit of time seeing what was happening.
With this change all formats in the spec work and all existing tests pass as I converted back to a normal SimpleCookie instance anyway. I guess we could take the bulk of the parse code from this MIT licensed 3rd party cookies lib (there may be other alternatives) and make it return a SimpleCookie and use the python http.cookies exceptions to maintain compatibility and expectations of any code using cookiejar. Is that a strategy you would approve of? |
I thought about these regexps If some awesome library for working with cookies already exists -- this is cool, we can consider its usage. Maybe the work is not that hard, fixing a few regular expressions do what do you need? |
Is #4493 a duplicate of this issue? (Found this after commenting over there.) I've tried fixing my issue at https://github.com/aio-libs/aiohttp/blob/master/aiohttp/cookiejar.py#L48 like this: DATE_YEAR_RE = re.compile(r"-?(\d{2,4})") But that didn't work. |
The ANSI C format doesn't work in http.cookies, so a bug should be reported to cpython to fix that one:
Once working in SimpleCookie, it should work here, the regex looks like it would match correctly. The RFC 850 one does work in SimpleCookie and just needs the regex updating as asvetlov mentioned. |
Long story short
Compliance with rfc6265 for cookie expires functionality. Took a while yesterday trying to work out why some client code wasn't working correctly, eventually tracked it down to cookie handling in aiohttp; well in pythons http.cookies. The server was returning an old but should be valid date format.
Expected behaviour
The specific problems I had are related to expires. Digging through the rfc's my current understanding is that expires as defined in rfc6265 states that the date format should be a sane-cookie-date as described in https://tools.ietf.org/html/rfc2616#section-3.3.1
Problem is that aiohttp doesn't handle all these options and it appears to strip cookies that have two of these formats.
Steps to reproduce
This is a simple python server to return the different values, I included the common type with 4 digit years as everywhere seems to use it.
If I run a request with aiohttp
Actual behaviour
I will get output along the lines of
rfc850 and ansic dates are excluded during response parsing.
I'm not sure if supporting these formats is important to you, I'm going to get the server we are connecting to to switch formats aliviating the problem for me specifically. Just thought I would report it anyway.
OS: MacOSX
Python: 3.7
aiohttp: 3.6.2
The text was updated successfully, but these errors were encountered: