Skip to content

Commit 7e1a526

Browse files
committed
[Security][Guard] Prevent user enumeration via response content
1 parent b6e24b3 commit 7e1a526

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Authentication/Provider/UserAuthenticationProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1515
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
16+
use Symfony\Component\Security\Core\Exception\AccountStatusException;
1617
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1718
use Symfony\Component\Security\Core\Exception\AuthenticationServiceException;
1819
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
@@ -83,7 +84,7 @@ public function authenticate(TokenInterface $token)
8384
$this->userChecker->checkPreAuth($user);
8485
$this->checkAuthentication($user, $token);
8586
$this->userChecker->checkPostAuth($user);
86-
} catch (BadCredentialsException $e) {
87+
} catch (AccountStatusException $e) {
8788
if ($this->hideUserNotFoundExceptions) {
8889
throw new BadCredentialsException('Bad credentials.', 0, $e);
8990
}

Tests/Authentication/Provider/UserAuthenticationProviderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function testAuthenticateWhenProviderDoesNotReturnAnUserInterface()
7979

8080
public function testAuthenticateWhenPreChecksFails()
8181
{
82-
$this->expectException('Symfony\Component\Security\Core\Exception\CredentialsExpiredException');
82+
$this->expectException(BadCredentialsException::class);
8383
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
8484
$userChecker->expects($this->once())
8585
->method('checkPreAuth')
@@ -97,7 +97,7 @@ public function testAuthenticateWhenPreChecksFails()
9797

9898
public function testAuthenticateWhenPostChecksFails()
9999
{
100-
$this->expectException('Symfony\Component\Security\Core\Exception\AccountExpiredException');
100+
$this->expectException(BadCredentialsException::class);
101101
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
102102
$userChecker->expects($this->once())
103103
->method('checkPostAuth')
@@ -116,15 +116,15 @@ public function testAuthenticateWhenPostChecksFails()
116116
public function testAuthenticateWhenPostCheckAuthenticationFails()
117117
{
118118
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
119-
$this->expectExceptionMessage('Bad credentials');
119+
$this->expectExceptionMessage('Bad credentials.');
120120
$provider = $this->getProvider();
121121
$provider->expects($this->once())
122122
->method('retrieveUser')
123123
->willReturn($this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock())
124124
;
125125
$provider->expects($this->once())
126126
->method('checkAuthentication')
127-
->willThrowException(new BadCredentialsException())
127+
->willThrowException(new CredentialsExpiredException())
128128
;
129129

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

0 commit comments

Comments
 (0)