-
Notifications
You must be signed in to change notification settings - Fork 176
Description
Overview
The handleState logic falls over in the case that the nuxt-auth-state cookie is already present. This results in a "state mismatch" error and is unrecoverable without instructing users to erase cookies.
Detail
handleState attempts to fetch the cookie. If its successful, it erases and returns it. If it fails, it generates and stores it.
nuxt-auth-utils/src/runtime/server/lib/utils.ts
Lines 207 to 217 in 84f879e
| export async function handleState(event: H3Event) { | |
| let state = getCookie(event, 'nuxt-auth-state') | |
| if (state) { | |
| deleteCookie(event, 'nuxt-auth-state') | |
| return state | |
| } | |
| state = encodeBase64Url(getRandomBytes(8)) | |
| setCookie(event, 'nuxt-auth-state', state) | |
| return state | |
| } |
The issue is that we call this method twice during oauth. Once before the external redirect and again when the user returns and the code and state query params are available. Example.
The happy path is where nuxt-auth-state is undefined, it is generated, stored and sent along with the redirect to the oauth provider. On return, its returned and erased.
The failure path is where nuxt-auth-state is defined as an arbitrary value, it is returned and erased. On return, it is undefined and a new value is generated resulting in a mismatch.
Proposal
WIP - feedback welcomed
Related