Skip to content

Commit

Permalink
Merge pull request #4371 from kenjis/fix-cookieSameSite
Browse files Browse the repository at this point in the history
Fix Undefined property: Config\App::$cookieSameSite
  • Loading branch information
paulbalandan committed Mar 2, 2021
2 parents b951050 + 31ccc2f commit 906d251
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions system/HTTP/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ public function __construct($config)
$this->cookieHTTPOnly = $config->cookieHTTPOnly;
$this->cookieSameSite = $config->cookieSameSite ?? Cookie::SAMESITE_LAX;

$config->cookieSameSite = $config->cookieSameSite ?? Cookie::SAMESITE_LAX;

if (! in_array(strtolower($config->cookieSameSite ?: Cookie::SAMESITE_LAX), Cookie::ALLOWED_SAMESITE_VALUES, true))
{
throw CookieException::forInvalidSameSite($config->cookieSameSite);
Expand Down
16 changes: 16 additions & 0 deletions tests/system/HTTP/ResponseCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@ public function testCookieBlankSetSameSite()
$this->assertSame('', $allCookies['bar;;/']->getSameSite());
}

public function testCookieWithoutSameSite()
{
$config = new App();
unset($config->cookieSameSite);
$response = new Response($config);
$response->setCookie([
'name' => 'bar',
'value' => 'foo',
]);

$allCookies = $response->getCookies();
$this->assertCount(1, $allCookies);
$this->assertInstanceOf(Cookie::class, $allCookies['bar;;/']);
$this->assertSame('Lax', $allCookies['bar;;/']->getSameSite());
}

public function testCookieStrictSameSite()
{
$config = new App();
Expand Down

0 comments on commit 906d251

Please sign in to comment.