Skip to content

[HttpFoundation] Support samesite cookies in response #26478

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

Closed
wants to merge 2 commits into from
Closed

[HttpFoundation] Support samesite cookies in response #26478

wants to merge 2 commits into from

Conversation

lstrojny
Copy link
Contributor

@lstrojny lstrojny commented Mar 10, 2018

Q A
Branch? 3.4
Bug fix? yes
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #25344
License MIT
Doc PR n.A.

This hack adds support for samesite cookies in Response::sendHeaders(). One can misuse the path parameter to set the samesite attribute nevertheless.

@staabm
Copy link
Contributor

staabm commented Mar 10, 2018

They might kill your hack in the next php version
php/php-src#3179

@cmb69
Copy link

cmb69 commented Mar 10, 2018

They might kill your hack in the next php version

Note that the PR targets PHP-7.1, since it is supposed to fix a bug.

@staabm
Copy link
Contributor

staabm commented Mar 11, 2018

Maybe you could use or take some inspiration from https://github.com/delight-im/PHP-Cookie

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Mar 12, 2018
@nicolas-grekas
Copy link
Member

The hack might be acceptable if it is tested.

@lstrojny
Copy link
Contributor Author

@nicolas-grekas the best idea I could come up with for a test is an integration test that starts the built-in PHP server and verifies that the header is as expected.

@@ -338,10 +338,11 @@ public function sendHeaders()

// cookies
foreach ($this->headers->getCookies() as $cookie) {
$path = $cookie->getPath().(null !== $cookie->getSameSite() ? ('; samesite='.$cookie->getSameSite()) : '');
Copy link
Member

Choose a reason for hiding this comment

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

I understand that this is a hack needed because of the lack of support of samesite in PHP cookie functions. However, wouldn't it be better to hack this into $cookie->getDomain() instead of $cookie->getPath() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@javiereguiluz the issue is, domain can be null while path will always be something

Copy link
Member

Choose a reason for hiding this comment

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

OK then 👍 ... but @nicolas-grekas proposal may be a better way to solve this? What do you think?

@nicolas-grekas nicolas-grekas changed the title Support samesite cookies in response [HttpFoundation] Support samesite cookies in response Mar 16, 2018
@nicolas-grekas
Copy link
Member

Actually here is another approach I worked on, the discussion might still be relevant: #25348

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 9, 2018

Closing in favor of #25348, thank you @lstrojny

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.

6 participants