Multi-session: getToken() on a non-active session writes that session's token into __session
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 72/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- authentication
Línea de trabajo
Start in packages/clerk-js/src/core/resources/Session.ts at #hydrateCache and getToken(), then trace TokenUpdate handling in packages/clerk-js/src/core/auth/AuthCookieService.ts. Verify the active-session check against the described multi-session flow. Done means getToken() and hydration for an inactive session still return its token without updating __session, while the active session continues to update the cookie.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Preliminary checks
- I have reviewed the documentation: https://clerk.com/docs
- I have searched for existing issues: https://github.com/clerk/javascript/issues
- This issue is not a question, general help request, or feature request.
Reproduction
Found by reading the source. There is no public repro repo yet. The steps below reproduce it in any multi-session app.
- Turn on multi-session. Sign in as user A, then add user B in the same browser, so one client holds 2 sessions. A is the active session in the tab.
- In the focused tab, call
getToken()on B's session object, for exampleclerk.client.sessions.find(s => s.id !== clerk.session.id).getToken(). A common reason is to call your own API as B, for example to list B's data in an account switcher. - Read the
__sessioncookie. It now holds B's token. The next request from this tab to the app's server is authenticated as B, although the tab still shows A. - Keep the tab focused. B's token refreshes in the background about every 43 s, and each refresh writes
__sessionagain. The tab's own poller writes A's token back within about 1.5 s. So the server sees B for short windows, over and over.
Publishable key
Can share privately on request.
Description
In @clerk/[email protected], Session.getToken() decides whether to emit TokenUpdate like this:
const shouldDispatchTokenUpdate = !template && organizationId === this.lastActiveOrganizationId;
It does not check whether this is the client's active session. AuthCookieService writes every TokenUpdate into __session while the tab has focus:
The background-tab guard in updateSessionCookie (L202-L207) does not help here, because the tab that calls getToken() is the focused one.
#hydrateCache has the same gap. It sets shouldDispatchTokenUpdate = true for any session that it hydrates, so a non-active session whose last token still has more than about 17 s left gets a focused refresh that writes __session:
The code at main (2ee976bb66, 2026-09-28) is the same.
Expected: only the client's active session writes __session. getToken() on any other session returns a token and does not touch the cookie.
Actual: the cookie flips to the other user. In production, the server then sees user B for requests the user makes as A. For us that showed up as brief authorization refusals on pages that A may open. If both users belong to the same organization, a write could be attributed to the wrong user.
Suggested fix: also require this.id === <client's active session id> in both places, at L221 and L459. A JWT template token already skips the event, but templates cannot carry sid, so they are not a replacement for servers that check session revocation.
We are working around this by listing the other accounts' data on our server, and no longer calling getToken() on inactive sessions in the browser.
Environment
@clerk/clerk-js: 6.34.1 (loaded from the Clerk CDN via @clerk/shared 4.31.0)
@clerk/nextjs: current
Framework: Next.js (App Router)
Browsers: Chrome, Arc, Safari on macOS
Multi-session: enabled
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.8k
- Forks
- 477
- Merge medio
- 2 d 25 min
- PR fusionados (30 d)
- 267
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de clerk/javascript
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
clerk/javascript#10026 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
@clerk/nextjs: onBeforeSetActive never settles when invalidateCacheAction rejects (e.g. after a redeploy), so setActive and signOut hang foreverPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
clerk/javascript#9987 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
clerk/javascript#10011 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 50/100
clerk/javascript#9984 ·
Los mantenedores suelen responder en 1 día
-
M2M Token only authentication in Clerk MiddlewarePosiblemente ocupada @wobsoriano la tomó hace 8 días. Abiertoneeds-triage
clerk/javascript#9981 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de clerk/javascript
Issues similares
-
bug DUP Reservations
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
bcgov/reserve-rec-public#952 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
daufderheide/racecoordinator_ai#948 ·
Los mantenedores suelen responder en 1 día
-
Bug pulumi/pulumi
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
bug priority:high
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
api bug claude
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
diegosouzapw/OmniRoute#15764 ·
Los mantenedores suelen responder en 2 días