security: normalize login error messages to prevent user enumeration (#6)#583
Merged
lakhansamani merged 2 commits intomainfrom Apr 7, 2026
Merged
security: normalize login error messages to prevent user enumeration (#6)#583lakhansamani merged 2 commits intomainfrom
lakhansamani merged 2 commits intomainfrom
Conversation
) Distinct login error messages let attackers enumerate registered users: - "user has not signed up email & password" - "email not verified" - "email verification pending" - "user has not signed up with phone number & password" - "phone number is not verified" - "bad user credentials" - "user not found" (forgot password, resend verify, magic link) - "user access has been revoked" All authentication failures now return the same generic "invalid credentials" message to the client. The real reason is recorded in the debug log for ops visibility via structured fields (reason="user_not_found", "bad_password", "account_revoked", etc.). Forgot password, resend verify email, and magic link login no longer reveal whether the email exists — they return the same generic success response in all cases. Timing-attack defense: a precomputed dummy bcrypt hash is compared in the user-not-found and other early-exit paths so total request time matches the real authentication path. Without this, an attacker can distinguish "no such user" from "wrong password" by latency alone. Tests updated to assert on the new generic error message.
…typos (#6) The previous generic-success messages ("Please check your inbox") were identical between the success and silent-failure paths — good for preventing enumeration — but gave the user no recourse when the email never arrived because they had typed the address wrong. Updated the message in all three handlers to a single sentence that: 1. Explicitly says the email was sent IF the account exists (so the user knows the response is conditional) 2. Tells them to check their inbox 3. Hints that they should double-check the address for typos if nothing arrives within a few minutes The message is identical across the success path AND the silent-failure paths in each handler, so enumeration is still impossible: - forgot_password.go: user_not_found, account_revoked, and the success branch all return the same string - resend_verify_email.go: user_not_found, verification_request_not_found, and the success branch all return the shared genericResponse - magic_link_login.go: account_revoked branch and the trailing success branch share the same string
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.
Summary
Distinct login error messages let attackers enumerate registered users (
user not foundvswrong passwordvsemail not verifiedvswrong auth method). All authentication failures now return the same genericinvalid credentialsmessage; the specific reason is recorded at debug level.Changes
internal/graphql/login.go— collapse all distinct failure paths toinvalid credentials. Add a precomputed dummy bcrypt comparison on the user-not-found and other early-exit paths so request latency matches the real password-verification path.internal/graphql/forgot_password.go— return generic success for unknown email and revoked accounts.internal/graphql/resend_verify_email.go— return generic success for unknown user / missing verification request.internal/graphql/magic_link_login.go— return generic success for revoked accounts.login_test.go,forgot_password_test.go,metrics_test.gonow assert on the new generic message and on the silent-success behaviour (the failure metric is still recorded internally).Test plan
TEST_DBS=sqlite go test -run "TestLogin|TestForgotPassword|TestMagicLink|TestResendVerifyEmail|TestForgotPasswordMetrics" ./internal/integration_tests/