Skip to content

Commit 86d83ce

Browse files
committed
Session: by default uses sameSite: Lax (BC break)
1 parent 9f791c6 commit 86d83ce

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

src/Http/Session.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Session
3939
// cookies
4040
'cookie_lifetime' => 0, // until the browser is closed
4141
'cookie_httponly' => true, // must be enabled to prevent Session Hijacking
42+
'cookie_samesite' => 'Lax', // must be enabled to prevent CSRF
4243

4344
// other
4445
'gc_maxlifetime' => self::DEFAULT_FILE_LIFETIME, // 3 hours

tests/Http.DI/SessionExtension.config.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $container->getService('session')->start();
3737

3838
Assert::same(
3939
PHP_VERSION_ID >= 70300
40-
? ['lifetime' => 0, 'path' => '/x', 'domain' => 'nette.org', 'secure' => true, 'httponly' => true, 'samesite' => '']
41-
: ['lifetime' => 0, 'path' => '/x', 'domain' => 'nette.org', 'secure' => true, 'httponly' => true],
40+
? ['lifetime' => 0, 'path' => '/x', 'domain' => 'nette.org', 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']
41+
: ['lifetime' => 0, 'path' => '/x; SameSite=Lax', 'domain' => 'nette.org', 'secure' => true, 'httponly' => true],
4242
session_get_cookie_params()
4343
);

tests/Http/Session.cookies.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Assert::same([
2525
'use_trans_sid' => 0,
2626
'cookie_lifetime' => 0,
2727
'cookie_httponly' => true,
28+
'cookie_samesite' => 'Lax',
2829
'gc_maxlifetime' => 10800,
2930
'cookie_path' => '/user/',
3031
'cookie_domain' => 'nette.org',

tests/Http/Session.sameSite.phpt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ if (PHP_SAPI === 'cli') {
1515
$factory = new Nette\Http\RequestFactory;
1616
$session = new Nette\Http\Session($factory->createHttpRequest(), new Nette\Http\Response);
1717

18-
$session->setOptions([
19-
'cookie_samesite' => 'Lax',
20-
]);
21-
18+
// is samesite=Lax by default
2219
$session->start();
2320

2421
Assert::contains(

tests/Http/Session.setOptions.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Assert::same([
2222
'use_trans_sid' => 0,
2323
'cookie_lifetime' => 0,
2424
'cookie_httponly' => true,
25+
'cookie_samesite' => 'Lax',
2526
'gc_maxlifetime' => 10800,
2627
'cookie_path' => '/',
2728
'cookie_domain' => '',
@@ -39,6 +40,7 @@ Assert::same([
3940
'use_trans_sid' => 0,
4041
'cookie_lifetime' => 0,
4142
'cookie_httponly' => true,
43+
'cookie_samesite' => 'Lax',
4244
'gc_maxlifetime' => 10800,
4345
'cookie_path' => '/',
4446
'cookie_secure' => false,
@@ -55,6 +57,7 @@ Assert::same([
5557
'use_trans_sid' => 0,
5658
'cookie_lifetime' => 0,
5759
'cookie_httponly' => true,
60+
'cookie_samesite' => 'Lax',
5861
'gc_maxlifetime' => 10800,
5962
'cookie_path' => '/',
6063
'cookie_secure' => false,

0 commit comments

Comments
 (0)