Auth.js security: session strategy, secrets and the checks your routes make
Auth.js handles sign-in inside your own application, with installation steps for Next.js, Qwik, SvelteKit and Express, and its configuration decides how a session is stored, sealed and ended.
This guide follows those decisions in order, with a decision table to fill in for your own application and a local test set that illustrates the JWT and database session strategies side by side.
In this guide
Auth.js session decision table and local test set
An illustration and a worksheet. Part 1 is a decision tree that settles which session strategy your configuration runs.
How to use itHide the instructions
Part 2 is a thirteen-item record sheet: where to look, what the named Auth.js page or advisory says, and what to write down, read-only and owner-run. Parts 3 to 5 are a Node.js lab with no installs and no Auth.js code, run on 127.0.0.1 with invented users and secrets, and the output it printed on Node.js v26.0.0.
authjs.txt
Introduction7 lines
Part 1. Decision tree26 lines
Part 2. Record sheet99 lines
Part 3. Lab file: session-lab.mjs195 lines
Part 4. Lab file: run-session-tests.mjs145 lines
Part 5. Running the lab, and what it printed38 lines
Whole template525 lines
AUTH.JS SESSION DECISION TABLE, WITH A LOCAL SESSION TEST SET
ILLUSTRATION AND WORKSHEET. Part 1 is a decision tree that settles which session strategy your Auth.js configuration actually runs. Part 2 is a record sheet of thirteen items to fill in for your own application. Parts 3 to 5 are a local lab: two Node.js files written for this page, run on 127.0.0.1 with invented users and invented secrets, and the output they printed. The lab holds no Auth.js code. It illustrates the difference between JWT and database sessions; it does not test Auth.js.
Every line under Docs in Part 2 comes from the Auth.js page or advisory named on the line, as read on 14 November 2026. Lines under This page's reading are this guide's inferences from them.
Every item in Part 2 only reads. You read your own configuration files, the variable names in your hosting provider's environment settings and its member list, the values of AUTH_TRUST_HOST and AUTH_URL, which hold no secret, the lockfile of the build you deployed, counts from your own database, and this page's advisory log and the repository's advisories page, and you ask the person who runs your proxy one question. No item changes a setting, rotates a secret or sends traffic to a service you do not own, and no item asks you to open an environment settings screen or an .env file that shows a secret's value. Where the configuration file itself holds a secret, record only that it does. Record that a secret is set, never its value, and never copy a cookie, token or password into the sheet. Fill in one copy for each environment that issues sessions, and date it.
PART 1. DECISION TREE
Q1. Is an adapter set in the Auth.js configuration (the adapter option)?
No: sessions are JWTs, the default the @auth/core reference gives.
Go to Q3.
Yes: go to Q2.
Q2. Does session.strategy say "jwt"?
Yes: users and accounts live in the database, but sessions are still JWTs.
The v5 upgrade guide shows this set-up for adapters that are not
compatible with the Edge runtime. Go to Q3.
No: sessions are database rows, and the cookie holds only a session
token. Go to Q4.
Q3. JWT sessions. The session strategies page says a copy of the JWT saved
elsewhere is accepted until it expires (lab runs J4 and J5). The
role-based access control guide says that with this strategy, if you
want to update the role, the user needs to be forced to sign in again
(J6 and J7). Give items 2, 3 and 10 the most weight, then work through
the rest of Part 2.
Q4. Database sessions. The session strategies page says signing out
deletes the session from the database. In the lab, signing out and
ending every session for a user on the server each remove the row, and
the next request is refused (D4 and D5). In the role-based access
control guide's database example, the session callback copies the role
from the user record (D6). Give items 2, 9 and 12 the most weight, then
work through the rest of Part 2.
PART 2. RECORD SHEET
Environment: ____________ Filled in by: ____________ Date: ____________
next-auth or @auth/* version read in item 13: ____________
1. SESSION STRATEGY
Where to look: the Auth.js configuration file (auth.ts by the installation page's convention) and, where the configuration is split for the Edge runtime as the v5 upgrade guide shows, the second configuration file as well.
Docs (@auth/core reference, session.strategy): the default is "jwt", an encrypted JWT (JWE) in the session cookie. When an adapter is used the default is "database", and "jwt" can still be forced. With "database", the session cookie only contains a sessionToken value, used to look up the session in the database.
Record: adapter set (yes or no) ______ session.strategy (value or not set) ______ strategy that results ______
Lab: compare J1 to J11 with D1 to D7.
2. SESSION LIFETIME
Where to look: session.maxAge and session.updateAge in the configuration.
Docs (@auth/core reference): maxAge defaults to 2592000 seconds (30 days). updateAge defaults to 86400 seconds (1 day), and 0 updates the session every time.
Docs (v5 upgrade guide): whenever auth() is passed the response object, it rotates the session expiry.
Docs (session strategies page): with JWT sessions, Auth.js destroys the cookie on sign-out, but a copy of the JWT saved elsewhere is valid until it expires.
Record: maxAge ______ updateAge ______ (write default where not set)
Lab: J11 and D7.
3. AUTH_SECRET
Where to look: the variable names set in every environment that runs the app (production, staging, previews), from a listing that shows names without values; a search of local .env files and the repository for AUTH_SECRET that lists file names only; and the secret option in the configuration. Do not open a settings screen or an .env file that displays the value.
Docs (installation page): AUTH_SECRET is the only mandatory environment variable, a random value used to encrypt tokens and email verification hashes. The Auth.js CLI adds a generated value to the .env file, following the framework's convention, such as .env.local for Next.js.
Docs (deployment page): it should be a cryptographically secure random string of at least 32 characters.
Docs (@auth/core reference, secret): an array of secrets is accepted. The first secret that successfully decrypts the JWT is used, and the newer secret goes at the start of the array, where it is used for all new sessions.
Docs (v5 upgrade guide): environment variables should be prefixed with AUTH_, and NEXTAUTH_ is no longer in use.
Record for this environment: AUTH_SECRET set (yes or no) ______ secret option given as one value or a list, and how many entries ______ NEXTAUTH_ variables still present, by name only ______
Record for the repository: the names of any committed files that contain an AUTH_SECRET line, found with a search that lists file names only ______
Never record the value.
Lab: J3, J8, J9, J10 and R1.
4. PREVIEW DEPLOYMENTS
Where to look: whether AUTH_REDIRECT_PROXY_URL is set in each environment, from the names-only listing used in item 3, and the hosting team's member list for who can read preview environment settings.
Docs (deployment page): with AUTH_REDIRECT_PROXY_URL, the AUTH_SECRET value needs to be the same for the stable deployment and the previews that need OAuth, and the redirect is secured by relying on that shared server-side secret. The stable deployment can be the main site's URL.
This page's reading: anyone who can read a preview deployment's environment settings can read the secret the stable deployment uses.
Record: AUTH_REDIRECT_PROXY_URL set (yes or no) ______ stable deployment URL ______ who can read preview settings ______
5. SECURE COOKIES
Where to look: useSecureCookies and cookies in the configuration. This item reads the configuration only, so that no step displays a session token.
Docs (@auth/core reference): useSecureCookies, when set to true, makes all cookies set by NextAuth.js accessible only from HTTPS URLs. It defaults to false on URLs that start with http:// and true for HTTPS sites, and setting it to false is not recommended. The cookies option is an advanced option, and using it opts out of the built-in dynamic policy.
Docs (v5 upgrade guide): the next-auth cookie prefix is renamed to authjs.
Record: useSecureCookies (value or not set) ______ cookies option (set or not set) ______
If the cookies option is set, for each cookie it overrides: name ______ options it sets, as written in the configuration ______
6. TRUSTED HOST
Where to look: trustHost in the configuration, AUTH_TRUST_HOST and AUTH_URL in each environment (read on their own, without displaying any secret's value), and how the app is hosted.
Docs (@auth/core reference): Auth.js relies on the incoming request's host header, trustHost needs to be set to true for this reason, and you should make sure your deployment platform sets the host header safely.
Docs (deployment page): behind a reverse proxy, AUTH_TRUST_HOST needs to be set to true, which tells Auth.js to trust the X-Forwarded-Host header. Auth.js infers it on supported hosting providers, and the page names VERCEL and CF_PAGES (Cloudflare Pages). In Docker, set trustHost: true or AUTH_TRUST_HOST to true.
Docs (v5 upgrade guide): when AUTH_TRUST_HOST is true, Auth.js trusts the X-Forwarded-Host and X-Forwarded-Proto headers to detect the host URL.
Record: trustHost ______ AUTH_TRUST_HOST ______ AUTH_URL ______ hosting and the proxy in front ______
Who confirmed that the proxy sets X-Forwarded-Host and X-Forwarded-Proto itself, and when ______
7. REDIRECTS
Where to look: callbacks.redirect in the configuration.
Docs (@auth/core reference): the redirect callback is called anytime the user is redirected to a callback URL, and by default only URLs on the same host as the origin are allowed.
Record: default or custom ______ if custom, every host it allows ______
8. PROVIDERS, SCOPES AND CHECKS
Where to look: the providers list in the configuration.
Docs (configuring OAuth providers guide): options passed to a provider are deep-merged with its defaults, and overriding "authorization.params.scope" is enough to change its scopes.
Docs (@auth/core providers reference): checks defaults to PKCE, and state is added automatically when a redirect proxy URL is set. Accounts with the same email address are not linked automatically on OAuth sign-in; allowDangerousEmailAccountLinking turns that on.
Docs (deployment page): when users are stored in a database, a different OAuth app for development and production is recommended, so test and production user bases do not mix.
Docs (credentials page): the Credentials provider does not persist data in the database by default; you can still save data there, but you have to provide the necessary logic, for example to encrypt passwords, add rate limiting and add password reset.
Record for each provider: scopes requested, and the feature that uses each ______ checks ______ allowDangerousEmailAccountLinking ______ OAuth app used by this environment ______
For a Credentials provider: where rate limiting, password storage and password reset are handled ______
9. ADAPTER RECORDS
Where to look: the tables your adapter created for users, accounts, sessions and verification tokens. The database models page says models vary slightly by adapter.
Docs (database models page): the Account model stores access_token, expires_at, refresh_token, id_token, token_type, scope and session_state by default. An expired session is deleted from the database when it is read. Each verification token is usable only once and has a default lifetime of 1 day.
Docs (@auth/core providers reference): a provider's account callback returns the subset of the token set that is saved.
Docs (magic links page): an email provider cannot be enabled without a database.
Record: rows in the account table where access_token is not empty, as a count ______ rows where refresh_token is not empty, as a count ______ database roles that can read the account table ______ session rows already past expiry, as a count ______
Use counting queries only. Never run a query that prints a token column.
Lab: D7.
10. JWT AND SESSION CALLBACKS
Where to look: callbacks.jwt and callbacks.session in the configuration.
Docs (@auth/core reference): the jwt callback is called whenever a JSON Web Token is created (at sign in) or updated (whenever a session is accessed in the client), and anything it returns is saved in the JWT. With the jwt strategy, data sent from the client through useSession().update arrives in its session parameter, and you should validate it before using it. The session callback's return value is exposed to the client; by default only a subset of the token (email, name, image) is returned.
Docs (role-based access control guide): with the JWT strategy, the role is persisted in the cookie by assigning user.role to token.role in the jwt callback on sign-in, and if you want to update the role, the user needs to be forced to sign in again.
Docs (refresh token rotation guide): with the JWT strategy, the refresh_token is stored in the encrypted JWT inside an HttpOnly cookie.
Record: each field the jwt callback writes into the token ______ whether the update path writes client data into the token without checking it ______ each field the session callback returns ______ any returned field that is a token ______
Lab: J6, J7 and D6.
11. SIGN-IN RULES AND AUDIT EVENTS
Where to look: callbacks.signIn and events in the configuration.
Docs (@auth/core reference): the signIn callback controls whether a user is allowed to sign in, and events are useful for audit logging.
Docs (GHSA-x445-f3h2-j279): one of the workarounds it gives for those who cannot upgrade immediately is to treat events.linkAccount as sensitive, with audit logging, user notification or out-of-band confirmation, which it calls defence in depth, not a root-cause fix.
Record: the sign-in rule, or none ______ events logged, and where the log goes ______
12. ROUTE HANDLER AND PROXY CHECKS
Where to look: the "authorized" callback, the proxy or middleware file and its matcher, and every page, route handler and server function that calls auth().
Docs (protecting resources page): do not rely on the proxy exclusively for authorisation, and verify the session as close to your data fetching as possible.
Docs (GHSA-8fpg-xm3f-6cx3): in next-auth 5.0.0-beta.0 to 5.0.0-beta.31, when the configuration produces a server-side error, a check that only tests whether the auth object exists treats every request as authenticated. Its workaround, for those who cannot upgrade immediately, is to check a concrete property such as auth.user.
Docs (role-based access control guide): determining the user's role is your responsibility.
Record for each handler: path ______ what it checks (object exists, user present, role, owner of the record) ______
Handlers that check existence only ______ handlers that rely on the proxy alone ______
Lab: R1 and R2.
13. VERSION
Where to look: the resolved next-auth version, and any @auth/* versions, in the lockfile of the commit that is deployed.
Docs (Auth.js security page): "Security updates are only released for the current latest version", and old releases are not maintained and do not receive updates.
Record: versions ______ advisories in this page's log whose affected range includes them ______ date you checked the repository's advisories page for newer ones ______
PART 3. LAB FILE: session-lab.mjs
// session-lab.mjs: an illustration of the choice an Auth.js configuration
// makes between JWT and database sessions. It holds no Auth.js code. One strategy seals
// the session into an encrypted cookie and keeps nothing on the server; the
// other puts an opaque id in the cookie and keeps a session row on the server.
// It listens on 127.0.0.1 only, keeps everything in memory and uses two
// invented users. The secrets below are invented for the lab and protect
// nothing.
import { createServer } from 'node:http'
import { createCipheriv, createDecipheriv, hkdfSync, randomBytes, randomUUID } from 'node:crypto'
export const INVENTED_SECRET_OLD = 'invented-lab-secret-one-protects-nothing'
export const INVENTED_SECRET_NEW = 'invented-lab-secret-two-protects-nothing'
export const COOKIE_NAME = 'lab.session'
export const MAX_AGE_SECONDS = 3600
// A clock the test runner can move forward, so expiry is tested in
// milliseconds rather than an hour.
export function createClock() {
let offsetSeconds = 0
return {
nowSeconds: () => Math.floor(Date.now() / 1000) + offsetSeconds,
advance: (seconds) => { offsetSeconds += seconds },
}
}
// The invented user store. Roles live here; a role change is a write here.
export function createUserStore() {
return new Map([
['ada', { id: 'ada', role: 'admin' }],
['ben', { id: 'ben', role: 'member' }],
])
}
function deriveKey(secret) {
return Buffer.from(hkdfSync('sha256', secret, 'lab.session salt', 'lab session key', 32))
}
// Seals the payload with AES-256-GCM under the first secret in the list.
function seal(payload, secrets) {
const iv = randomBytes(12)
const cipher = createCipheriv('aes-256-gcm', deriveKey(secrets[0]), iv)
const body = Buffer.concat([cipher.update(JSON.stringify(payload), 'utf8'), cipher.final()])
const tag = cipher.getAuthTag()
return [iv, body, tag].map((part) => part.toString('base64url')).join('.')
}
// Tries each secret in turn and returns the payload from the first that
// opens the cookie, or null when none does.
function unseal(value, secrets) {
const parts = value.split('.')
if (parts.length !== 3) return null
const [iv, body, tag] = parts.map((part) => Buffer.from(part, 'base64url'))
for (const secret of secrets) {
try {
const decipher = createDecipheriv('aes-256-gcm', deriveKey(secret), iv)
decipher.setAuthTag(tag)
const text = Buffer.concat([decipher.update(body), decipher.final()]).toString('utf8')
return JSON.parse(text)
} catch {
// This secret did not open the cookie; try the next one.
}
}
return null
}
// Strategy one: everything the server needs travels in the sealed cookie.
export function createSealedCookieStrategy({ secrets, users, clock }) {
return {
name: 'sealed cookie',
signIn(userId) {
const user = users.get(userId)
const issuedAt = clock.nowSeconds()
return seal({ sub: user.id, role: user.role, iat: issuedAt, exp: issuedAt + MAX_AGE_SECONDS }, secrets.list)
},
readSession(cookieValue) {
if (secrets.list.length === 0) return { message: 'There was a problem with the server configuration.' }
if (!cookieValue) return null
const payload = unseal(cookieValue, secrets.list)
if (!payload) return null
if (payload.exp <= clock.nowSeconds()) return null
return { user: { id: payload.sub, role: payload.role } }
},
signOut() {
// Nothing is stored on the server, so there is nothing to delete.
},
endAllSessionsFor() {
return 0
},
}
}
// Strategy two: the cookie holds an opaque id; the session row and the
// current role are read on every request.
export function createDatabaseStrategy({ secrets, users, clock }) {
const sessions = new Map()
return {
name: 'database',
sessions,
signIn(userId) {
const sessionId = randomUUID()
sessions.set(sessionId, { userId, expires: clock.nowSeconds() + MAX_AGE_SECONDS })
return sessionId
},
readSession(cookieValue) {
if (secrets.list.length === 0) return { message: 'There was a problem with the server configuration.' }
if (!cookieValue) return null
const row = sessions.get(cookieValue)
if (!row) return null
if (row.expires <= clock.nowSeconds()) {
sessions.delete(cookieValue)
return null
}
const user = users.get(row.userId)
return { user: { id: user.id, role: user.role } }
},
signOut(cookieValue) {
sessions.delete(cookieValue)
},
endAllSessionsFor(userId) {
let ended = 0
for (const [sessionId, row] of sessions) {
if (row.userId === userId) {
sessions.delete(sessionId)
ended += 1
}
}
return ended
},
}
}
function readCookie(request) {
const header = request.headers.cookie || ''
for (const pair of header.split(';')) {
const [name, ...rest] = pair.trim().split('=')
if (name === COOKIE_NAME) return rest.join('=')
}
return ''
}
function send(response, status, body, extraHeaders) {
response.writeHead(status, { 'content-type': 'application/json', ...(extraHeaders || {}) })
response.end(JSON.stringify(body))
}
function sessionCookie(value, maxAge) {
// No Secure attribute: the lab runs over plain HTTP on 127.0.0.1.
return COOKIE_NAME + '=' + value + '; Path=/; HttpOnly; SameSite=Lax; Max-Age=' + maxAge
}
// The route handler checks the role itself, from whatever the strategy
// returns. It does not rely on any earlier filter.
function handleAdminReport(request, response, strategy) {
const session = strategy.readSession(readCookie(request))
if (!session || !session.user) return send(response, 401, { error: 'not signed in' })
if (session.user.role !== 'admin') return send(response, 403, { error: 'admin role required', role: session.user.role })
send(response, 200, { report: 'invented figures', role: session.user.role })
}
// Two ways to write the same check, kept side by side for the runs labelled R.
function handleExistenceCheck(request, response, strategy) {
const session = strategy.readSession(readCookie(request))
if (session) return send(response, 200, { report: 'invented figures' })
send(response, 401, { error: 'not signed in' })
}
function handleUserCheck(request, response, strategy) {
const session = strategy.readSession(readCookie(request))
if (session && session.user) return send(response, 200, { report: 'invented figures' })
send(response, 401, { error: 'not signed in' })
}
function route(request, response, strategy) {
const url = new URL(request.url, 'http://127.0.0.1')
if (request.method === 'POST' && url.pathname === '/signin') {
const value = strategy.signIn(url.searchParams.get('user'))
return send(response, 200, { signedIn: true }, { 'set-cookie': sessionCookie(value, MAX_AGE_SECONDS) })
}
if (request.method === 'POST' && url.pathname === '/signout') {
strategy.signOut(readCookie(request))
return send(response, 200, { signedOut: true }, { 'set-cookie': sessionCookie('', 0) })
}
if (url.pathname === '/admin/report') return handleAdminReport(request, response, strategy)
if (url.pathname === '/existence-check') return handleExistenceCheck(request, response, strategy)
if (url.pathname === '/user-check') return handleUserCheck(request, response, strategy)
send(response, 404, { error: 'no such route' })
}
// Starts one lab server on 127.0.0.1 at a port the system picks.
export function startLabServer(strategy) {
return new Promise((resolve) => {
const server = createServer((request, response) => route(request, response, strategy))
server.listen(0, '127.0.0.1', () => resolve(server))
})
}
PART 4. LAB FILE: run-session-tests.mjs
// run-session-tests.mjs: the session-tampering and stale-access test set.
// It starts the lab servers from session-lab.mjs on 127.0.0.1, sends each
// request with node:http, prints a line for each run and stops every server.
// Cookie values are never printed.
import { request } from 'node:http'
import {
createClock,
createDatabaseStrategy,
createSealedCookieStrategy,
createUserStore,
INVENTED_SECRET_NEW,
INVENTED_SECRET_OLD,
MAX_AGE_SECONDS,
startLabServer,
} from './session-lab.mjs'
function send(server, method, path, cookieValue) {
const port = server.address().port
const headers = cookieValue ? { cookie: 'lab.session=' + cookieValue } : {}
return new Promise((resolve, reject) => {
const outgoing = request({ host: '127.0.0.1', port, method, path, headers }, (incoming) => {
let text = ''
incoming.on('data', (chunk) => { text += chunk })
incoming.on('end', () => resolve({ status: incoming.statusCode, body: JSON.parse(text), setCookie: incoming.headers['set-cookie'] }))
})
outgoing.on('error', reject)
outgoing.end()
})
}
function readSetCookieValue(response) {
const first = response.setCookie[0]
return first.split(';')[0].split('=').slice(1).join('=')
}
async function signIn(server, userId) {
const response = await send(server, 'POST', '/signin?user=' + userId)
return readSetCookieValue(response)
}
// Changes one character in the middle of the cookie value.
function tamper(value) {
const middle = Math.floor(value.length / 2)
const swapped = value[middle] === 'A' ? 'B' : 'A'
return value.slice(0, middle) + swapped + value.slice(middle + 1)
}
function describe(response) {
const word = response.status === 200 ? 'accepted' : 'refused'
const role = response.body.role ? ', role used: ' + response.body.role : ''
return response.status + ' ' + word + role
}
function print(label, text, response) {
console.log(label + ' ' + text + ': ' + describe(response))
}
async function runSealedCookieSet() {
const clock = createClock()
const users = createUserStore()
const secrets = { list: [INVENTED_SECRET_OLD] }
const strategy = createSealedCookieStrategy({ secrets, users, clock })
const server = await startLabServer(strategy)
console.log('Strategy: sealed cookie (session sealed into the cookie, nothing kept on the server)')
const cookieA = await signIn(server, 'ada')
print('J1', 'baseline, cookie A (ada, admin) on GET /admin/report', await send(server, 'GET', '/admin/report', cookieA))
print('J2', 'tampered, cookie A with one character changed', await send(server, 'GET', '/admin/report', tamper(cookieA)))
const otherStrategy = createSealedCookieStrategy({ secrets: { list: ['invented-attacker-secret'] }, users, clock })
const forged = otherStrategy.signIn('ben')
print('J3', 'forged, a cookie sealed under a secret the server does not hold', await send(server, 'GET', '/admin/report', forged))
await send(server, 'POST', '/signout', cookieA)
print('J4', 'replay after sign-out, cookie A saved before signing out', await send(server, 'GET', '/admin/report', cookieA))
const ended = strategy.endAllSessionsFor('ada')
print('J5', 'server ends every session for ada (sessions ended: ' + ended + '), cookie A', await send(server, 'GET', '/admin/report', cookieA))
users.get('ada').role = 'member'
print('J6', 'stale role, ada demoted to member in the user store, cookie A', await send(server, 'GET', '/admin/report', cookieA))
const cookieB = await signIn(server, 'ada')
print('J7', 'fresh sign-in after the demotion, cookie B', await send(server, 'GET', '/admin/report', cookieB))
users.get('ada').role = 'admin'
secrets.list = [INVENTED_SECRET_NEW, INVENTED_SECRET_OLD]
const cookieC = await signIn(server, 'ada')
print('J8', 'rotation, new secret first and old secret second, cookie A', await send(server, 'GET', '/admin/report', cookieA))
secrets.list = [INVENTED_SECRET_NEW]
print('J9', 'rotation, old secret removed, cookie A', await send(server, 'GET', '/admin/report', cookieA))
print('J10', 'rotation, old secret removed, cookie C issued under the new secret', await send(server, 'GET', '/admin/report', cookieC))
clock.advance(MAX_AGE_SECONDS + 1)
print('J11', 'expired, clock moved past the maximum age, cookie C', await send(server, 'GET', '/admin/report', cookieC))
await new Promise((resolve) => server.close(resolve))
}
async function runDatabaseSet() {
const clock = createClock()
const users = createUserStore()
const secrets = { list: [INVENTED_SECRET_OLD] }
const strategy = createDatabaseStrategy({ secrets, users, clock })
const server = await startLabServer(strategy)
console.log('Strategy: database (opaque id in the cookie, session row kept on the server)')
const cookieA = await signIn(server, 'ada')
print('D1', 'baseline, cookie A (ada, admin) on GET /admin/report', await send(server, 'GET', '/admin/report', cookieA))
print('D2', 'tampered, cookie A with one character changed', await send(server, 'GET', '/admin/report', tamper(cookieA)))
print('D3', 'forged, a well-formed id the server never issued', await send(server, 'GET', '/admin/report', '00000000-0000-4000-8000-000000000000'))
await send(server, 'POST', '/signout', cookieA)
print('D4', 'replay after sign-out, cookie A saved before signing out', await send(server, 'GET', '/admin/report', cookieA))
const cookieB = await signIn(server, 'ada')
const ended = strategy.endAllSessionsFor('ada')
print('D5', 'server ends every session for ada (sessions ended: ' + ended + '), cookie B', await send(server, 'GET', '/admin/report', cookieB))
const cookieC = await signIn(server, 'ada')
users.get('ada').role = 'member'
print('D6', 'stale role, ada demoted to member in the user store, cookie C', await send(server, 'GET', '/admin/report', cookieC))
users.get('ada').role = 'admin'
clock.advance(MAX_AGE_SECONDS + 1)
print('D7', 'expired, clock moved past the maximum age, cookie C', await send(server, 'GET', '/admin/report', cookieC))
console.log('D7 session rows left after the expired read: ' + strategy.sessions.size)
await new Promise((resolve) => server.close(resolve))
}
async function runRouteHandlerSet() {
const clock = createClock()
const users = createUserStore()
const secrets = { list: [] }
const strategy = createSealedCookieStrategy({ secrets, users, clock })
const server = await startLabServer(strategy)
console.log('Route handler checks with no secret configured (the session reader returns an error object)')
print('R1', 'existence check, if (session), request with no cookie', await send(server, 'GET', '/existence-check'))
print('R2', 'user check, if (session && session.user), request with no cookie', await send(server, 'GET', '/user-check'))
await new Promise((resolve) => server.close(resolve))
}
await runSealedCookieSet()
await runDatabaseSet()
await runRouteHandlerSet()
console.log('All lab servers stopped.')
PART 5. RUNNING THE LAB, AND WHAT IT PRINTED
How to run it:
- Save the files from Part 3 and Part 4 into an empty folder, with the names shown, and open a terminal there.
- Run: node run-session-tests.mjs
- It starts each lab server on 127.0.0.1 at a port the system picks, sends the requests with node:http, prints a line for each run and stops every server before it exits. Cookie values are never printed; each cookie the lab server issued at sign-in is named by a letter.
- Apart from the runner importing session-lab.mjs, the lab imports only node:http and node:crypto, and it installs no packages. Use it to see how the two strategies differ, or as a pattern for tests on your own local or staging copy: test accounts you created, with email addresses you control, no more than five requests per run, no load and no real user's session.
What the labels mean:
- J runs use the sealed cookie strategy (the session is encrypted into the cookie with AES-256-GCM, in a format of the lab's own rather than Auth.js's JWE, and nothing is kept on the server).
- D runs use the database strategy (the cookie holds a random id, and the server keeps a session row and reads the current role from the user store on each request).
- R runs start a server with no secret configured, where the session reader returns an error object, modelled on the behaviour GHSA-8fpg-xm3f-6cx3 describes.
Output of node run-session-tests.mjs on Node.js v26.0.0, copied from the captured file. It held no local paths, so no line was cut.
Strategy: sealed cookie (session sealed into the cookie, nothing kept on the server)
J1 baseline, cookie A (ada, admin) on GET /admin/report: 200 accepted, role used: admin
J2 tampered, cookie A with one character changed: 401 refused
J3 forged, a cookie sealed under a secret the server does not hold: 401 refused
J4 replay after sign-out, cookie A saved before signing out: 200 accepted, role used: admin
J5 server ends every session for ada (sessions ended: 0), cookie A: 200 accepted, role used: admin
J6 stale role, ada demoted to member in the user store, cookie A: 200 accepted, role used: admin
J7 fresh sign-in after the demotion, cookie B: 403 refused, role used: member
J8 rotation, new secret first and old secret second, cookie A: 200 accepted, role used: admin
J9 rotation, old secret removed, cookie A: 401 refused
J10 rotation, old secret removed, cookie C issued under the new secret: 200 accepted, role used: admin
J11 expired, clock moved past the maximum age, cookie C: 401 refused
Strategy: database (opaque id in the cookie, session row kept on the server)
D1 baseline, cookie A (ada, admin) on GET /admin/report: 200 accepted, role used: admin
D2 tampered, cookie A with one character changed: 401 refused
D3 forged, a well-formed id the server never issued: 401 refused
D4 replay after sign-out, cookie A saved before signing out: 401 refused
D5 server ends every session for ada (sessions ended: 1), cookie B: 401 refused
D6 stale role, ada demoted to member in the user store, cookie C: 403 refused, role used: member
D7 expired, clock moved past the maximum age, cookie C: 401 refused
D7 session rows left after the expired read: 0
Route handler checks with no secret configured (the session reader returns an error object)
R1 existence check, if (session), request with no cookie: 200 accepted
R2 user check, if (session && session.user), request with no cookie: 401 refused
All lab servers stopped.What Auth.js does in your application, and what it leaves to you
Auth.js is a library you install into your application.
The installation page shows one package per framework: next-auth for Next.js, installed with the beta tag, @auth/sveltekit for SvelteKit and @auth/express for Express, with Qwik added through its own CLI. In a Next.js application, a configuration file (auth.ts, by the documentation's convention) passes the options to NextAuth() and exports the auth function, the sign-in and sign-out methods and the handlers, and an App Router route handler exports those handlers as GET and POST.
The @auth/core reference gives that route's base path as /api/auth in next-auth and /auth in the other frameworks. The upgrade guide calls version 5 of the next-auth package NextAuth.js v5, and some advisories in the log below use the NextAuth.js name.
The Auth.js pages cited in this guide describe that version line: next-auth version 5, which the installation page and the upgrade guide install with the beta tag, and the @auth/* packages.
The session, secure-cookie and redirect defaults quoted below come from the @auth/core reference, and the next-auth reference gives the same ones for its own configuration type, NextAuthConfig. Version 4 appears here only in the upgrade guide's renames and in the advisories.
That arrangement puts many of the decisions in your hands. Auth.js runs the sign-in flows and creates the session, sealed into a cookie or stored in your database. Your configuration and code decide who may sign in, which roles exist, how long a session lasts and what each route checks.
The role-based access control guide says it in one line: determining the user's role is your responsibility. The credentials page says that by default the Credentials provider does not persist data in the database, and that you can still save data there but have to provide the necessary logic, for example to encrypt passwords, add rate limiting and add password reset.
Notices on the documentation site belong at the start of any review. The documentation pages read for this guide show the line "The Auth.js project is now part of Better Auth." The Auth.js security page says "Security updates are only released for the current latest version", and that old releases are not maintained and do not receive updates.
As read on 14 November 2026, it also said the @auth/* packages, other than the database adapters, were under development and, unless stated otherwise, not considered ready for production. The version item in the decision table exists because of those statements.
JWT or database sessions: the choice that decides what you can revoke
The session strategies page describes the JWT-based session and the database session as the main session strategies Auth.js supports, chosen with the session.strategy option.
The @auth/core reference gives the default as "jwt", an encrypted JWT in the session cookie, and says the default becomes "database" when an adapter is used, though "jwt" can still be forced. With the database strategy, the session cookie only contains a session token, which is used to look up the session in the database.
The session strategies page sets out what follows from each. With JWT sessions, signing out deletes the cookie, but expiring a token before its encoded expiry is not possible without a server-side blocklist, and a copy of the JWT saved elsewhere is accepted until it expires. With database sessions, signing out deletes the session from the database, and sessions can be modified on the server at any time, so you can implement features such as "sign out everywhere" or limiting concurrent logins, which the page says might be more difficult, but not impossible, with the JWT strategy.
The upgrade guide shows a third arrangement that is easy to miss. For an adapter that is not compatible with the Edge runtime, its example keeps the adapter in auth.ts, forces the jwt strategy there, and initialises Auth.js in the proxy without the adapter.
An application built that way keeps users and accounts in the database and still issues JWT sessions, so the JWT rules above apply to its sessions. Read the strategy the configuration produces, not the presence of a database.
This page's view: if your application needs to end a session from the server, after a staff member leaves or a laptop goes missing, the database strategy does that with a delete. If it uses JWT sessions, plan on a copied cookie working until it expires and set the maximum age with that in mind.
The JWT security guide covers the general trade-off between self-contained tokens and server-side sessions; this page stays with the Auth.js settings.
What to read in an Auth.js configuration that uses JWT sessions
Start with the lifetime.
The @auth/core reference gives session.maxAge a default of 2592000 seconds (30 days) and session.updateAge a default of 86400 seconds (1 day), and the upgrade guide says that whenever auth() is passed the response object it rotates the session expiry. The session strategies page says a saved copy of the JWT is accepted until it expires.
This page's reading is that maxAge, which the reference describes as the relative time from now when the session expires, is the figure to plan around.
Then the claims. The role-based access control guide persists a role in the JWT strategy by assigning user.role to token.role in the jwt callback on sign-in, and its example does so only when a user object is present. The reference says that callback is called whenever a token is created at sign-in or updated whenever a session is accessed in the client, that what it returns is saved in the token, and that the user parameter is available when the trigger is a sign-in or a sign-up.
The guide says that with this strategy, if you want to update the role, the user needs to be forced to sign in again.
Runs J6 and J7 in the lab illustrate that on invented code: the demoted user's old cookie still carries admin, and only a fresh sign-in carries the new role.
Two more callback details belong in the review. The reference says that, with the jwt strategy, the session parameter of the jwt callback carries data sent from the client through useSession().update, and that you should validate it before using it. It also says the session callback's return value is exposed to the client, and that by default only the email, name and image are returned. Any further field added there, such as a provider access token, is therefore sent to the browser.
Where the application calls a provider's API on the user's behalf, the refresh token rotation guide, as read on 14 November 2026, says there is no built-in solution for automatic refresh token rotation. With the jwt strategy, it says Auth.js libraries store the refresh_token in an encrypted JWT in an HttpOnly cookie, and that storing it in a cookie is simpler but less secure; with the database strategy, the access_token, expires_at and refresh_token are saved on the account for the provider.
By default, the token itself is encrypted. The jwt reference says Auth.js encrypts its JWT by default with the A256CBC-HS512 algorithm (JWE), using a key derived from AUTH_SECRET or the secret option passed in, and that these tokens are meant to be used by the same app that issued them; for JWT authentication to a third-party API, it points to your identity provider instead.
The session strategies page adds that data in an encrypted JWT should not be assumed to be impossible to decrypt at some point, and recommends a secret with high entropy.
AUTH_SECRET: where it is set and what depends on it
The installation page calls AUTH_SECRET the only mandatory environment variable, a random value used to encrypt tokens and email verification hashes.
The deployment page says it should be a cryptographically secure random string of at least 32 characters. Its value never belongs in a review record. What the review records is where it is set, in which environments, and who can read those settings.
The installation page says the Auth.js CLI adds the generated secret to the .env file, following the framework's convention, such as .env.local for Next.js. That is convenient on a laptop and worth checking in a repository, so the decision table asks for the names of any committed files that hold an AUTH_SECRET line, found with a search that lists file names only.
The upgrade guide says environment variables should be prefixed with AUTH_ and that NEXTAUTH_ is no longer in use, so the table also lists any NEXTAUTH_ variable still set, by name.
The @auth/core reference describes how to rotate the secret. The secret option can take an array, the first secret that successfully decrypts the JWT is used, and the newer secret goes at the start of the array, where it is used for all new sessions. Runs J8 to J10 in the lab follow that order: with the new secret first and the old one second, a cookie sealed under the old secret still opens; once the old secret is removed it does not, and a cookie sealed under the new secret keeps working.
Two deployment details reach the secret. For preview deployments that use AUTH_REDIRECT_PROXY_URL, the deployment page says the AUTH_SECRET value needs to be the same for the stable deployment and the previews that need OAuth, that the redirect is secured by relying on that shared secret, and that the stable deployment can be the main site.
On this page's reading, anyone who can read a preview's environment settings can read the secret the stable deployment uses, which is why the table asks who that is.
And GHSA-8fpg-xm3f-6cx3 names an unset AUTH_SECRET as one of the configuration errors behind the fail-open checks described in the route checks section below.
Providers, scopes, account linking and adapter records
Each provider requests the scopes it is configured with.
The guide to configuring OAuth providers says options passed to a provider are deeply merged with its defaults, and that overriding "authorization.params.scope" is enough to change the scopes. This page's advice: list each provider's scopes next to the feature that uses them, because a scope nothing uses is access granted for no purpose, and with an adapter the tokens that carry it are stored by default, as the next paragraph shows.
The database models page says the Account model saves access_token, expires_at, refresh_token, id_token, token_type, scope and session_state by default, and the providers reference says a provider's account callback returns the subset that is saved. An account table can therefore hold provider tokens for every user who has signed in through an OAuth provider, so the decision table asks whether those columns hold values, as a count, and who can read the table, never for the values.
The database models page also says an expired session is deleted when it is read, and that each email sign-in token is usable only once, with a default lifetime of 1 day. The magic links page says an email provider cannot be enabled without a database.
The OAuth checks and linking rules are provider settings too. The providers reference gives the checks option a default of PKCE, says state is added automatically when a redirect proxy URL is set, and lists none, state, nonce and pkce as the values for OpenID Connect providers.
It says accounts with the same email address are not linked automatically on OAuth sign-in, that automatic account linking on sign-in is not secure between arbitrary providers and is disabled by default, and that allowDangerousEmailAccountLinking turns it on, which it says may be desirable if you trust the provider to have securely verified the email address.
The database models page says linking otherwise happens automatically only when the addresses match and the user is signed in. The OAuth and OpenID Connect guide explains what state, nonce and PKCE each protect.
The deployment page also recommends a different OAuth app for development and production when users are stored in a database, so that test and production user bases do not mix. The table records which OAuth app each environment uses.
Callbacks and route handlers: where the access decision is made
Auth.js gives you several places to make an access decision, and they are not equivalent.
The signIn callback, which the @auth/core reference says controls whether a user is allowed to sign in, decides who gets a session at all. The "authorized" callback, which the next-auth reference says is invoked when a user needs authorisation using Middleware, decides what the proxy lets through. The protecting resources page says not to rely on the proxy exclusively for authorisation, and to verify the session as close to your data fetching as possible.
The Next.js guide explains why middleware is a filter rather than the boundary; for Auth.js, the question is what each check actually tests.
One advisory answers that question directly. GHSA-8fpg-xm3f-6cx3 (CVE-2026-73421), published on 20 July 2026, says that when the Auth.js configuration produces a server-side error, the auth object is populated with an error object instead of being null, so an application that checks only whether the auth object exists treats every request, including unauthenticated ones, as authenticated.
It lists next-auth 5.0.0-beta.0 to 5.0.0-beta.31 as affected and 5.0.0-beta.32 as patched, and says there is no impact while the configuration is valid. Its workaround, for those who cannot upgrade immediately, is to check a concrete property such as auth.user rather than the bare object.
The protecting resources page, as read on 14 November 2026, shows existence checks in its examples: its proxy example's "authorized" callback returns !!auth, and its Next.js App Router API route example returns the session when req.auth is present.
The next-auth reference example for the same callback returns !!auth.user. The advisory says its fix makes existence checks fail closed rather than open. Checking for the user rather than the object is the form both the advisory's workaround and the reference example use.
Runs R1 and R2 in the lab illustrate the difference on invented code: with no secret configured, the existence check lets a request with no cookie through and the user check refuses it.
A session is still not permission. GHSA-v64w-49xw-qq89 notes that the existence of a NextAuth.js session state can provide simple authentication, but not authorisation, and the role-based access control guide shows the server-side form: import the auth function and verify that the user has the expected role. This page's advice is that each route handler and server function returning data makes that check itself, against the record being asked for.
next-auth advisories to check your version against
This log lists advisories from the nextauthjs/next-auth repository that bear on the settings in this guide, each read on its repository advisory page on 14 November 2026.
Version ranges come from each advisory's version fields. It is a log as of that date, not a complete list: the repository's advisories page also holds earlier advisories, including advisories published in 2022, and is the place to check for newer ones. Compare the resolved next-auth version in the lockfile of your deployed build with each entry.
- GHSA-8fpg-xm3f-6cx3 (CVE-2026-73421), published 20 July 2026: configuration errors can make existence-based auth checks fail open. Affected: next-auth 5.0.0-beta.0 to 5.0.0-beta.31. Patched: next-auth 5.0.0-beta.32. Workaround, if you cannot upgrade immediately: check a concrete property such as auth.user rather than the bare auth object.
- GHSA-x445-f3h2-j279 (CVE-2026-73419), published 20 July 2026: in affected versions, the cookies that hold the OAuth state, nonce and PKCE verifier are not bound to the provider that created them, which in a multi-provider app that allows account linking while logged in can let an attacker link their account at a second provider to a victim's user. Affected: next-auth up to 4.24.14 and 5.0.0-beta.1 to 5.0.0-beta.31, and @auth/core up to 0.41.2. Patched: next-auth 4.24.15 and 5.0.0-beta.32, and @auth/core 0.41.3. The advisory says apps with a single OAuth provider, no logged-in account linking, or PKCE enforced by every provider are not affected.
- GHSA-7rqj-j65f-68wh (CVE-2026-73420), published 20 July 2026: the default email normaliser for magic-link sign-in validates the address before Unicode normalisation, so a mail library that normalises the address may deliver the sign-in link to a different recipient than intended. Affected: next-auth from 4.10.3 to before 4.24.15 and 5.0.0-beta.1 to 5.0.0-beta.31, and @auth/core from 0.1.0 to before 0.41.3. Patched: next-auth 4.24.15 and 5.0.0-beta.32, and @auth/core 0.41.3. The advisory says apps that do not use the email provider, or whose normaliser or mailer rejects or canonicalises non-ASCII addresses before validating them, are not affected.
- GHSA-xmf8-cvqr-rfgj (CVE-2026-73418), published 20 July 2026: getToken() can throw an uncaught exception when it reads a malformed Bearer header. Affected: next-auth 4.0.6 to 4.24.14 and 5.0.0-beta.0 to 5.0.0-beta.31, and @auth/core from 0.1.0 to before 0.41.3. Patched: next-auth 4.24.15 and 5.0.0-beta.32, and @auth/core 0.41.3. The advisory says apps that only use the framework's auth() helper and never call getToken() themselves, or that wrap every getToken() call in their own exception handling, are not affected.
- GHSA-5jpx-9hw9-2fx4, "NextAuthjs Email misdelivery Vulnerability", published 27 October 2025, with no known CVE: email sign-in can be forced to deliver authentication emails to an attacker-controlled mailbox because of a bug in the nodemailer address parser the project uses, which the advisory says was fixed in nodemailer v7.0.7. Affected: next-auth below 4.24.12 and below 5.0.0-beta.30. Patched: next-auth 4.24.12 and 5.0.0-beta.30.
- GHSA-v64w-49xw-qq89 (CVE-2023-48309), published 20 November 2023: next-auth applications prior to 4.24.5 that rely on the default Middleware authorisation are affected, because a JWT from an interrupted OAuth sign-in flow could stand in for the session cookie and simulate a logged-in user with no user information. Affected: next-auth below 4.24.5. Patched: next-auth 4.24.5.
- GHSA-7r7x-4c4q-c4qf (CVE-2023-27490), published 9 March 2023: in next-auth applications using OAuth before 4.20.1, someone who can spy on the victim's network, or who gets the victim to click a manipulated login link, could intercept and tamper with the authorisation URL to log in as the victim, bypassing the CSRF protection. Affected: next-auth below 4.20.1. Patched: next-auth 4.20.1.
How to fill in the decision table
The asset on this page has five parts.
Part 1 is a decision tree: two questions settle which session strategy your configuration really runs, and the answer says which items in Part 2 carry the most weight. Part 2 is the record sheet, thirteen items, each naming where to look, what the named Auth.js page or advisory says and what to write down, with the lab runs that show the behaviour where there are any. Parts 3 to 5 are the lab described in the next section.
- Work from the configuration files, the variable names in your hosting provider's environment settings and its member list, the values of AUTH_TRUST_HOST and AUTH_URL, the lockfile of the deployed commit, counting queries on your own database, the advisory log on this page and the repository's advisories page, and the person who runs your proxy. Every item only reads; none changes a setting, rotates a secret or sends traffic to a service you do not own, and none asks you to open an environment settings screen or an .env file that shows a secret's value.
- Record that a secret is set, never its value, and never copy a cookie, token or password into the sheet. Where an item looks at a file, a table or a configuration that can hold a secret or a token, it asks for a yes or no, a count or a name, never the secret or token itself.
- Fill in one copy for each environment that issues sessions: production, staging and previews. Previews that use the redirect proxy share the stable deployment's AUTH_SECRET by design, as the AUTH_SECRET section explains.
- Date each copy and note the next-auth version it was read against. A change to the configuration file, the adapter or the next-auth version is the moment to fill it in again.
Running the session test set on your own machine
Parts 3 to 5 of the asset illustrate the difference between JWT and database sessions.
They are not a test of Auth.js, and the lab holds no Auth.js code. It runs a small server with two invented users, ada (admin) and ben (member), in two modes. In sealed cookie mode the session is encrypted into the cookie with AES-256-GCM, in a format of the lab's own rather than Auth.js's JWE, and nothing is kept on the server.
In database mode the cookie holds a random id, and the server keeps a session row and reads the user's current role on each request.
The secrets are invented and labelled so in the code. The server binds to 127.0.0.1 at a port the system picks and keeps everything in memory. Apart from the runner importing the lab file, the two files import only node:http and node:crypto, and nothing is installed.
Part 5 holds the output of node run-session-tests.mjs on Node.js v26.0.0 with the files as shown, copied from the captured file by a script.
Run node run-session-tests.mjs in a folder holding the two files. It prints a line for each run, never prints a cookie's value, names each cookie the lab server issued at sign-in by a letter, and stops every server before it exits. This is what each group of runs showed; Part 5 has the exact lines.
- J1 and D1: the admin cookie was accepted on GET /admin/report in both modes (200).
- J2, J3, D2 and D3: a cookie with one character changed, a cookie sealed under a secret the server does not hold, and an id the server never issued were each refused with 401.
- J4 and D4: a cookie saved before signing out and sent again afterwards was accepted in sealed cookie mode (200) and refused in database mode (401).
- J5 and D5: when the server ended every session for ada, sealed cookie mode had nothing to end (sessions ended: 0) and the old cookie was still accepted; database mode ended one session and the cookie was refused.
- J6, J7 and D6: after ada was demoted to member in the user store, the old sealed cookie still carried admin and was accepted, while a fresh sign-in carried member and was refused with 403. Database mode read the current role and refused the existing session with 403.
- J8, J9 and J10: with the new secret first and the old one second, the old cookie was accepted; once the old secret was removed it was refused, and a cookie sealed under the new secret was accepted.
- J11 and D7: once the lab clock passed the maximum age, both modes refused the cookie, and database mode printed 0 session rows left after the expired read.
- R1 and R2: with no secret configured, the session reader returned an error object, modelled on the behaviour GHSA-8fpg-xm3f-6cx3 describes. The existence check accepted a request with no cookie, and the check for session.user refused it.
Using the same runs on your own application
The runner sends every request over HTTP, and makes the demotion, the session ending, the secret change and the clock move in the lab's memory. The HTTP part of the sequence can be pointed at a local or staging copy of your own application: sign in as a test account you created, with an email address you control, keep the cookie in the test script's memory as the lab does, never in notes or logs, then sign out or demote that test account and send the cookie again.
Keep each run to no more than five requests, never use a real user's session, and run it only against applications you own or are authorised in writing to test. The R runs need a server with no secret configured, so they stay in the lab.
What a review of your own configuration cannot show
The decision table describes how your configuration is meant to behave.
Some questions need evidence it cannot hold.
- Whether a copied cookie is already in someone else's hands. The table shows how long a copy would keep working, not whether one exists.
- What the identity provider does on its side: whether it verified an email address, which scopes a user consented to, and how its own sessions end. Those settings live with the provider and its own documentation.
- Whether every handler checks its caller. Part 2 lists the handlers you know about; routes added later, or reachable in forms the proxy matcher does not cover, need testing against the running application.
- Whether the proxy in front of the application sets X-Forwarded-Host itself. The configuration shows trustHost; only the proxy's own settings, or a request to the running application, show what reaches it.
- Whether your own code around Auth.js holds: ownership checks, the way roles are updated, and what a session callback returns. A flaw there belongs to the application, and an Auth.js upgrade leaves it in place.
- Which attributes the production site's cookies actually carry. The table reads the configuration, so the cookies the running site sets need checking against the running application.
Where an outside test fits
This guide covers a review you can run on your own configuration.
It does not describe a test of the Auth.js library or of any identity provider's platform. Active testing of your own running application sits within a scoped Clever Ops web application and API penetration test, a signed-in test of a custom application whose coverage includes authentication and sessions and what each role can see and change.
Its session checks include replaying the old session after sign-out to see whether the server still accepts it, and checking whether an account's open sessions stop working once an administrator suspends that account.
For the code itself, a Clever Ops secure code review reads custom web applications and their APIs, such as Next.js, React and Node applications, through read-only access to your repository. Its written scope names the areas read, for example the authorisation layer and every route that returns customer data. In an Auth.js application, the callbacks and route checks above sit in those areas.
In the report, every finding carries its evidence, a fix written for your stack and the criteria its retest will use. When Clever Ops built or hosts the application, the work is called a security review rather than an independent test, and the report records who built the application and who hosts it.
Frequently asked questions
With database sessions, your application can: the Auth.js session strategies page says database sessions can be modified on the server at any time, so you can implement features such as "sign out everywhere". With JWT sessions, it says expiring a token before its encoded expiry needs a server-side blocklist, and that a copy of the JWT saved elsewhere is accepted until it expires, even after Auth.js destroys the cookie. The @auth/core reference gives a default maximum age of 30 days, so check what yours is set to.
The @auth/core reference gives the default as "jwt", an encrypted JWT in the session cookie, and says it becomes "database" when an adapter is used. A JWT strategy can still be forced alongside an adapter, which the upgrade guide shows for adapters that are not compatible with the Edge runtime. Read the adapter option and session.strategy together to know which one runs.
The @auth/core reference says the secret option accepts an array: the first secret that successfully decrypts a JWT is used, and the newer secret goes at the start of the array, where it is used for all new sessions. This page's advice is to remove the old secret once sessions sealed under it have passed their maximum age. The deployment page asks for a cryptographically secure random string of at least 32 characters.
Yes. They are published as security advisories in the nextauthjs/next-auth repository on GitHub. Each advisory in this page's log that was published on 20 July 2026 lists next-auth 5.0.0-beta.32 as patched for version 5, and those that also affect version 4 list next-auth 4.24.15. Check the resolved version in your deployed lockfile against the log on this page, then against the repository's advisories page for anything newer. The Auth.js security page says "Security updates are only released for the current latest version".
Not by default. The @auth/core providers reference says accounts with the same email address are not linked automatically on OAuth sign-in, that automatic account linking on sign-in is not secure between arbitrary providers and is disabled by default, and that allowDangerousEmailAccountLinking turns it on, which it says may be desirable if you trust the provider to have securely verified the address. The database models page says linking otherwise happens automatically only when the addresses match and the user is signed in.
With JWT sessions, the Auth.js role-based access control guide stores the role in the token through the jwt callback at sign-in, and says that with this strategy, if you want to update the role, the user needs to be forced to sign in again. With database sessions, the guide's session callback copies the role from the user record, and the @auth/core reference says that callback is called whenever a session is checked. Runs J6 and D6 in this page's lab illustrate both on invented code.
Scope the right test for your application
Tell us what you have built, who uses it and when it needs to launch. You will get a plain-English recommendation: a website audit, a web application test or a referral to a specialist.