fix(password_reset): return 400 on ErrNotFound in ResetPassword#233
Merged
Conversation
Copilot created this pull request from a session on behalf of
veverkap
May 10, 2026 18:23
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes password reset confirmation behavior to avoid returning HTTP 500 when the reset token points to a deleted/non-existent user, aligning the response with other invalid-token conditions.
Changes:
- Handle
auth.ErrNotFoundfromUsers.FindByIDinResetPassword()by returning HTTP 400"invalid or expired reset token"instead of HTTP 500. - Keep logging/500 behavior for unexpected user store errors.
Show a summary per file
| File | Description |
|---|---|
handler/password_reset.go |
Adds an ErrNotFound guard in the reset confirmation flow to treat missing users as an invalid/expired token (400). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
Cover the case where a user is deleted after a valid reset token is issued. Asserts HTTP 400 and that UpdatePassword and DeletePasswordResetToken are not called.
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.
Bug Fix
What was the bug?
ResetPassword()was the only handler callingFindByIDwithout checkingauth.ErrNotFound— a deleted or non-existent user would yield a 500 instead of a 400, leaking an internal error for what is a client-side invalid token condition.How did you fix it?
Added the missing
ErrNotFoundguard before the 500 path, consistent with every otherFindByIDcall site in the codebase:Testing
Covered by existing test suite (
go test ./...).Greptile Summary
This PR adds a missing
ErrNotFoundguard inResetPassword()so that a deleted or non-existent user returns HTTP 400 instead of HTTP 500, consistent with every otherFindByIDcall site in the handler package.handler/password_reset.go: Inserts anerrors.Is(err, auth.ErrNotFound)check before the generic 500 path, returning 400 with the same "invalid or expired reset token" message used elsewhere in the handler.handler/password_reset_test.go: AddsTestResetPassword_userDeletedAfterTokenIssuedwhich verifies the 400 response and confirms that neitherUpdatePasswordnorDeletePasswordResetTokenare called when the user no longer exists.Confidence Score: 5/5
This is a minimal, well-targeted change that closes a gap in error-code handling with no risk of regression to the happy path.
The change is a single guard clause inserted in an already well-covered code path, and the new test directly validates the corrected behavior and absence of unintended side effects.
No files require special attention.
Important Files Changed
Sequence Diagram
sequenceDiagram participant Client participant Handler as ResetPassword Handler participant Resets as ResetStore participant Users as UserStore Client->>Handler: POST /reset-password Handler->>Resets: FindPasswordResetToken(hash) Resets-->>Handler: PasswordResetToken or error alt invalid or expired token Handler-->>Client: 400 Bad Request end Handler->>Users: FindByID(token.UserID) Users-->>Handler: User or error alt ErrNotFound (user deleted) Handler-->>Client: 400 Bad Request (new guard) else other error Handler-->>Client: 500 Internal Server Error end alt OIDC-only account Handler-->>Client: 400 Bad Request end Handler->>Users: UpdatePassword(userID, hash) Handler->>Resets: DeletePasswordResetToken(id) Handler-->>Client: 200 OKReviews (2): Last reviewed commit: "test: add test for FindByID returning Er..." | Re-trigger Greptile