Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit 962860f

Browse files
Merge branch '3.4' into 4.4
* 3.4: [Http Foundation] Fix clear cookie samesite [Security] Check if firewall is stateless before checking for session/previous session [Form] Support customized intl php.ini settings [Security] Remember me: allow to set the samesite cookie flag [Debug] fix for PHP 7.3.16+/7.4.4+ [Validator] Backport translations Prevent warning in proc_open()
2 parents 45017e8 + 06a4e09 commit 962860f

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

Guard/GuardAuthenticatorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function setSessionAuthenticationStrategy(SessionAuthenticationStrategyIn
127127

128128
private function migrateSession(Request $request, TokenInterface $token, ?string $providerKey)
129129
{
130-
if (!$this->sessionStrategy || !$request->hasSession() || !$request->hasPreviousSession() || \in_array($providerKey, $this->statelessProviderKeys, true)) {
130+
if (\in_array($providerKey, $this->statelessProviderKeys, true) || !$this->sessionStrategy || !$request->hasSession() || !$request->hasPreviousSession()) {
131131
return;
132132
}
133133

Guard/Tests/GuardAuthenticatorHandlerTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,25 @@ public function testSessionStrategyIsNotCalledWhenStateless()
153153
$handler->authenticateWithToken($this->token, $this->request, 'some_provider_key');
154154
}
155155

156+
/**
157+
* @requires function \Symfony\Component\HttpFoundation\Request::setSessionFactory
158+
*/
159+
public function testSessionIsNotInstantiatedOnStatelessFirewall()
160+
{
161+
$sessionFactory = $this->getMockBuilder(\stdClass::class)
162+
->setMethods(['__invoke'])
163+
->getMock();
164+
165+
$sessionFactory->expects($this->never())
166+
->method('__invoke');
167+
168+
$this->request->setSessionFactory($sessionFactory);
169+
170+
$handler = new GuardAuthenticatorHandler($this->tokenStorage, $this->dispatcher, ['stateless_provider_key']);
171+
$handler->setSessionAuthenticationStrategy($this->sessionStrategy);
172+
$handler->authenticateWithToken($this->token, $this->request, 'stateless_provider_key');
173+
}
174+
156175
protected function setUp(): void
157176
{
158177
$this->tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock();

Http/RememberMe/AbstractRememberMeServices.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ abstract class AbstractRememberMeServices implements RememberMeServicesInterface
3939
protected $options = [
4040
'secure' => false,
4141
'httponly' => true,
42+
'samesite' => null,
4243
];
4344
private $providerKey;
4445
private $secret;
@@ -276,7 +277,7 @@ protected function cancelCookie(Request $request)
276277
$this->logger->debug('Clearing remember-me cookie.', ['name' => $this->options['name']]);
277278
}
278279

279-
$request->attributes->set(self::COOKIE_ATTR_NAME, new Cookie($this->options['name'], null, 1, $this->options['path'], $this->options['domain'], $this->options['secure'] ?? $request->isSecure(), $this->options['httponly'], false, $this->options['samesite'] ?? null));
280+
$request->attributes->set(self::COOKIE_ATTR_NAME, new Cookie($this->options['name'], null, 1, $this->options['path'], $this->options['domain'], $this->options['secure'] ?? $request->isSecure(), $this->options['httponly'], false, $this->options['samesite']));
280281
}
281282

282283
/**

Http/RememberMe/PersistentTokenBasedRememberMeServices.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected function processAutoLoginCookie(array $cookieParts, Request $request)
8686
$this->options['secure'] ?? $request->isSecure(),
8787
$this->options['httponly'],
8888
false,
89-
$this->options['samesite'] ?? null
89+
$this->options['samesite']
9090
)
9191
);
9292

@@ -121,7 +121,7 @@ protected function onLoginSuccess(Request $request, Response $response, TokenInt
121121
$this->options['secure'] ?? $request->isSecure(),
122122
$this->options['httponly'],
123123
false,
124-
$this->options['samesite'] ?? null
124+
$this->options['samesite']
125125
)
126126
);
127127
}

Http/RememberMe/TokenBasedRememberMeServices.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function onLoginSuccess(Request $request, Response $response, TokenInt
8383
$this->options['secure'] ?? $request->isSecure(),
8484
$this->options['httponly'],
8585
false,
86-
$this->options['samesite'] ?? null
86+
$this->options['samesite']
8787
)
8888
);
8989
}

0 commit comments

Comments
 (0)