Thanks to visit codestin.com
Credit goes to github.com

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

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

return $credentials;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,54 @@ public function __toString()
$this->assertSame('s$cr$t', $credentialsBadge->getPassword());
}

/**
* @dataProvider postOnlyDataProvider
*/
public function testHandleNonStringCsrfTokenWithArray($postOnly)
{
$request = Request::create('/login_check', 'POST', ['_username' => 'foo', 'password' => 'bar', '_csrf_token' => []]);
$request->setSession($this->createSession());

$this->setUpAuthenticator(['post_only' => $postOnly]);

$this->expectException(BadRequestHttpException::class);
$this->expectExceptionMessage('The key "_csrf_token" must be a string, "array" given.');

$this->authenticator->authenticate($request);
}

/**
* @dataProvider postOnlyDataProvider
*/
public function testHandleNonStringCsrfTokenWithInt($postOnly)
{
$request = Request::create('/login_check', 'POST', ['_username' => 'foo', 'password' => 'bar', '_csrf_token' => 42]);
$request->setSession($this->createSession());

$this->setUpAuthenticator(['post_only' => $postOnly]);

$this->expectException(BadRequestHttpException::class);
$this->expectExceptionMessage('The key "_csrf_token" must be a string, "integer" given.');

$this->authenticator->authenticate($request);
}

/**
* @dataProvider postOnlyDataProvider
*/
public function testHandleNonStringCsrfTokenWithObject($postOnly)
{
$request = Request::create('/login_check', 'POST', ['_username' => 'foo', 'password' => 'bar', '_csrf_token' => new \stdClass()]);
$request->setSession($this->createSession());

$this->setUpAuthenticator(['post_only' => $postOnly]);

$this->expectException(BadRequestHttpException::class);
$this->expectExceptionMessage('The key "_csrf_token" must be a string, "object" given.');

$this->authenticator->authenticate($request);
}

public static function postOnlyDataProvider()
{
yield [true];
Expand Down