//nefariousplan

CVE-2026-44573: Next.js's resolveRoutes Prefixed Direct Pages With the Default Locale. It Did Not Prefix Data Routes.

vendor

patterns

cve

proof of concept

A request to GET /dashboard on a Next.js Pages Router app with i18n returns a 307 to /en/dashboard, where the middleware fires, sees no session cookie, and returns a 302 to the login page. A request to GET /_next/data/<buildId>/dashboard.json on the same server returns 200 with the rendered props for the same page. Same handler. Same default locale. Two locale-resolution sites in the same function, one of which forgot to apply the default-locale prefix to data routes. That is CVE-2026-44573.

The shape of the bypass

Every Next.js Pages Router page that uses getServerSideProps is served from two URLs. The first is the page URL the user types or clicks: /dashboard. The second is the data URL the client router fetches on subsequent navigations: /_next/data/<buildId>/dashboard.json. Both URLs run the same getServerSideProps. Both URLs return the same props. The page URL renders HTML around those props. The data URL returns the props as JSON.

On a vanilla single-locale app this duality is benign. The two URLs run the same handler, hit the same middleware, evaluate the same authorization, and either both succeed or both fail. They are two encodings of one resource.

Turn on i18n.

The moment a Next.js app declares a locales array and a defaultLocale, every route in that app has a locale dimension. /dashboard is no longer a path. It is shorthand for /<defaultLocale>/dashboard rewritten by the router as soon as the request lands. The user types /dashboard, the router observes that no locale prefix is present, the request is internally relabeled as /en/dashboard, and from that moment on, middleware sees a path with a locale segment. Middleware can be matched against that path. Authorization can be evaluated against that path. The whole framework is built on the assumption that by the time middleware runs, the locale has been resolved.

For direct page requests, that assumption holds. For /_next/data/<buildId>/dashboard.json requests, it did not.

This is CVE-2026-44573. It affects Next.js Pages Router applications that use i18n routing together with middleware whose matcher is scoped to a non-root path. It is fixed in v15.5.16 and v16.2.5. The patch is eleven lines. The defective code path was added at the same time as the working code path, in the same function, by the same author, with the same intent. One was correct. One was not.

Two locale-resolution sites in one function

The function is resolveRoutes in packages/next/src/server/lib/router-utils/resolve-routes.ts. It is the part of the Next.js dev server and standalone server that takes a raw incoming URL, classifies it (is this a static asset, a data route, a page route, an API route, a rewrite target), and produces a normalized internal pathname that downstream stages can match against.

For an i18n app, normalization means inserting the default locale when the request did not specify one. That logic appears in two places.

The first site runs early, before route classification. Pre-patch, it looked like this:

const initialLocaleResult = normalizeLocalePath(
  removePathPrefix(parsedUrl.pathname || '/', config.basePath),
  config.i18n?.locales
)

if (
  !initialLocaleResult.detectedLocale &&
  !initialLocaleResult.pathname.startsWith('/_next/')
) {
  parsedUrl.pathname = addPathPrefix(
    initialLocaleResult.pathname === '/'
      ? `/${defaultLocale}`
      : addPathPrefix(initialLocaleResult.pathname || '', `/${defaultLocale}`),
    hadBasePath ? config.basePath : ''
  )
}

Read what that says. Strip the basePath. Try to detect a locale in the remaining path. If no locale was detected, and the path is not internal (not under /_next/), prepend the default locale to the path and put the basePath back. After this block, parsedUrl.pathname is guaranteed to carry a locale segment for any non-internal request.

The second site runs much later, after the data-route normalizer has had a chance to strip /_next/data/<buildId>/...json off the front of the URL and reveal the underlying page path. Pre-patch:

let updated = false
if (normalizers.data.match(normalized)) {
  updated = true
  addRequestMeta(req, 'isNextDataReq', true)
  normalized = normalizers.data.normalize(normalized, true)
}

if (config.i18n) {
  const curLocaleResult = normalizeLocalePath(
    normalized,
    config.i18n.locales
  )

  if (curLocaleResult.detectedLocale) {
    addRequestMeta(req, 'locale', curLocaleResult.detectedLocale)
  }
}

Read what that says. If this is a data route, strip the /_next/data/<buildId>/ prefix and the .json suffix to reveal the page path. Then try to detect a locale in that page path. If a locale was detected, store it on the request metadata.

Compare the two blocks. The first does locale detection and then, if no locale was detected, applies the default locale as a prefix. The second does locale detection and then, if a locale was detected, stores it. There is no else branch. There is no default-locale fallback. A data request to /_next/data/<buildId>/dashboard.json in an i18n app with defaultLocale: 'en' and a logged-out user is processed as follows: the data normalizer strips the prefix and suffix to reveal /dashboard, normalizeLocalePath is called against /dashboard and the locales array, no locale is detected, control falls out of the i18n block with normalized still equal to /dashboard.

That is the path the middleware matcher will be evaluated against.

The matcher regex is not optional about the locale

When a Next.js project declares middleware with a matcher, that matcher is not used as a runtime string comparison. It is compiled into a regular expression at build time, in getMiddlewareMatchers in packages/next/src/build/analysis/get-page-static-info.ts. The compilation wraps the user's source pattern in two prefixes. The first is the optional data-route prefix:

const OPTIONAL_MIDDLEWARE_NEXT_DATA_PREFIX = '/:nextData(_next/data/[^/]{1,})?'

This makes the matcher tolerate both encodings of the same page. A request for /dashboard and a request for /_next/data/<buildId>/dashboard.json both run through the same matcher regex, because the matcher knows the framework rewrites between the two. The data prefix is optional.

The second wrap is the i18n locale prefix, applied when the project declares i18n in next.config.js and the matcher entry does not set locale: false:

if (i18n?.locales && matcher.locale !== false) {
  source = `/:nextInternalLocale((?!_next/)[^/.]{1,})${source}`
}

This locale prefix is not optional. There is no trailing ?. The compiled regex for matcher: '/dashboard' on an i18n project ends up looking roughly like:

^(?:/(_next/data/[^/]{1,}))?/(?<nextInternalLocale>(?!_next/)[^/.]+)/dashboard(\.json)?[/#?]?$

The matcher requires that some locale segment is present in the path. Not a specific locale. Any locale segment that consists of a non-empty run of characters that are not slashes, not dots, and are not the literal string _next/. If the matcher is going to fire, the path it is matched against must carry that segment.

This is consistent with the framework's invariant for direct page requests. By the time the matcher runs, those requests carry a locale segment, because the early locale-resolution site applies the default-locale prefix. The matcher does not need to handle the missing-locale case. The framework guarantees that case has been resolved upstream.

The framework did not guarantee it for data requests.

What the user types and what the matcher sees

Consider a project with defaultLocale: 'en', locales: ['en', 'fr'], and middleware whose matcher is /dashboard. A logged-out user requests /dashboard. The early locale-resolution site fires. The path has no locale prefix. The path is not internal. The block applies the default locale. The path becomes /en/dashboard. The matcher regex evaluates against /en/dashboard. The locale segment captures en. The matcher fires. Middleware runs. The middleware checks the session cookie, finds none, redirects to /login.

Now the same logged-out user requests /_next/data/<buildId>/dashboard.json directly. The early locale-resolution site fires. The path is internal. The block does not apply the default locale. The path is still /_next/data/<buildId>/dashboard.json. Later, the data normalizer strips the prefix and suffix. The second locale-resolution site fires. normalizeLocalePath is called against /dashboard. No locale is detected. The block exits without applying any prefix. The path is now /dashboard. The matcher regex evaluates against /dashboard. The mandatory locale segment is not present. The matcher does not fire. Middleware does not run.

Routing continues. The data request is dispatched to the getServerSideProps handler for the dashboard page. That handler, deeper in the stack, runs against the default locale, because the data path is treated as the default-locale data path by the page-rendering machinery that has no idea the matcher was skipped. The handler returns props. The server returns 200. The JSON the page would have shown to a logged-in user is in the response body.

The renderer falls back to the default locale on its own. The matcher does not. That gap is the data route.

The reproduction is one curl

The full proof of concept fits on a phone screen. Take a project that has middleware doing session-based authorization on /dashboard, with i18n configured, and confirm the page redirect:

$ curl -sI http://localhost:3000/dashboard
HTTP/1.1 307 Temporary Redirect
Location: /en/dashboard

$ curl -sI http://localhost:3000/en/dashboard
HTTP/1.1 302 Found
Location: /login

Same handler, full redirect chain to the login page, exactly what the developer wrote the middleware to do.

Now ask the server for the same page's data:

$ curl -s http://localhost:3000/_next/data/<buildId>/dashboard.json
{"pageProps":{"message":"private dashboard","user":{...}},"__N_SSP":true}

200 OK. JSON in the body. The buildId is the value the dev server prints at startup and is available client-side in __NEXT_DATA__.buildId on any other page on the same origin. The whole exploit is finding a buildId and changing the URL.

The data URL has the same expressivity as the page URL. It can carry path parameters. It can carry query parameters. If getServerSideProps returns user-tied data based on the session, that data is returned. If getServerSideProps returns admin-tied data based on a role check that happens inside the handler rather than inside the middleware, that is fine. If the role check is in the middleware, where most Next.js authorization documentation places it, then the role check did not run.

This is not a theoretical exposure. The official Next.js documentation has been recommending middleware-based authorization for the entire lifetime of the Pages Router with i18n. The Vercel blog has guides titled with phrases like "authentication in Next.js middleware." Conference talks have walked through patterns where the middleware checks a JWT and rewrites unauthenticated users to the login page. Those patterns work for /dashboard. They have not worked for /_next/data/<buildId>/dashboard.json since i18n routing landed.

The patch is the missing else-branch

The fix is in the same function. v15.5.16 modifies the second locale-resolution site to mirror the first:

if (config.i18n) {
  const curLocaleResult = normalizeLocalePath(
    normalized,
    config.i18n.locales
  )

  if (curLocaleResult.detectedLocale) {
    addRequestMeta(req, 'locale', curLocaleResult.detectedLocale)
  } else if (
    defaultLocale &&
    !curLocaleResult.pathname.startsWith('/_next/')
  ) {
    // Match normalized _next/data requests against the same
    // locale-prefixed internal pathname shape used by direct page
    // requests when the default locale was inferred.
    normalized = addPathPrefix(
      curLocaleResult.pathname === '/'
        ? `/${defaultLocale}`
        : addPathPrefix(curLocaleResult.pathname || '', `/${defaultLocale}`)
    )
  }
}

Read the comment. It is the maintainer's admission of what the bug was. The data request was supposed to be normalized to "the same locale-prefixed internal pathname shape used by direct page requests when the default locale was inferred." It was not. The patch makes it so.

The regression test added in the same commit asserts exactly the case the pre-patch code missed. It declares middleware whose matcher is a non-root path, with i18n. It asserts that a request to /middleware/works produces the middleware header. Then, the next line:

const res3 = await fetchViaHTTP(
  next.url,
  `/_next/data/${next.buildId}/middleware/works.json`
)
expect(await res3.json()).toMatchObject({
  pageProps: { message: '(en) Hello from /middleware/works' },
})
expect(res3.headers.get('X-From-Middleware')).toBe('true')

The test passes after the patch. The test fails before the patch. The header is missing because the middleware did not run, because the matcher did not match, because the locale was missing, because the second site did not apply the default-locale prefix the way the first site did.

There is nothing more to say about the mechanism. The maintainer's own comment said it. The patch is small, surgical, and obvious in hindsight, which is the signature of a defect that was always going to be found, by someone, the first time someone bothered to compare the two sites.

The pattern: parallel implementation, same function, drift

The defender-frame name for what happened here is parallel-implementation-gap, and the unusual feature of this exhibit is that the two parallel implementations live inside one function. Most parallel-implementation-gap exhibits in the catalog are about two files that should do the same thing and do not: a validator and a renderer that disagree about what a URL means, a write path and a read path that disagree about what a record is, a CLI and a config loader that disagree about what a flag does. In this exhibit, the validator and the renderer are forty lines apart in the same file. The author had clearly seen the missing-locale case once. The patch is the same eleven-line block, repeated. The defect was the absence of those eleven lines on the second pass.

There is a sibling exhibit in the same Next.js release, CVE-2026-44575. That one is also about middleware matchers and Pages Router data routes, but the missing case is the App Router's .rsc and .segments suffixes rather than the i18n locale prefix. The same getMiddlewareMatchers function compiles both classes of route, and the App Router suffixes were added to the matcher when the App Router shipped, but the i18n locale handling for data routes never quite caught up with the framework's other locale-handling invariants. Two CVEs, one release, both about the matcher disagreeing with the renderer about which encodings of a URL refer to the same resource.

There is a second pattern here, internal-only-by-convention, which has its own catalog of twenty-three exhibits and is the reason the framework's authors did not see this in code review. The _next/data/<buildId>/ prefix looks internal. It begins with an underscore. It is named for the implementation rather than for any user-meaningful resource. The Next.js codebase calls it "internal" in several places, and the framework's documentation discourages developers from constructing those URLs by hand. The buildId is supposed to be opaque, transient, and accessible only through the framework's own client-side router. But none of those properties are enforced. The buildId is in every page's HTML in the __NEXT_DATA__ script tag. The URL pattern is documented in the framework's own e2e tests. Any HTTP client on any laptop can construct the URL. "Internal" was a property of how the framework's author saw the URL. It was not a property of the request stream that arrived at the server.

The whole vulnerability is the gap between those two views. From the inside, /_next/data/<buildId>/dashboard.json is a different kind of thing from /dashboard, normalized through different code paths, named with different prefixes, treated as different cases by resolveRoutes. From the outside, the two URLs are the same resource, and any control plane that treats one but not the other has a hole exactly the size of the difference.

What this CVE costs

A Next.js app that uses middleware for authentication or authorization, runs on the Pages Router, has i18n configured with a non-false default locale, and has a middleware matcher scoped to anything other than the root path, was exposing the JSON form of every protected page to any unauthenticated client. The page form was protected. The JSON form was not.

The JSON form contains, in many real apps, the same data the page would have rendered. Dashboards expose user records and metrics. Account pages expose profile data, email addresses, billing information. Admin pages expose user lists, role assignments, audit logs. The data the developer thought was behind a session check is in the body of the response, behind a URL that any visitor could compute.

Three things made the bug last. The middleware logs do not show what they do not run, so the missing requests left no trace in the framework's own observability. The page form still redirected, which made the protection look intact to anyone testing the app through a browser. And the URL shape of the data route is one the framework's own client constructs and consumes, so the only people sending those requests in normal traffic were doing so under conditions where the missing matcher did not matter, because they were on already-authenticated sessions that would have passed the check anyway.

The bug was discovered the way these bugs are always discovered. Someone wrote a test that asserted middleware ran for a data request. The test failed. The maintainer added the eleven-line else-branch. The advisory got a number.

The patch is the eleven-line fallback at line 230 of the same file, re-typed at line 425.