Skip to content

fix: only retry urldecoded password when decoding changes it (LDAP badPwdCount double-increment)#62474

Open
mvanhorn wants to merge 1 commit into
nextcloud:masterfrom
mvanhorn:fix/33657-ldap-double-badpwdcount
Open

fix: only retry urldecoded password when decoding changes it (LDAP badPwdCount double-increment)#62474
mvanhorn wants to merge 1 commit into
nextcloud:masterfrom
mvanhorn:fix/33657-ldap-double-badpwdcount

Conversation

@mvanhorn

Copy link
Copy Markdown

Summary

When a wrong password is entered for an LDAP or Active Directory user, the directory's failed-login counter is increased by two instead of one. Administrators who lock accounts after three failed attempts therefore find users locked out after only two mistakes, which causes avoidable lockouts and support load.

The cause is in the password check inside the user manager. After the first authentication attempt with the plain password fails, the method decodes the password and then tries every backend a second time. That second pass exists so that non-ASCII passwords sent over HTTP basic auth, which arrive percent-encoded, can still be verified. The problem is that the second pass ran unconditionally, even when the password contained nothing to decode, so an ordinary wrong password produced two identical authentication attempts and two directory binds for a single login.

This change performs the second attempt only when decoding actually changes the password. When decoding leaves the password unchanged, the method now returns right after the first attempt, so one wrong password results in exactly one directory bind and one counter increment. The compatibility path for genuinely percent-encoded passwords is preserved: when decoding does change the value, the second attempt still runs against the decoded password.

Two unit tests were added. The first checks that a wrong password with nothing to decode reaches the backend exactly once. The second checks that a percent-encoded password still triggers a second attempt with the decoded value and authenticates when the decoded form is accepted.

Fixes #33657

TODO

Nothing outstanding. The change is self-contained and covered by the added tests.

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

AI was used for assistance.

…dPwdCount double-increment)

Fixes nextcloud#33657

Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
@mvanhorn
mvanhorn requested a review from a team as a code owner July 24, 2026 09:20
@mvanhorn
mvanhorn requested review from Altahrim, leftybournes, provokateurin and salmart-dev and removed request for a team July 24, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: a wrong password will trigger badPwdCount twice in ldap

1 participant