Skip to content

Commit 4000b93

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: (39 commits) fix merge add missing return type-hints fix merge explicitly mark nullable parameters as nullable fix low deps tests [HttpKernel] Fix datacollector caster for reference object property [Serializer] Fixing PHP warning in the ObjectNormalizer with MaxDepth enabled bug #51578 [Cache] always select database for persistent redis connections [Security] Validate that CSRF token in form login is string similar to username/password [Serializer] Use explicit nullable type [validator] validated Dutch translation Improve dutch translations initialize the current time with midnight before modifying the date [Translation] Skip state=needs-translation entries only when source == target [HttpKernel] Ensure controllers are not lazy [Validator] Fill in trans-unit id 113: This URL does not contain a TLD. [Validator] added missing Polish translation for unit 113 [Validator] add missing lv translation fix tests [HttpClient] Let curl handle transfer encoding ...
2 parents fcee234 + feb9b06 commit 4000b93

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

Authenticator/FormLoginAuthenticator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ private function getCredentials(Request $request): array
143143
throw new BadRequestHttpException(sprintf('The key "%s" must be a non-empty string.', $this->options['password_parameter']));
144144
}
145145

146+
if (!\is_string($credentials['csrf_token'] ?? '') && (!\is_object($credentials['csrf_token']) || !method_exists($credentials['csrf_token'], '__toString'))) {
147+
throw new BadRequestHttpException(sprintf('The key "%s" must be a string, "%s" given.', $this->options['csrf_parameter'], \gettype($credentials['csrf_token'])));
148+
}
149+
146150
return $credentials;
147151
}
148152

Tests/Authenticator/FormLoginAuthenticatorTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,54 @@ public function __toString()
193193
$this->assertSame('s$cr$t', $credentialsBadge->getPassword());
194194
}
195195

196+
/**
197+
* @dataProvider postOnlyDataProvider
198+
*/
199+
public function testHandleNonStringCsrfTokenWithArray($postOnly)
200+
{
201+
$request = Request::create('/login_check', 'POST', ['_username' => 'foo', 'password' => 'bar', '_csrf_token' => []]);
202+
$request->setSession($this->createSession());
203+
204+
$this->setUpAuthenticator(['post_only' => $postOnly]);
205+
206+
$this->expectException(BadRequestHttpException::class);
207+
$this->expectExceptionMessage('The key "_csrf_token" must be a string, "array" given.');
208+
209+
$this->authenticator->authenticate($request);
210+
}
211+
212+
/**
213+
* @dataProvider postOnlyDataProvider
214+
*/
215+
public function testHandleNonStringCsrfTokenWithInt($postOnly)
216+
{
217+
$request = Request::create('/login_check', 'POST', ['_username' => 'foo', 'password' => 'bar', '_csrf_token' => 42]);
218+
$request->setSession($this->createSession());
219+
220+
$this->setUpAuthenticator(['post_only' => $postOnly]);
221+
222+
$this->expectException(BadRequestHttpException::class);
223+
$this->expectExceptionMessage('The key "_csrf_token" must be a string, "integer" given.');
224+
225+
$this->authenticator->authenticate($request);
226+
}
227+
228+
/**
229+
* @dataProvider postOnlyDataProvider
230+
*/
231+
public function testHandleNonStringCsrfTokenWithObject($postOnly)
232+
{
233+
$request = Request::create('/login_check', 'POST', ['_username' => 'foo', 'password' => 'bar', '_csrf_token' => new \stdClass()]);
234+
$request->setSession($this->createSession());
235+
236+
$this->setUpAuthenticator(['post_only' => $postOnly]);
237+
238+
$this->expectException(BadRequestHttpException::class);
239+
$this->expectExceptionMessage('The key "_csrf_token" must be a string, "object" given.');
240+
241+
$this->authenticator->authenticate($request);
242+
}
243+
196244
public static function postOnlyDataProvider()
197245
{
198246
yield [true];

0 commit comments

Comments
 (0)