Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpFoundation][HttpKernel] Configure session.cookie_secure earlier #40231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ public function setOptions(array $options)
$this->emulateSameSite = $value;
continue;
}
if ('cookie_secure' === $key && 'auto' === $value) {
continue;
}
ini_set('url_rewriter.tags' !== $key ? 'session.'.$key : $key, $value);
}
}
Expand Down
16 changes: 13 additions & 3 deletions 16 src/Symfony/Component/HttpKernel/EventListener/SessionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Psr\Container\ContainerInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

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

protected function getSession(): ?SessionInterface
public function onKernelRequest(GetResponseEvent $event)
jderusse marked this conversation as resolved.
Show resolved Hide resolved
{
if (!$this->container->has('session')) {
return null;
parent::onKernelRequest($event);

if (!$event->isMasterRequest() || !$this->container->has('session')) {
return;
}

if ($this->container->has('session_storage')
Expand All @@ -46,6 +49,13 @@ protected function getSession(): ?SessionInterface
) {
$storage->setOptions(['cookie_secure' => true]);
}
}

protected function getSession(): ?SessionInterface
{
if (!$this->container->has('session')) {
return null;
}

return $this->container->get('session');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testSessionIsSet()
$listener = new SessionListener($container);

$event = $this->createMock(RequestEvent::class);
$event->expects($this->once())->method('isMasterRequest')->willReturn(true);
$event->expects($this->exactly(2))->method('isMasterRequest')->willReturn(true);
$event->expects($this->once())->method('getRequest')->willReturn($request);

$listener->onKernelRequest($event);
Expand Down Expand Up @@ -203,12 +203,16 @@ public function testGetSessionIsCalledOnce()
$listener = new SessionListener($container);
$listener->onKernelRequest($event);

// storage->setOptions() should have been called already
$container->set('session_storage', null);
$sessionStorage = null;

$subRequest = $masterRequest->duplicate();
// at this point both master and subrequest have a closure to build the session

$masterRequest->getSession();

// calling the factory on the subRequest should not trigger a second call to storage->sesOptions()
// calling the factory on the subRequest should not trigger a second call to storage->setOptions()
$subRequest->getSession();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.