Skip to content

Disabled account is shown "Bad credentials" error #42793

Closed
@fmonts

Description

@fmonts

I'm using the old 5.2 Security component, since we don't have docs for the new system yet.

I noticed that when User::isEnabled() returns false (for example if the user is banned or not yet approved), at login the user is shown "Bad credentials" error, because of this:

A DisabledException is thrown...

if (!$user->isEnabled()) {
$ex = new DisabledException('User account is disabled.');
$ex->setUser($user);
throw $ex;
}

Which extends AccountStatusException...

class DisabledException extends AccountStatusException

Which throws a BadCredentialsException

} catch (AccountStatusException | BadCredentialsException $e) {
if ($this->hideUserNotFoundExceptions && !$e instanceof CustomUserMessageAccountStatusException) {
throw new BadCredentialsException('Bad credentials.', 0, $e);
}

This was changed in May, here: https://symfony.com/blog/cve-2021-21424-prevent-user-enumeration-in-authentication-mechanisms

But I do not think this is a proper solution, if a user is banned or pending approval, and they insert the valid credentials, they shouldn't see an "Invalid credential" errors, this will make them think they forgot the password or their account has been stolen, and try to reset the password... (without success, since after the reset the same error will be shown, so they will end up contacting the admin in despair)

In my case I did this in login controller:

if(is_a($error, DisabledException::class) && $error->getUser()->isStatus(User::STATUS_PENDING_APPROVAL)) {
    // Show "please wait to be approved" message
}

Which is not working anymore.

A workaround is to set hide_user_not_found: false, but this will cause other unwanted effects (and as per the option name, it should regard "not found" users, not "disabled" ones)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions