Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
[Security\Core] Fix user enumeration via response body on invalid cre…
Browse files Browse the repository at this point in the history
…dentials
  • Loading branch information
chalasr authored and nicolas-grekas committed May 19, 2021
1 parent 06dbfe4 commit ac1af40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Core/Authentication/Provider/UserAuthenticationProvider.php
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
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 ac1af40

Please sign in to comment.