Skip to content

Middleware crashes when JWT is expired #2081

Open
@pmmmwh

Description

@pmmmwh

Checklist

Description

In v4.5.1 (latest version at the time of writing), a security patch was released to ensure JWTs are expired alongside the cookies.
However, that has caused some side-effects - the middleware now crashes with HTTP 500 whenever an expired JWT hits the server:

[JWTExpired: "exp" claim timestamp check failed]

I am not sure this is an intentional behaviour or an oversight? Coming from the user's perspective, I felt like the middleware should have caught this and handled as if there is no session, instead of throwing. How it is handled could dependant on the route - e.g. profile should return 401, and for non-auth routes probably short circuit the session updates.

Reproduction

  1. Obtain an expired JWT
  2. Hit the Next.js server wired up with the Auth0 middleware
  3. Boom, HTTP 500

Additional context

No response

nextjs-auth0 version

4.5.1

Next.js version

14.2.28

Node.js version

22.14.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions