Skip to content
Access control Write-up Intermediate

What Happens on Next.js?

Next.js versions 14.2.25 and 15.2.3 mishandle trailing slashes and URL encoding, allowing attackers to bypass middleware authorization checks. An attacker could access protected routes without authentication, potentially exposing sensitive data.

medium.com

Published on medium.com

Companies choose Next.js because it delivers high performance, scalability, and flexibility. Its server-side rendering (SSR) ensures faster load times and better SEO, making websites more discoverable.

CUBeeSEC Securities, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the middleware's path matching did not normalise URLs, so paths with trailing slashes or encoded slashes were treated as different and skipped the authorization check.

Impact

Attackers could bypass middleware authorization checks and access protected routes, potentially exposing sensitive data or restricted resources.

What the attacker needed

Next.js 14.2.25 or 15.2.3; Middleware used for authorization; Ability to send crafted HTTP requests

The fix

The vulnerability was fixed in newer Next.js releases; additionally, URLs should be normalised before authorization checks and server-side authorization should be added as a backup.

How it was found

  1. Send a request to a middleware-protected route with an invalid authentication cookie.
  2. Observe that the middleware redirects to the login page.
  3. Modify the request path by adding a trailing slash or encoding the slash.
  4. Send the modified request and observe that the middleware is skipped, granting access.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Middleware is code that runs before a request reaches a page, often used to check if a user is logged in. In these Next.js versions, the middleware failed to recognise some URL variations, so an attacker could skip the login check and reach protected pages.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.