-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-92936: allow double quote in cookie values #113663
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
gh-92936: allow double quote in cookie values #113663
Conversation
4e125ac
to
1b3b200
Compare
Lib/http/cookies.py
Outdated
@@ -442,7 +442,7 @@ def OutputString(self, attrs=None): | |||
( # Optional group: there may not be a value. | |||
\s*=\s* # Equal Sign | |||
(?P<val> # Start of group 'val' | |||
"(?:[^\\"]|\\.)*" # Any doublequoted string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
webob handles cookies with quotes more robustly: https://github.com/Pylons/webob/blob/main/src/webob/cookies.py#L335
78dce80
to
1b78ed1
Compare
1b78ed1
to
3eae48a
Compare
@orsenthil sorry for the random mention, but I saw you were active on some other cookie related issues in the past and wondered if you could review this or help me get pointed in the direction to find someone to review this? |
95af939
to
e9b3cd5
Compare
I have nothing to add to this other than to say that I spent about 4 hours today debugging an issue caused and it almost drove me to madness before I found the problem. This is a particularly pernicious issue because the error is caused by a level of the infrastructure you expect to never fail. I'm sure this impacts people all the time and they have no idea why their thing doesn't work and just give up. Keep fighting the good fight trying to get this merged! I have no power to help you but the PR looks good to me. |
e9b3cd5
to
6e3d1d7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an additional test case demonstrating the need for a lazy match in regex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Formatted the test case.
- Added an additional test for lazy matching of quoted characters, which would fail if the match was greedy.
@nburns ,and @danbirken - thanks for raising this issue. Apologize for not looking into this or responding to the ping. |
f88d0a7
to
72c88f9
Compare
Co-authored-by: Senthil Kumaran <senthil@python.org>
72c88f9
to
081ace2
Compare
@orsenthil Thanks for taking a look, I applied your suggestion and fixed up the tests, also updated the news entry and signed the CLA, is there anything else I can do to help move this PR forward? |
Thank you for updating and fixing the tests. I didn't realize the failure when I ran it yesterday. Thanks. |
Can we have a follow-up PR here that adds a What's New entry and updates the documentation of |
Also, please be careful but we have some examples with quotes on the online docs so maybe they should be updated. |
Sure, I'll take a look |
|
updated the docs in #137566 |
As detailed more extensively in: #92936 it's not uncommon to see cookies with json and therefore double quotes in them. While IMO a well behaved application would base64 or otherwise encode those values, there are numerous services putting double quotes in the cookies, and it would be nice to have support for this directly in python so various http server/client/util libraries don't need to implement their own cookie parsing. Additionally browsers are tolerant of and handle double quotes in cookie values so
SimpleCookie
should also.Before this change
SimpleCookie
will without error drop cookie values that appear after a value with a double quote in them, which can lead to some very confusing and hard to debug issues when implementing http clients and servers.After this change
SimpleCookie
allows a double quote character in the values section of the cookie while making no attempt to determine if the value is valid json or anything else (since that's a application/usecase specific concern)Downstream issues:
aio-libs/aiohttp#7993
yt-dlp/yt-dlp#4780