Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0016095

Browse files
committed
Do not overwrite the current setting in session storage if cookie_secure is set to auto, and resolve this auto value immediately when the SessionListener event is called.
1 parent 9765b5a commit 0016095

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ public function setOptions(array $options)
389389
$this->emulateSameSite = $value;
390390
continue;
391391
}
392+
if ('cookie_secure' === $key && 'auto' === $value) {
393+
// Do not overwrite existing setting if the cookie_secure value is "auto".
394+
continue;
395+
}
392396
ini_set('url_rewriter.tags' !== $key ? 'session.'.$key : $key, $value);
393397
}
394398
}

src/Symfony/Component/HttpKernel/EventListener/SessionListener.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Psr\Container\ContainerInterface;
1515
use Symfony\Component\HttpFoundation\Session\SessionInterface;
1616
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
17+
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1718

1819
/**
1920
* Sets the session in the request.
@@ -33,10 +34,12 @@ public function __construct(ContainerInterface $container)
3334
$this->container = $container;
3435
}
3536

36-
protected function getSession(): ?SessionInterface
37+
public function onKernelRequest(GetResponseEvent $event)
3738
{
38-
if (!$this->container->has('session')) {
39-
return null;
39+
parent::onKernelRequest($event);
40+
41+
if (!$event->isMasterRequest() || !$this->container->has('session')) {
42+
return;
4043
}
4144

4245
if ($this->container->has('session_storage')
@@ -46,6 +49,13 @@ protected function getSession(): ?SessionInterface
4649
) {
4750
$storage->setOptions(['cookie_secure' => true]);
4851
}
52+
}
53+
54+
protected function getSession(): ?SessionInterface
55+
{
56+
if (!$this->container->has('session')) {
57+
return null;
58+
}
4959

5060
return $this->container->get('session');
5161
}

0 commit comments

Comments
 (0)