Repository navigation
Description
Preliminary Checks
- I have reviewed the documentation: https://clerk.com/docs
- I have searched for existing issues: https://github.com/clerk/javascript/issues
- I have not already reached out to Clerk support via email or Discord
- This issue is a bug report directly related to Clerk
Note: I first reported this privately to security@clerk.dev. The security team confirmed it is a real bug, classified it as low-severity hardening, and said a public issue is fine.
Reproduction
Self-contained snippet below (no project needed). It uses a made-up key, so no real instance is involved.
Publishable key
N/A. The snippet builds a fake live key for clerk.example.com.
Description
If the __session cookie holds a three-part token whose payload segment decodes to the JSON literal null (for example <header>.bnVsbA.<sig>), authenticateRequest() throws instead of returning a signed-out or handshake state:
TypeError: Cannot read properties of null (reading 'iss')
In Next.js, clerkMiddleware() calls authenticateRequest() before the route handler, so every route covered by the middleware, including the sign-in page, responds with 500 until the user clears the cookie.
The token cannot occur by accident. It needs someone who can set a cookie for the app's domain (for example from a sibling subdomain).
Reproduction with @clerk/backend 3.33.0 on Node 24:
import { createClerkClient } from "@clerk/backend";
const fapi = "clerk.example.com";
const clerk = createClerkClient({
secretKey: "sk_live_" + "x".repeat(40),
publishableKey: "pk_live_" + Buffer.from(fapi + "$").toString("base64"),
});
const b64 = (s) => Buffer.from(s).toString("base64url");
const token = b64('{"alg":"RS256","kid":"x"}') + "." + b64("null") + ".c2ln";
const cookie = "__session=" + token + "; __client_uat=" + Math.floor(Date.now() / 1000);
await clerk.authenticateRequest(
new Request("https://app.example.com/", { headers: { cookie, accept: "text/html", "sec-fetch-dest": "document" } }),
);
// -> TypeError: Cannot read properties of null (reading 'iss')
// Same result without __client_uat. Also reproduced on 3.33.1-canary.v20261125163017.
Cause: decodeJwt() in packages/backend/src/jwt/verifyJwt.ts returns { data } whenever JSON.parse succeeds, so a payload of null passes. AuthenticateContext.tokenHasIssuer() in packages/backend/src/tokens/authenticateContext.ts then reads data.payload.iss without a guard. #9268 fixed payloads that fail to parse, but not payloads that parse to a non-object value.
Suggested fix: in decodeJwt(), return a TokenVerificationError (reason TokenInvalid) when the decoded header or payload is not a plain object. That protects every caller of decodeJwt(), not only tokenHasIssuer().
Environment
@clerk/backend: 3.33.0 (also 3.33.1-canary.v20261125163017, and the current main)
@clerk/nextjs: 7.9.19 (observed through clerkMiddleware)
Node: 24.22.1
OS: macOS
Activity