Skip to content

Commit 236fb1b

Browse files
committed
cleanup: don't include state when redirecting back to custom domain; explain csrf token structure
1 parent 932f4e3 commit 236fb1b

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

middleware.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ async function redirectToAuthSync (request, searchParams, domain, signup, header
8080
// -- CSRF protection --
8181
// retrieve the csrfToken from the cookie
8282
const csrfCookie = request.cookies.get('__Host-next-auth.csrf-token')
83+
// csrf is stored as token|hash, we only need the token
8384
const csrfToken = csrfCookie ? csrfCookie.value.split('|')[0] : null
8485
// bail if we don't have a csrfToken
8586
if (!csrfToken) return NextResponse.redirect(new URL('/error', request.url), { headers })
@@ -115,6 +116,7 @@ async function establishAuthSync (request, searchParams, headers) {
115116

116117
// -- CSRF protection --
117118
const csrfCookie = request.cookies.get('__Host-next-auth.csrf-token')
119+
// csrf is stored as token|hash, we only need the token
118120
const csrfToken = csrfCookie ? csrfCookie.value.split('|')[0] : null
119121
// bail if we don't have a csrfToken
120122
if (!csrfToken) return NextResponse.redirect(new URL('/error', request.url), { headers })

pages/api/auth/sync.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ async function redirectToDomain (res, domainName, verificationToken, redirectUri
142142

143143
// add the verification sync token and the redirectUri to the URL
144144
target.searchParams.set('synctoken', verificationToken.split('|')[0])
145-
target.searchParams.set('state', verificationToken.split('|')[1])
146145
target.searchParams.set('redirectUri', redirectUri)
147146

148147
// redirect to the custom domain

0 commit comments

Comments
 (0)