Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nburns
Copy link
Contributor

@nburns nburns commented Jan 2, 2024

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

@@ -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
Copy link
Contributor Author

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

@nburns nburns force-pushed the allow-double-quote-in-cookie-values branch 2 times, most recently from 78dce80 to 1b78ed1 Compare January 8, 2024 18:22
@nburns nburns force-pushed the allow-double-quote-in-cookie-values branch from 1b78ed1 to 3eae48a Compare January 12, 2024 15:51
@nburns
Copy link
Contributor Author

nburns commented Jan 12, 2024

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant