Skip to content

Commit af08358

Browse files
committed
Session: added support for SameSite cookie
1 parent 6178788 commit af08358

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/Http/Session.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ private function configure(array $config): void
400400
}
401401

402402
if ($cookie !== $origCookie) {
403+
if (isset($cookie['samesite'])) {
404+
$cookie['path'] .= '; SameSite=' . $cookie['samesite'];
405+
}
403406
session_set_cookie_params(
404407
$cookie['lifetime'], $cookie['path'], $cookie['domain'],
405408
$cookie['secure'], $cookie['httponly']

tests/Http/Session.sameSite.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Tester\Assert;
6+
7+
8+
require __DIR__ . '/../bootstrap.php';
9+
10+
if (PHP_SAPI === 'cli') {
11+
Tester\Environment::skip('Cookies are not available in CLI');
12+
}
13+
14+
15+
$factory = new Nette\Http\RequestFactory;
16+
$session = new Nette\Http\Session($factory->createHttpRequest(), new Nette\Http\Response);
17+
18+
$session->setOptions([
19+
'cookie_samesite' => 'Lax',
20+
]);
21+
22+
$session->start();
23+
24+
Assert::contains(
25+
'Set-Cookie: PHPSESSID=' . $session->getId() . '; path=/; SameSite=Lax; HttpOnly',
26+
headers_list()
27+
);

0 commit comments

Comments
 (0)