Skip to content

Comments

fix(core): guard against undefined provider in POST callback handler#13383

Open
JWPapi wants to merge 1 commit intonextauthjs:mainfrom
JWPapi:fix/guard-provider-type-access
Open

fix(core): guard against undefined provider in POST callback handler#13383
JWPapi wants to merge 1 commit intonextauthjs:mainfrom
JWPapi:fix/guard-provider-type-access

Conversation

@JWPapi
Copy link

@JWPapi JWPapi commented Feb 20, 2026

Summary

When a POST request hits /api/auth/callback/<invalid-provider-id>, options.provider is undefined because no configured provider matches the ID. The code at packages/core/src/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 — during the CSRF check gate.

Fix

Add optional chaining: options.provider?.type — consistent with how lib/init.ts:40 already handles the same property.

When provider is undefined, the CSRF check is skipped (correctly — there's no credentials provider to protect), and execution falls through to actions.callback() which throws the proper InvalidProvider error.

How to reproduce

Send a POST request to /api/auth/callback/nonexistent-provider with any body. Commonly triggered by bot/scanner traffic probing auth endpoints.

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.
@JWPapi JWPapi requested a review from ThangHuuVu as a code owner February 20, 2026 13:51
@vercel
Copy link

vercel bot commented Feb 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
auth-docs Ready Ready Preview, Comment Feb 20, 2026 1:57pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
next-auth-docs Ignored Ignored Preview Feb 20, 2026 1:57pm

Request Review

@vercel
Copy link

vercel bot commented Feb 20, 2026

@JWPapi is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Refers to `@auth/core`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant