Skip to content

Commit 915d881

Browse files
committed
feature #28168 Add SameSite cookies to FrameWorkBundle (rpkamp)
This PR was merged into the 4.2-dev branch. Discussion ---------- Add SameSite cookies to FrameWorkBundle | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes, and added to changelog https://github.com/symfony/symfony/pull/28168/files#diff-276f5b13978c2ce3f555b9603f44801aR21 | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27631 | License | MIT | Doc PR | symfony/symfony-docs#10202 Uses `session.cookie_samesite` for PHP >= 7.3. For PHP < 7.3 it first does a session_start(), find the emitted header, changes it, and emits it again with the value for SameSite added. I also tried it in a minimal Symfony 4.1 app, and works there too: ![screenshot from 2018-08-08 21-39-10](https://user-images.githubusercontent.com/1059790/43864708-b7437978-9b60-11e8-81dd-b41f1a5afb52.png) Commits ------- 4091feb693 Add SameSite cookies to FrameWorkBundle
2 parents 64ba59f + 947c229 commit 915d881

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ CHANGELOG
2929
* Deprecated `Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser`
3030
* The `container.service_locator` tag of `ServiceLocator`s is now autoconfigured.
3131
* Add the ability to search a route in `debug:router`.
32+
* Add the ability to use SameSite cookies for sessions.
3233

3334
4.0.0
3435
-----

DependencyInjection/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
2020
use Symfony\Component\Config\Definition\ConfigurationInterface;
2121
use Symfony\Component\Form\Form;
22+
use Symfony\Component\HttpFoundation\Cookie;
2223
use Symfony\Component\Lock\Lock;
2324
use Symfony\Component\Lock\Store\SemaphoreStore;
2425
use Symfony\Component\Messenger\MessageBusInterface;
@@ -484,6 +485,7 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
484485
->scalarNode('cookie_domain')->end()
485486
->enumNode('cookie_secure')->values(array(true, false, 'auto'))->end()
486487
->booleanNode('cookie_httponly')->defaultTrue()->end()
488+
->enumNode('cookie_samesite')->values(array(null, Cookie::SAMESITE_LAX, Cookie::SAMESITE_STRICT))->defaultNull()->end()
487489
->booleanNode('use_cookies')->end()
488490
->scalarNode('gc_divisor')->end()
489491
->scalarNode('gc_probability')->defaultValue(1)->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
757757
// session storage
758758
$container->setAlias('session.storage', $config['storage_id'])->setPrivate(true);
759759
$options = array('cache_limiter' => '0');
760-
foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'use_cookies', 'gc_maxlifetime', 'gc_probability', 'gc_divisor') as $key) {
760+
foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'cookie_samesite', 'use_cookies', 'gc_maxlifetime', 'gc_probability', 'gc_divisor') as $key) {
761761
if (isset($config[$key])) {
762762
$options[$key] = $config[$key];
763763
}

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ protected static function getBundleDefaultConfig()
232232
'storage_id' => 'session.storage.native',
233233
'handler_id' => 'session.handler.native_file',
234234
'cookie_httponly' => true,
235+
'cookie_samesite' => null,
235236
'gc_probability' => 1,
236237
'save_path' => '%kernel.cache_dir%/sessions',
237238
'metadata_update_threshold' => '0',

0 commit comments

Comments
 (0)