Skip to content

Commit 1ebe28f

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: explicitly mark nullable parameters as nullable fix low deps tests [HttpKernel] Fix datacollector caster for reference object property bug #51578 [Cache] always select database for persistent redis connections [Security] Validate that CSRF token in form login is string similar to username/password [validator] validated Dutch translation Improve dutch translations [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 [HttpClient] Let curl handle transfer encoding [Messenger] Make Doctrine connection ignore unrelated tables on setup [HttpFoundation] Set content-type header in RedirectResponse add translations for the requireTld constraint option message [Serializer] Fix unexpected allowed attributes [FrameworkBundle] Fix registration of the bundle path to translation
2 parents bf75489 + 9d9ff86 commit 1ebe28f

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
@@ -135,6 +135,10 @@ private function getCredentials(Request $request): array
135135
throw new BadRequestHttpException(sprintf('The key "%s" must be a string, "%s" given.', $this->options['password_parameter'], \gettype($credentials['password'])));
136136
}
137137

138+
if (!\is_string($credentials['csrf_token'] ?? '') && (!\is_object($credentials['csrf_token']) || !method_exists($credentials['csrf_token'], '__toString'))) {
139+
throw new BadRequestHttpException(sprintf('The key "%s" must be a string, "%s" given.', $this->options['csrf_parameter'], \gettype($credentials['csrf_token'])));
140+
}
141+
138142
return $credentials;
139143
}
140144

Tests/Authenticator/FormLoginAuthenticatorTest.php

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

168+
/**
169+
* @dataProvider postOnlyDataProvider
170+
*/
171+
public function testHandleNonStringCsrfTokenWithArray($postOnly)
172+
{
173+
$request = Request::create('/login_check', 'POST', ['_username' => 'foo', 'password' => 'bar', '_csrf_token' => []]);
174+
$request->setSession($this->createSession());
175+
176+
$this->setUpAuthenticator(['post_only' => $postOnly]);
177+
178+
$this->expectException(BadRequestHttpException::class);
179+
$this->expectExceptionMessage('The key "_csrf_token" must be a string, "array" given.');
180+
181+
$this->authenticator->authenticate($request);
182+
}
183+
184+
/**
185+
* @dataProvider postOnlyDataProvider
186+
*/
187+
public function testHandleNonStringCsrfTokenWithInt($postOnly)
188+
{
189+
$request = Request::create('/login_check', 'POST', ['_username' => 'foo', 'password' => 'bar', '_csrf_token' => 42]);
190+
$request->setSession($this->createSession());
191+
192+
$this->setUpAuthenticator(['post_only' => $postOnly]);
193+
194+
$this->expectException(BadRequestHttpException::class);
195+
$this->expectExceptionMessage('The key "_csrf_token" must be a string, "integer" given.');
196+
197+
$this->authenticator->authenticate($request);
198+
}
199+
200+
/**
201+
* @dataProvider postOnlyDataProvider
202+
*/
203+
public function testHandleNonStringCsrfTokenWithObject($postOnly)
204+
{
205+
$request = Request::create('/login_check', 'POST', ['_username' => 'foo', 'password' => 'bar', '_csrf_token' => new \stdClass()]);
206+
$request->setSession($this->createSession());
207+
208+
$this->setUpAuthenticator(['post_only' => $postOnly]);
209+
210+
$this->expectException(BadRequestHttpException::class);
211+
$this->expectExceptionMessage('The key "_csrf_token" must be a string, "object" given.');
212+
213+
$this->authenticator->authenticate($request);
214+
}
215+
168216
public static function postOnlyDataProvider()
169217
{
170218
yield [true];

0 commit comments

Comments
 (0)