Conversation
GetUserData indexed e.Elements[0] without checking the slice length. When LinkedIn's /v2/emailAddress endpoint returns an empty elements array (for example when the email scope is not granted), this panics with "index out of range [0] with length 0", which the recoverer turns into a 500 and fails the OAuth callback. Read the email through a length-guarded local, mirroring the existing guard in getAvatarUrl, so a missing email is handled gracefully. Adds a regression test that exercises the empty-elements response.
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.
What
linkedinProvider.GetUserDatareads the user's email ase.Elements[0].HandleTilde.EmailAddresswithout checking thatElementsis non-empty. When LinkedIn's/v2/emailAddressendpoint returns an empty array — e.g. when the email scope isn't granted or no primary email is available — this panics:The
recoverermiddleware turns the panic into a500, so the OAuth callback fails instead of degrading gracefully. Note thatgetAvatarUrla few lines above already guards itsElementsaccess withlen(...) > 0; the email path was missing the same check.Fix
Read the email through a length-guarded local (mirroring
getAvatarUrl). A missing email now yields an empty value that flows through the existingemail != ""handling, so sign-in proceeds without the email rather than crashing.Testing
Added
TestSignupExternalLinkedin_MissingEmailininternal/api/external_linkedin_test.go, which drives the OAuth callback with an empty{"elements": []}email response. Before the change it fails with the recovered panic (500); after it, the callback redirects normally (302). All existing LinkedIn provider tests still pass;gofmtandgo vetare clean.