From 14c310f5fb8ee6cb0f7ae5c8c8f8aa5a894af844 Mon Sep 17 00:00:00 2001 From: Mike Francis Date: Wed, 19 Jul 2017 12:17:30 +0100 Subject: [PATCH] Fix case sensitive sameSite cookie --- src/Symfony/Component/HttpFoundation/Cookie.php | 4 ++++ src/Symfony/Component/HttpFoundation/Tests/CookieTest.php | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Cookie.php b/src/Symfony/Component/HttpFoundation/Cookie.php index 492c6fbe75..5ea881c6e3 100644 --- a/src/Symfony/Component/HttpFoundation/Cookie.php +++ b/src/Symfony/Component/HttpFoundation/Cookie.php @@ -77,6 +77,10 @@ class Cookie $this->httpOnly = (bool) $httpOnly; $this->raw = (bool) $raw; + if (null !== $sameSite) { + $sameSite = strtolower($sameSite); + } + if (!in_array($sameSite, array(self::SAMESITE_LAX, self::SAMESITE_STRICT, null), true)) { throw new \InvalidArgumentException('The "sameSite" parameter value is not valid.'); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php index 3986a7e8f8..ad6d3f508c 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php @@ -180,4 +180,10 @@ class CookieTest extends TestCase $this->assertTrue($cookie->isRaw()); $this->assertEquals('foo=b+a+r; path=/', (string) $cookie); } + + public function testSameSiteAttributeIsCaseInsensitive() + { + $cookie = new Cookie('foo', 'bar', 0, '/', null, false, true, false, 'Lax'); + $this->assertEquals('lax', $cookie->getSameSite()); + } }