Skip to content

Commit

Permalink
security #cve-2021-21424 [Security\Core] Fix user enumeration via res…
Browse files Browse the repository at this point in the history
…ponse body on invalid credentials (chalasr)

This PR was merged into the 3.4 branch.
  • Loading branch information
nicolas-grekas committed May 19, 2021
2 parents d0d17db + e850700 commit 1ad13fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public function authenticate(TokenInterface $token)
$this->userChecker->checkPreAuth($user);
$this->checkAuthentication($user, $token);
$this->userChecker->checkPostAuth($user);
} catch (AccountStatusException $e) {
if ($this->hideUserNotFoundExceptions) {
} catch (AuthenticationException $e) {
if ($this->hideUserNotFoundExceptions && ($e instanceof AccountStatusException || $e instanceof BadCredentialsException)) {
throw new BadCredentialsException('Bad credentials.', 0, $e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Core\Role\SwitchUserRole;
use Symfony\Component\Security\Core\User\UserInterface;

class UserAuthenticationProviderTest extends TestCase
{
Expand Down Expand Up @@ -62,6 +63,24 @@ public function testAuthenticateWhenUsernameIsNotFoundAndHideIsTrue()
$provider->authenticate($this->getSupportedToken());
}

public function testAuthenticateWhenCredentialsAreInvalidAndHideIsTrue()
{
$provider = $this->getProvider();
$provider->expects($this->once())
->method('retrieveUser')
->willReturn($this->createMock(UserInterface::class))
;
$provider->expects($this->once())
->method('checkAuthentication')
->willThrowException(new BadCredentialsException())
;

$this->expectException(BadCredentialsException::class);
$this->expectExceptionMessage('Bad credentials.');

$provider->authenticate($this->getSupportedToken());
}

/**
* @group legacy
*/
Expand Down

0 comments on commit 1ad13fe

Please sign in to comment.