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

Skip to content

[Security] FormLoginAuthenticator: fail for non-string password #51445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2023
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 @@ -157,6 +157,10 @@ private function getCredentials(Request $request): array

$request->getSession()->set(Security::LAST_USERNAME, $credentials['username']);

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

return $credentials;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\Security\Http\Authenticator\FormLoginAuthenticator;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PasswordUpgradeBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials;
use Symfony\Component\Security\Http\HttpUtils;
use Symfony\Component\Security\Http\Tests\Authenticator\Fixtures\PasswordUpgraderProvider;

Expand Down Expand Up @@ -126,6 +127,44 @@ public function testHandleNonStringUsernameWithToString($postOnly)
$this->authenticator->authenticate($request);
}

/**
* @dataProvider postOnlyDataProvider
*/
public function testHandleNonStringPasswordWithArray(bool $postOnly)
{
$this->expectException(BadRequestHttpException::class);
$this->expectExceptionMessage('The key "_password" must be a string, "array" given.');

$request = Request::create('/login_check', 'POST', ['_username' => 'foo', '_password' => []]);
$request->setSession($this->createSession());

$this->setUpAuthenticator(['post_only' => $postOnly]);
$this->authenticator->authenticate($request);
}

/**
* @dataProvider postOnlyDataProvider
*/
public function testHandleNonStringPasswordWithToString(bool $postOnly)
{
$passwordObject = new class() {
public function __toString()
{
return 's$cr$t';
}
};

$request = Request::create('/login_check', 'POST', ['_username' => 'foo', '_password' => $passwordObject]);
$request->setSession($this->createSession());

$this->setUpAuthenticator(['post_only' => $postOnly]);
$passport = $this->authenticator->authenticate($request);

/** @var PasswordCredentials $credentialsBadge */
$credentialsBadge = $passport->getBadge(PasswordCredentials::class);
$this->assertSame('s$cr$t', $credentialsBadge->getPassword());
}

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