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

Commit 9bb1230

Browse filesBrowse files
koenreiniersnicolas-grekas
authored andcommitted
[Security] Check if firewall is stateless before checking for session/previous session
1 parent 5b5b61f commit 9bb1230
Copy full SHA for 9bb1230

File tree

Expand file treeCollapse file tree

2 files changed

+20
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-1
lines changed

‎src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function setSessionAuthenticationStrategy(SessionAuthenticationStrategyIn
134134

135135
private function migrateSession(Request $request, TokenInterface $token, $providerKey)
136136
{
137-
if (!$this->sessionStrategy || !$request->hasSession() || !$request->hasPreviousSession() || \in_array($providerKey, $this->statelessProviderKeys, true)) {
137+
if (\in_array($providerKey, $this->statelessProviderKeys, true) || !$this->sessionStrategy || !$request->hasSession() || !$request->hasPreviousSession()) {
138138
return;
139139
}
140140

‎src/Symfony/Component/Security/Guard/Tests/GuardAuthenticatorHandlerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Guard/Tests/GuardAuthenticatorHandlerTest.php
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,25 @@ public function testSessionStrategyIsNotCalledWhenStateless()
149149
$handler->authenticateWithToken($this->token, $this->request, 'some_provider_key');
150150
}
151151

152+
/**
153+
* @requires function \Symfony\Component\HttpFoundation\Request::setSessionFactory
154+
*/
155+
public function testSessionIsNotInstantiatedOnStatelessFirewall()
156+
{
157+
$sessionFactory = $this->getMockBuilder(\stdClass::class)
158+
->setMethods(['__invoke'])
159+
->getMock();
160+
161+
$sessionFactory->expects($this->never())
162+
->method('__invoke');
163+
164+
$this->request->setSessionFactory($sessionFactory);
165+
166+
$handler = new GuardAuthenticatorHandler($this->tokenStorage, $this->dispatcher, ['stateless_provider_key']);
167+
$handler->setSessionAuthenticationStrategy($this->sessionStrategy);
168+
$handler->authenticateWithToken($this->token, $this->request, 'stateless_provider_key');
169+
}
170+
152171
protected function setUp()
153172
{
154173
$this->tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.