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

Support for Partitioned cookies attribute #112713

Closed
giles-v opened this issue Dec 4, 2023 · 14 comments · Fixed by #112714
Closed

Support for Partitioned cookies attribute #112713

giles-v opened this issue Dec 4, 2023 · 14 comments · Fixed by #112714
Assignees
Labels
3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@giles-v
Copy link
Contributor

giles-v commented Dec 4, 2023

Feature or enhancement

Proposal:

Chrome is phasing out support for Third Party Cookies in Q1 2024, and for several key use cases, the proposed solution is CHIPS (https://github.com/privacycg/CHIPS).

See Chrome's blogpost about these changes: https://developer.chrome.com/en/docs/privacy-sandbox/third-party-cookie-phase-out/#partitioned

Currently, cookies with the Partitioned attribute cannot be set from within the http.cookies library. I'm proposing that we add support for that attribute.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@giles-v giles-v added the type-feature A feature request or enhancement label Dec 4, 2023
@AlexWaygood AlexWaygood added the stdlib Python modules in the Lib dir label Dec 4, 2023
@giles-v
Copy link
Contributor Author

giles-v commented Jan 17, 2024

Hey there @AlexWaygood, just a ping on this issue per the contributors guide -- this issue and the PR have been up for about six weeks now. A review would be appreciated, thank you!

@Flecart
Copy link

Flecart commented Feb 10, 2024

I need this feature, for starlette. encode/starlette#2500.

Flecart added a commit to Flecart/starlette that referenced this issue Feb 10, 2024
the test should fail, we need to wait for python/cpython#112713
@merwok
Copy link
Member

merwok commented Feb 12, 2024

AFAIU this is a proposed / experimental thing for now, and from MDN it’s not implemented in Firefox or Safari yet.
If this becomes a standard (with WHATWG or W3C), it could be considered for Python.

@gpshead gpshead added the 3.13 bugs and security fixes label Feb 14, 2024
@gpshead gpshead self-assigned this Feb 14, 2024
@gpshead gpshead moved this to In Progress in Cookies issues 🍪 Feb 14, 2024
@merwok
Copy link
Member

merwok commented Feb 14, 2024

@gpshead could you reply to my note here before going on with the PR?

@gpshead
Copy link
Member

gpshead commented Feb 14, 2024

Sorry I missed your comment earlier. Holding off awaiting a standard is fine, I misread it and thought it'd been implemented already rather than seeing those were the prior attempts.

This really just seems to be adding an attribute that adds an additional string to a cookie. If it winds up not meaning anything, it wouldn't be the end of the world - though we'd obviously need different docs than what the PR contains right now.

What's the alternative within the existing http.cookies API for adding Partitioned to a cookie it creates and checking for Partitioned when parsing today without implementing your own parsing? (that could expand into a bigger question about whether the stdlib API is actually a good one)

@gpshead gpshead removed the 3.13 bugs and security fixes label Feb 14, 2024
@gpshead gpshead assigned merwok and unassigned gpshead Feb 14, 2024
@gpshead gpshead moved this from In Progress to Todo in Cookies issues 🍪 Feb 14, 2024
@Flecart
Copy link

Flecart commented Feb 19, 2024

I would like to note that https://developers.google.com/privacy-sandbox/3pcd#report-issues google is already rolling out this change for 1% of users.

@mst-kialo
Copy link

mst-kialo commented Feb 21, 2024

We had to patch in support for partitioned cookies ourselves in preparation for the switch to partitioned cookies in Edge / Chrome because that will likely be coming for every Chrome and Edge users no matter what. For us that makes the experience of users in embedded contexts much smoother since we know that we will be supporting embedding even after the phaseout of 3rd party cookies has been completed sometime this year on those two browsers.

It would be nice not having to patch it because the accepted attributes for morsels are as restrictive as they currently are, especially since unknown properties are simply ignored by other browsers. Firefox and Safari don't care if the Partitioned property is set and continue working with the cookies as is.

In conclusion waiting for this PR to be pulled until this has become a standard results in either a worse experience for users of chromium browsers or having to manually patch it in anyway.
Furthermore Safari and Firefox seem to have positioned themselves open to implement support for it sometime down the road as well:

WebKit/standards-positions#50
mozilla/standards-positions#678

@merwok merwok added the 3.13 bugs and security fixes label Feb 21, 2024
@merwok
Copy link
Member

merwok commented Feb 21, 2024

OK, there seems to be consensus, so this can be added to 3.13

ep1cman added a commit to ep1cman/uiprotect that referenced this issue Jun 11, 2024
As of UniFi Protect 4.0.5, they have started sending the cookie flag "partitioned".
Python currently does not know about this (planned to be fixed in 3.13 python/cpython#112713).
This causes the cookie to be considered invalid, and thus the auth cookie is never saved.
Since unifi protect rate limits authentication attempts this leads to 501 errors after a few requests are made.

This commit adds `partitioned` to the list of cookie flags the standard library accepts as valid.
Thus allowing the cookie to be correctly parsed and saved.
@picnixz picnixz removed the 3.13 bugs and security fixes label Sep 9, 2024
@picnixz
Copy link
Member

picnixz commented Sep 9, 2024

FTR: issues with type-feature always target the latest branch.

@merwok
Copy link
Member

merwok commented Sep 9, 2024

ok but why remove the tag indicating the version that a feature will or does appear in?

@picnixz
Copy link
Member

picnixz commented Sep 9, 2024

I think it's because the feature may or may not be included in that version when it's being merged. (Actually, I'm only following the devguide: https://devguide.python.org/triage/labels/#type-labels). We however use the 3.x labels for indicating the versions being affected by bugs (and those labels are then mirrored on the PR with "need backport 3.x")

@jinnatar
Copy link

jinnatar commented Dec 6, 2024

FYI, current behavior is to just silently drop cookie data when encountering any unsupported field such as partitioned, which leads to downstream weirdness that's difficult to troubleshoot. In my case it's expecting response cookies to be stored in an aiohttp session and some of them just not getting stored with zero errors. I would have expected an exception to be raised on invalid input.

python -i
Python 3.13.0 experimental free-threading build (main, Oct 16 2024, 03:26:14) [Clang 18.1.8 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from http.cookies import SimpleCookie
>>> c=SimpleCookie()
>>> c.load('TOKEN=foo; path=/; expires=Fri, 06 Dec 2024 18:10:39 GMT; samesite=none; secure; httponly; partitioned;')
>>> c
<SimpleCookie: >
>>> c.load('TOKEN=foo; path=/; expires=Fri, 06 Dec 2024 18:10:39 GMT; samesite=none; secure; httponly;')
>>> c
<SimpleCookie: TOKEN='foo'>

@giles-v
Copy link
Contributor Author

giles-v commented Jan 22, 2025

@merwok @gpshead just wanted to bump #112714 (comment) -- I think the PR to resolve this remains ready for review.

@gpshead gpshead added the 3.14 new features, bugs and security fixes label Jan 24, 2025
@gpshead gpshead moved this from Todo to In Progress in Cookies issues 🍪 Jan 24, 2025
@gpshead
Copy link
Member

gpshead commented Jan 24, 2025

Thanks for your work and patience. the PR is approved and set to automerge!

@gpshead gpshead closed this as completed Jan 24, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in Cookies issues 🍪 Jan 24, 2025
gpshead added a commit that referenced this issue Jan 24, 2025
…H-112714)

* Add support for 'partitioned' attribute in http.cookies

Co-authored-by: Giles Copp <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith [Google LLC] <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
Development

Successfully merging a pull request may close this issue.

8 participants