Skip to content

[RFC] partitioned option for setcookie/setrawcookie and sessions - #12652

Closed
ndossche wants to merge 2 commits into
php:masterfrom
ndossche:cookie-partitioned
Closed

[RFC] partitioned option for setcookie/setrawcookie and sessions#12652
ndossche wants to merge 2 commits into
php:masterfrom
ndossche:cookie-partitioned

Conversation

@ndossche

@ndosschendossche commented Nov 10, 2023

Copy link
Copy Markdown
Member

@iluuu1994

Copy link
Copy Markdown
Member

Partitioned cookies are marked as experimental by Mozilla (https://developer.mozilla.org/en-US/docs/Web/Privacy/Partitioned_cookies). Theoretically this means they are subject to change. It seems they're mostly pushed by Google.

I'm also unsure about the premise of the original issue:

As stated here (link), soon our cookies with SameSite=None; Secured, without the Partitioned parameter, will stop working.

I haven't tested this, but I think what this means is that Partitioned will essentially become the default, unless the domains are part of the same related website set. So I think this is essentially just an opt-in mechanism to ensure the cookies keep working? Related website sets are managed in a GitHub repository (https://github.com/GoogleChrome/related-website-sets). Thank you, Google, for that one. 😒

Maybe this warrants a short e-mail to the ML? I'm not a specialist in regards to cookies. Maybe other people have something to add.

@DustinAPI

Copy link
Copy Markdown

@nielsdos I am attempting to implement CHIPS for my app with an ugly workaround manually setting the cookie header so this PR would be very helpful but I think it should also include changes to the session cookie to truly allow developers to fix the problem.

session_set_cookie_params(['partitioned' => true])
['partitioned' => true]) = session_get_cookie_params()
ini_set('session.cookie_partitioned', 'on');

My use case is the most basic wherin my app (tool) is displayed in an iframe within a learning management system (LMS) and requires a session cookie for further interaction after the inital LTI launch.

@morsssss

Copy link
Copy Markdown
Contributor

Partitioned cookies are marked as experimental by Mozilla (https://developer.mozilla.org/en-US/docs/Web/Privacy/Partitioned_cookies). Theoretically this means they are subject to change. It seems they're mostly pushed by Google.

AFAIK, Mozilla and Safari have experimented with similar ideas, but right now only Chrome supports the Partitioned attribute. Chrome's goal is to let developers opt in to partitioning, instead of doing it by default.

As stated here (link), soon our cookies with SameSite=None; Secured, without the Partitioned parameter, will stop working.

I haven't tested this, but I think what this means is that Partitioned will essentially become the default, unless the domains are part of the same related website set. So I think this is essentially just an opt-in mechanism to ensure the cookies keep working?

That's it indeed! Chrome just started an experiment, now active for 1% of users, in which it will block third-party cookies that lack the Partitioned attribute and that are not allowed by other means. When a third-party site sets a Partitioned cookie, Chrome allows that site to access the cookie when it's embedded on a page from the domain where it was set. Access from other domains is blocked.

If this experiment results in a launch down the road, I think plenty of developers will want to use Partitioned, even though right now it's only a Chrome thing.

@ndossche

Copy link
Copy Markdown
MemberAuthor

@nielsdos I am attempting to implement CHIPS for my app with an ugly workaround manually setting the cookie header so this PR would be very helpful but I think it should also include changes to the session cookie to truly allow developers to fix the problem.

session_set_cookie_params(['partitioned' => true]) ['partitioned' => true]) = session_get_cookie_params() ini_set('session.cookie_partitioned', 'on');

My use case is the most basic wherin my app (tool) is displayed in an iframe within a learning management system (LMS) and requires a session cookie for further interaction after the inital LTI launch.

Yeah, I fear that the scope of this must be increased, and ini settings are probably necessary too.
That would mean this needs an RFC, which I can do, but I'm busy with other PHP work right now.

@bukka

Copy link
Copy Markdown
Member

I think we should probably have RFC for this as the agreement is not clear (Derick raised some concerns on internals) so I don't think we can just merge this.

@ndosschendossche changed the title Implement proof-of-concept partitioned option for setcookie[RFC] partitioned option for setcookie/setrawcookieJul 13, 2025
@ndossche
ndosscheforce-pushed the cookie-partitioned branch from e609e44 to 744fd4cCompareJuly 14, 2025 17:56
@ndossche
ndossche requested a review from Girgias as a code ownerJuly 14, 2025 19:58
@ndosschendossche changed the title [RFC] partitioned option for setcookie/setrawcookie[RFC] partitioned option for setcookie/setrawcookie and sessionsJul 14, 2025
@xepozz

Copy link
Copy Markdown
Contributor

LGTM

Comment threadext/session/session.c Outdated
Comment threadext/session/session.c Outdated

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.

It already looks misaligned, so let's have the space after comma:

Suggested change
STD_PHP_INI_BOOLEAN("session.cookie_partitioned","0",PHP_INI_ALL, OnUpdateSessionBool, cookie_partitioned, php_ps_globals, ps_globals)
STD_PHP_INI_BOOLEAN("session.cookie_partitioned","0", PHP_INI_ALL, OnUpdateSessionBool, cookie_partitioned, php_ps_globals, ps_globals)

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I'll just add a commit to reformat this table. But a separate commit for history reasons...

Comment threadext/session/session.c Outdated

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.

Using false/true here is inconsistent with the rest and also with the reassignment in line 1809. This should be unified one way or another.

Independent of this, this should probably be fixed once and for all with a tree-wide Coccinelle run. Something like:

 @@
bool b;
@@
- b = 1
+ b = true
@@
bool b;
@@
- b = 0
+ b = false

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I'll fix this for ext/session post-merge as a follow up

@TimWollaTimWollaAug 12, 2025

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'll fix this for ext/session post-merge as a follow up

Would do this tree-wide (possibly with per-extension commits) to not fix this piecemeal. See also: #19418 (comment)

A good opportunity might be right when branching PHP 8.5.

@TimWolla

Copy link
Copy Markdown
Member

Vote seems exceedingly likely to pass and the implementation is good except for minor nits, thus already requesting RM review as per https://externals.io/message/128453.

@TimWolla
TimWolla requested a review from a teamAugust 12, 2025 16:39
@ndossche

Copy link
Copy Markdown
MemberAuthor

Vote was accepted

@TimWollaTimWolla left a comment

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.

Previous remarks are just nits without an effect on functionality, so this should've been an approval.

@edorianedorian left a comment

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.

No RM objections 👍

nicolas-grekas added a commit to symfony/symfony that referenced this pull request Aug 20, 2025
…n PHP 8.5 (xabbuh)
This PR was merged into the 6.4 branch.
Discussion
----------
[HttpFoundation] fix session cookie options assertions on PHP 8.5
| Q | A
| ------------- | ---
| Branch? | 6.4
| Bug fix? | no
| New feature? | no
| Deprecations? | no
| Issues |
| License | MIT
see php/php-src#12652
Commits
-------
3c7a8ac fix session cookie options assertions on PHP 8.5
Sign up for freeto 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.

9 participants

@ndossche@iluuu1994@DustinAPI@morsssss@bukka@xepozz@TimWolla@edorian@Girgias