refresh operation throws a TypeError (500) when the session is revoked between the JWT strategy read and its own read
I maintainer di solito rispondono entro 1 giorno
@bfs2021 ci sta già lavorando.
Dal 23/11/2026.
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- Meno di un'ora
- Idoneità per principianti
- 82/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- authentication
Direzione di ricerca
Inizia in packages/payload/src/auth/operations/refresh.ts alla ricerca user.sessions.find(...) e alla scrittura su existingSession.expiresAt che la segue; la guardia su user.sessions/sid sopra non copre una sessione che è scomparsa. Esegui il repro collegato nell'issue (pnpm repro contro la linea 3.x) per vedere 200/500/500, e leggi l'hook beforeOperation nel suo src/collections/Users.ts per vedere la revoca a metà richiesta. Fatto assomiglia a: il witness case restituisce ancora 200 ed entrambi i casi di revoca restituiscono 403 Forbidden, coerentemente con il modo in cui la strategia JWT tratta una sessione mancante.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the Bug
With auth.useSessions enabled (the default), POST /api/{auth-collection}/refresh-token answers 500 instead of 403 when the caller's session is removed from the user document after the JWT strategy has authenticated the request and before refreshOperation reads the user again.
packages/payload/src/auth/operations/refresh.ts (3.x) looks the session up and writes on it with no check that it was found:
if (!Array.isArray(user.sessions) || !sid) {
throw new Forbidden(args.req.t)
}
const existingSession = user.sessions.find(({ id }: { id: number }) => id === sid)
const now = new Date()
const tokenExpInMs = collectionConfig.auth.tokenExpiration * 1000
existingSession.expiresAt = new Date(now.getTime() + tokenExpInMs)
user.sessions is still an array (empty, or holding other sessions), so the first check passes, find returns undefined, and the assignment throws:
TypeError: Cannot set properties of undefined (setting 'expiresAt')
Anything that revokes the session while the request is in flight falls into that window: a logout from another tab, or a server-side revocation (sessions: []) made by another request or by a hook. An admin tab left open sends this request on its own, which is how we met it in our server logs: a 500 and an error alert where a refusal was expected.
Expected: Forbidden (403), as the JWT strategy already treats a missing session as "no user".
Suggested fix, right after the lookup:
if (!existingSession) {
throw new Forbidden(args.req.t)
}
main no longer has the problem (extendSession followed by if (!session)); this is for the 3.x line. Seen on 3.92.0, reproduced on 3.94.1.
Link to the code that reproduces this issue
https://github.com/JAPellerin/payload-refresh-repro
Reproduction Steps
- Clone the repository above (blank template, SQLite adapter, nothing to configure).
pnpm installpnpm repro
The script logs in through the Local API, then sends the real REST request through handleEndpoints three times. A beforeOperation hook on users (src/collections/Users.ts) removes the caller's session during the refresh operation: it runs after the JWT strategy has accepted the session and before the operation reads the user again.
Output on 3.94.1:
POST /api/users/refresh-token
200 session untouched (witness)
500 own session removed mid-request
500 every session removed mid-request
Expected: 200, 403, 403
Which area(s) are affected?
area: core
Environment Info
Binaries:
Node: 26.11.1
npm: 11.20.0
Yarn: N/A
pnpm: 11.28.5
Relevant Packages:
payload: 3.94.1
next: 16.4.6
@payloadcms/db-sqlite: 3.94.1
@payloadcms/drizzle: 3.94.1
@payloadcms/graphql: 3.94.1
@payloadcms/next/utilities: 3.94.1
@payloadcms/richtext-lexical: 3.94.1
@payloadcms/ui/shared: 3.94.1
react: 19.2.9
react-dom: 19.2.9
Operating System:
Platform: linux
Arch: x64
- Lingua principale
- TypeScript
- Stelle
- 46.1k
- Fork
- 4.5k
- Merge medio
- 2g 15h
- PR unite (30g)
- 238
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di payloadcms/payload
-
db-postgres: date-only range on a single field drops every operator after the first (greater_than_equal + less_than_equal)Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
payloadcms/payload#20110 ·
I maintainer di solito rispondono entro 1 giorno
-
website template: the seed button fails intermittently with a deadlock, because the seed clears collections in parallelForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaarea: templates Bug db: postgres Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
payloadcms/payload#20019 ·
I maintainer di solito rispondono entro 1 giorno
-
Uploading a file whose name ends in a long number loops forever when the name is takenForse già presa @JayPokale l’ha presa 7 giorni fa. Apertaarea: core Bug community-pr Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
payloadcms/payload#19978 ·
I maintainer di solito rispondono entro 1 giorno
-
[v4] A row whose fields are all hidden by their conditions still adds a field margin (regression from v3)Forse già presa @paulw1982 l’ha presa 7 giorni fa. Apertaarea: ui Bug community-pr created-by: Contributor Payload OSS status: needs-triage v3-only
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
payloadcms/payload#19976 ·
I maintainer di solito rispondono entro 1 giorno
-
[v3] Maximum update depth exceeded opening a document from the list view with cacheComponents: true (dev): backport #18702's CloseModalOnRouteChange guardForse di nuovo libera @MuhammadAhmad67889 l’ha presa 8 giorni fa e non c’è nessuna pull request aperta. Apertaarea: ui Bug Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
payloadcms/payload#19954 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di payloadcms/payload
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Vessel9817/onion-site-template#512 ·
I maintainer di solito rispondono entro 1 giorno
-
nightly-tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
BlackBeltTechnology/pi-agent-dashboard#1256 ·
I maintainer di solito rispondono entro 1 giorno
-
approved
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
fritzprix/libr-agent#3266 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
better-auth/better-auth#13101 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno