fix(core): guard against undefined provider in POST callback handler#13383
Open
JWPapi wants to merge 1 commit intonextauthjs:mainfrom
Open
fix(core): guard against undefined provider in POST callback handler#13383JWPapi wants to merge 1 commit intonextauthjs:mainfrom
JWPapi wants to merge 1 commit intonextauthjs:mainfrom
Conversation
When a POST request hits `/api/auth/callback/<invalid-provider-id>`, `options.provider` is undefined because no configured provider matches the ID. The existing code at `lib/index.ts:73` accesses `options.provider.type` without a null check, causing: TypeError: Cannot read properties of undefined (reading 'type') The downstream `actions.callback()` already guards against this with `if (!options.provider) throw new InvalidProvider(...)`, but the crash occurs before that function is reached. This adds optional chaining (`options.provider?.type`) consistent with how `lib/init.ts:40` already handles the same property. Commonly triggered by bot/scanner traffic hitting auth endpoints with invalid provider IDs.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
|
@JWPapi is attempting to deploy a commit to the authjs Team on Vercel. A member of the Team first needs to authorize it. |
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
When a POST request hits
/api/auth/callback/<invalid-provider-id>,options.providerisundefinedbecause no configured provider matches the ID. The code atpackages/core/src/lib/index.ts:73accessesoptions.provider.typewithout a null check, causing:The downstream
actions.callback()already guards against this withif (!options.provider) throw new InvalidProvider(...), but the crash occurs before that function is reached — during the CSRF check gate.Fix
Add optional chaining:
options.provider?.type— consistent with howlib/init.ts:40already handles the same property.When
providerisundefined, the CSRF check is skipped (correctly — there's no credentials provider to protect), and execution falls through toactions.callback()which throws the properInvalidProvidererror.How to reproduce
Send a POST request to
/api/auth/callback/nonexistent-providerwith any body. Commonly triggered by bot/scanner traffic probing auth endpoints.