Skip to content

gh-112713 : Add support for 'partitioned' attribute in http.cookies#112714

Merged
gpshead merged 22 commits into
python:mainfrom
giles-v:add-cookies-partitioned-support
Jan 24, 2025
Merged

gh-112713 : Add support for 'partitioned' attribute in http.cookies#112714
gpshead merged 22 commits into
python:mainfrom
giles-v:add-cookies-partitioned-support

Conversation

@giles-v

@giles-v giles-v commented Dec 4, 2023

Copy link
Copy Markdown
Contributor

Fixes #112713.

This PR adds support for the new Partitioned attribute in the Morsel object in http.cookies.


📚 Documentation preview 📚: https://cpython-previews--112714.org.readthedocs.build/

@ghost

ghost commented Dec 4, 2023

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app

bedevere-app Bot commented Dec 4, 2023

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app

bedevere-app Bot commented Dec 4, 2023

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Comment thread Doc/library/http.cookies.rst Outdated
The attribute :attr:`partitioned` indicates to user agents that these
cross-site cookies *should* only be available in the same top-level context
that the cookie was first set in. For this to be accepted by the user agent,
you **must** also set both ``Secure`` and ``Path=/``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I updated the wording here to clarify that Secure is required... but the CHIPS spec doesn't explicitly say anything about Path= though Path=/ appears in all of its examples. What wording should be used regarding Path, I'm not sure how I've phrased this is wholly accurate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Per privacycg/CHIPS#49, Path=/ is not needed. I'm going to push an update to this PR shortly.

Comment thread Lib/test/test_http_cookies.py
@gpshead gpshead added the 3.13 bugs and security fixes label Feb 14, 2024
@gpshead gpshead added type-feature A feature request or enhancement and removed DO-NOT-MERGE 3.13 bugs and security fixes labels Feb 14, 2024
@gpshead gpshead marked this pull request as draft February 14, 2024 06:31
@gpshead gpshead removed their assignment Feb 14, 2024
@gpshead

gpshead commented Feb 14, 2024

Copy link
Copy Markdown
Member

I'm leaving this as a Draft PR as whether or not this is desirable isn't settled - it is not yet a standard. We normally wait until something sees actual accepted adoption.

@giles-v

giles-v commented Feb 15, 2024

Copy link
Copy Markdown
Contributor Author

Understood that CHIPS is a draft and that it probably makes sense to wait until it's ratified before adding to the stdlib. My understanding from reading the RFCs is that it has tentative support from Mozilla and Apple, so hopefully it will be mergeable whenever the wheels of the working groups turn! :)

I want to address this comment from #112713 by @gpshead:

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?

We are planning to provide a custom patch which does something like this (figuratively):

original_morsel_output = Cookie.Morsel.output

def patched_morsel_output(
    self: _MorselType,
    attrs: Optional[List[str]] = None,
    header: str = "Set-Cookie:",
):
    cookie_str = original_morsel_output(self, attrs, header)
    if "samesite=none" in cookie_str.lower():
        cookie_str += "; Partitioned"
    return cookie_str

Cookie.Morsel.output = patched_morsel_output

It's not ideal, but gives us space to also extend the stdlib in other ways since we'll be importing this instead of http.cookie from now on anyway.

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

merwok commented Feb 21, 2024

Copy link
Copy Markdown
Member

@giles-v Please note that discussions on PRs should be about the implementation; wider discussion about the request itself happens on the issue or on python-ideas.

@merwok

merwok commented Sep 9, 2024

Copy link
Copy Markdown
Member

This has missed the beta window, but I think an argument could be made to core-devs and RM on discuss that this change is useful to deal with an external standard. (I don’t have the time to be the one to do that)

We’ve had such a policy for changes to mimetypes for example. On the other hand, this is not a simple addition to a data dictionary, but a code change which we would not backport to stable branches, so the reply could be negative.

(Thanks for the gardening picnixz. GPS added the label, not I)

@giles-v

giles-v commented Sep 9, 2024

Copy link
Copy Markdown
Contributor Author

This has missed the beta window, but I think an argument could be made to core-devs and RM on discuss that this change is useful to deal with an external standard. (I don’t have the time to be the one to do that)

I would be glad to support such an argument if it's public; given the timeline of Google's CHIPS adoption, waiting for the next release is going to be onerous for users. As someone who has not engaged with the Python community before however I don't think I have any standing to drive a discussion like that either.

@picnixz

picnixz commented Sep 9, 2024

Copy link
Copy Markdown
Member

this change is useful to deal with an external standard

In this case, this could be categorized as type-security/bug fix (bugfixes would get backported to 3.12 and security fixes until 3.8) cc @Yhg1s

@merwok

merwok commented Sep 9, 2024

Copy link
Copy Markdown
Member

I think arguing for this feature as a security fix would go too far.

@giles-v

giles-v commented Dec 10, 2024

Copy link
Copy Markdown
Contributor Author

@merwok @gpshead let me know if anything else is needed to get this approved. Sorry for delays on responding to your comments.

@giles-v

giles-v commented Jan 24, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for the review @merwok -- are you able to merge also?

@gpshead gpshead enabled auto-merge (squash) January 24, 2025 22:26
@gpshead gpshead merged commit 9abbb58 into python:main Jan 24, 2025
@merwok

merwok commented Jan 24, 2025

Copy link
Copy Markdown
Member

I wanted a second review, not being an expert on the cookie module. Thanks gps!

@ulgens

ulgens commented Feb 16, 2026

Copy link
Copy Markdown

I was checking https://docs.python.org/3/whatsnew/3.14.html#http but couldn't find a mention of this change. Is it actually missing from the changelog or should I be looking for it in a different place?

ulgens added a commit to ulgens/cadwyn that referenced this pull request Feb 16, 2026
@Yhg1s

Yhg1s commented Feb 17, 2026

Copy link
Copy Markdown
Member

I was checking https://docs.python.org/3/whatsnew/3.14.html#http but couldn't find a mention of this change. Is it actually missing from the changelog or should I be looking for it in a different place?

It's not mentioned in What's New, but it is in the changelog: https://docs.python.org/3.14/whatsnew/changelog.html#id140

ulgens added a commit to ulgens/cadwyn that referenced this pull request Feb 17, 2026
ulgens added a commit to ulgens/cadwyn that referenced this pull request Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Partitioned cookies attribute

8 participants