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

Parse set header cookies properly #5084

Merged
merged 1 commit into from Dec 2, 2023

Conversation

Speedlulu
Copy link
Contributor

Description

Currently when an empty cookie attribute (Secure, HttpOnly ...) is encountered while parsing a Set-Cookie header it will create a CookieAttrs object containing a (key, value) pair with an empty string for the attribute value ie:

CookieAttrs[('Secure', ''), ('HttpOnly', ''), ('Path', '/')]

Resulting in an updated Set-Cookie header for the Response object with invalid values for those empty attributes ie:

(b'SetCookie', b'value=XYZ; Secure=; HttpOnly=; Path=/')

My browser (Firefox 95.0.1) does not pickup these attributes so the cookie looses them.


This fix replaces the empty string attribute for empty cookie attributes by the value None ie:

CookieAttrs[('Secure', None), ('HttpOnly', None), ('Path', '/')]

So that they can be told apart from attributes with intentional empty string values when setting the updated header, which results in a properly formatted header:

(b'SetCookie', b'value=XYZ; Secure; HttpOnly; Path=/')

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG.

@bratao
Copy link

bratao commented Feb 8, 2022

Just a +1 from me, this fixed an website found on the wild.

Copy link
Member

@mhils mhils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Thanks! 🍰

@mhils mhils merged commit 43bbcef into mitmproxy:main Dec 2, 2023
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants