fix(api): guard against nil session pointer dereference in user update and recovery codes - #2789
Open
Tyagiquamar wants to merge 1 commit into
Open
Conversation
…e and recovery codes
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.
Problem
When handling tokens where
sessionis nil (e.g. customized access tokens with blank or nil session IDs wheremaybeLoadUserOrSessiondoes not load a session), requests toPUT /userand recovery codes endpoints crash with a nil pointer dereference panic, resulting in an unhandled HTTP 500 error.Root Cause
In
internal/api/user.go:user.HasMFAEnabled() && !session.IsAAL2()dereferencessessionwhen MFA is enabled andsessionis nil.!session.IsRecovery()dereferencessessionwhen updating passwords without checking ifsessionis nil.In
internal/api/recovery_codes.go:!session.IsAAL2()without ensuringsessionis non-nil.Fix
Add nil guards that fail closed consistently with the rest of the API:
user.HasMFAEnabled() && (session == nil || !session.IsAAL2())if session == nil || !session.IsRecovery()if session == nil || !session.IsAAL2()in recovery codes generate and regenerate handlers.Verification
go vet ./internal/apiran cleanly.go test -c ./internal/apicompiled successfully.Fixes #2665