fix(auth): use generic wording for failed login logs/events - #3671
Open
IshanA2007 wants to merge 1 commit into
Open
IshanA2007 wants to merge 1 commit into
IshanA2007 wants to merge 1 commit into
Conversation
Local password verification failures previously logged and stored an
activity-log event containing the literal reason 'invalid password'.
Since this message is only ever emitted for a username that was
actually found in the database, it let an attacker distinguish a
valid username with a wrong password from a username that does not
exist at all (username enumeration), even though the HTTP response
itself was already generic ('Authentication error').
Use a fixed, generic 'invalid username or password' message instead
of interpolating the underlying error for both the plain
username/password failure path and the LDAP-fallback failure path.
Part of DefGuard#712
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 New contributors
📖 Description
Addresses the first checklist item of #712 (backend logging). Not using a closing
keyword, since the second item (red border on the
usernamefield in the web UI)is not part of this PR.
A failed local password check logged, and stored in the activity log as a
UserLoginFailedevent, the underlyingargon2error, which renders literally asinvalid password. Per the issue, both places that emit this now use the fixed,generic wording
invalid username or password:crates/defguard_core/src/handlers/auth.rs: the "password check failed, LDAP notenabled" branch and the "password check failed, LDAP fallback also failed" branch.
Beyond readability, this also removes a small username-enumeration signal: that
message is only ever emitted for a username/email that was found in the database,
so an admin reading the logs could previously tell a valid username with a wrong
password apart from one that does not exist. The HTTP response was already generic
(401, no body), and is unchanged.
Two things worth flagging:
warn!on that path still logsLDAP error: {ldap_err}, so operators can stilldiagnose LDAP problems from the server log. Happy to keep it in the event too if
you would rather not lose it there.
UserLoginFailedevent is emitted at all when the username does not exist (there is no user to
build
ApiRequestContextfrom), so the presence of the event is still a signal.That is pre-existing and structural; let me know if you want it addressed
separately.
Updated the 3 existing tests that hard-coded the old message string. No new test was
added because those tests already exercise exactly this path; I verified they bind
the change by reverting
auth.rsand confirming all 3 fail.🛠️ Dev Branch Merge Checklist
Documentation
short note explaining why the message must stay generic).
Testing
no new functionality.
via the integration suite.
(
cargo test -p defguard_core --test integration -- test_authenticate test_login_bruteforce test_change_self_password: 3 passed).cargo +nightly fmt --all --checkandcargo clippy --all-targets --all-features -- -D warningsare clean across the workspace.
Deployment
Prepared with AI assistance (Claude Code).