Skip to content

Commit 5ee1f8f

Browse files
ajgarlagnicolas-grekas
authored andcommitted
Fix SameSite attribute conversion from PSR7 to HttpFoundation
1 parent 53c15a6 commit 5ee1f8f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Factory/HttpFoundationFactory.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ private function createCookie($cookie)
210210

211211
continue;
212212
}
213+
214+
if ('samesite' === strtolower($name) && null !== $value) {
215+
$samesite = $value;
216+
217+
continue;
218+
}
213219
}
214220

215221
if (!isset($cookieName)) {
@@ -223,7 +229,9 @@ private function createCookie($cookie)
223229
isset($cookiePath) ? $cookiePath : '/',
224230
isset($cookieDomain) ? $cookieDomain : null,
225231
isset($cookieSecure),
226-
isset($cookieHttpOnly)
232+
isset($cookieHttpOnly),
233+
false,
234+
isset($samesite) ? $samesite : null
227235
);
228236
}
229237
}

Tests/Factory/HttpFoundationFactoryTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\Stream;
2020
use Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\UploadedFile;
2121
use Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\Uri;
22+
use Symfony\Component\HttpFoundation\Cookie;
2223

2324
/**
2425
* @author Kévin Dunglas <dunglas@gmail.com>
@@ -199,7 +200,7 @@ public function testCreateResponse()
199200
'Set-Cookie' => array(
200201
'theme=light',
201202
'test',
202-
'ABC=AeD; Domain=dunglas.fr; Path=/kevin; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Secure; HttpOnly',
203+
'ABC=AeD; Domain=dunglas.fr; Path=/kevin; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Secure; HttpOnly; SameSite=Strict',
203204
),
204205
),
205206
new Stream('The response body'),
@@ -230,6 +231,9 @@ public function testCreateResponse()
230231
$this->assertEquals('/kevin', $cookies[2]->getPath());
231232
$this->assertTrue($cookies[2]->isSecure());
232233
$this->assertTrue($cookies[2]->isHttpOnly());
234+
if (defined('Symfony\Component\HttpFoundation\Cookie::SAMESITE_STRICT')) {
235+
$this->assertEquals(Cookie::SAMESITE_STRICT, $cookies[2]->getSameSite());
236+
}
233237

234238
$this->assertEquals('The response body', $symfonyResponse->getContent());
235239
$this->assertEquals(200, $symfonyResponse->getStatusCode());

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy