-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The shape of the bypass\n\nEvery 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//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.\n\nOn 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.\n\nTurn on i18n.\n\nThe 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 `//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.\n\nFor direct page requests, that assumption holds. For `/_next/data//dashboard.json` requests, it did not.\n\nThis 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.\n\n## Two locale-resolution sites in one function\n\nThe 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.\n\nFor an i18n app, normalization means inserting the default locale when the request did not specify one. That logic appears in two places.\n\nThe first site runs early, before route classification. Pre-patch, it looked like this:\n\n```ts\nconst initialLocaleResult = normalizeLocalePath(\n removePathPrefix(parsedUrl.pathname || '/', config.basePath),\n config.i18n?.locales\n)\n\nif (\n !initialLocaleResult.detectedLocale &&\n !initialLocaleResult.pathname.startsWith('/_next/')\n) {\n parsedUrl.pathname = addPathPrefix(\n initialLocaleResult.pathname === '/'\n ? `/${defaultLocale}`\n : addPathPrefix(initialLocaleResult.pathname || '', `/${defaultLocale}`),\n hadBasePath ? config.basePath : ''\n )\n}\n```\n\nRead 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.\n\nThe second site runs much later, after the data-route normalizer has had a chance to strip `/_next/data//...json` off the front of the URL and reveal the underlying page path. Pre-patch:\n\n```ts\nlet updated = false\nif (normalizers.data.match(normalized)) {\n updated = true\n addRequestMeta(req, 'isNextDataReq', true)\n normalized = normalizers.data.normalize(normalized, true)\n}\n\nif (config.i18n) {\n const curLocaleResult = normalizeLocalePath(\n normalized,\n config.i18n.locales\n )\n\n if (curLocaleResult.detectedLocale) {\n addRequestMeta(req, 'locale', curLocaleResult.detectedLocale)\n }\n}\n```\n\nRead what that says. If this is a data route, strip the `/_next/data//` 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.\n\nCompare 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//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`.\n\nThat is the path the middleware matcher will be evaluated against.\n\n## The matcher regex is not optional about the locale\n\nWhen 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:\n\n```ts\nconst OPTIONAL_MIDDLEWARE_NEXT_DATA_PREFIX = '/:nextData(_next/data/[^/]{1,})?'\n```\n\nThis makes the matcher tolerate both encodings of the same page. A request for `/dashboard` and a request for `/_next/data//dashboard.json` both run through the same matcher regex, because the matcher knows the framework rewrites between the two. The data prefix is optional.\n\nThe 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`:\n\n```ts\nif (i18n?.locales && matcher.locale !== false) {\n source = `/:nextInternalLocale((?!_next/)[^/.]{1,})${source}`\n}\n```\n\nThis locale prefix is not optional. There is no trailing `?`. The compiled regex for `matcher: '/dashboard'` on an i18n project ends up looking roughly like:\n\n```\n^(?:/(_next/data/[^/]{1,}))?/(?(?!_next/)[^/.]+)/dashboard(\\.json)?[/#?]?$\n```\n\nThe 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.\n\nThis 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.\n\nThe framework did not guarantee it for data requests.\n\n## What the user types and what the matcher sees\n\nConsider 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`.\n\nNow the same logged-out user requests `/_next/data//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//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.\n\nRouting 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.\n\nThe renderer falls back to the default locale on its own. The matcher does not. That gap is the data route.\n\n## The reproduction is one curl\n\nThe 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:\n\n```\n$ curl -sI http://localhost:3000/dashboard\nHTTP/1.1 307 Temporary Redirect\nLocation: /en/dashboard\n\n$ curl -sI http://localhost:3000/en/dashboard\nHTTP/1.1 302 Found\nLocation: /login\n```\n\nSame handler, full redirect chain to the login page, exactly what the developer wrote the middleware to do.\n\nNow ask the server for the same page's data:\n\n```\n$ curl -s http://localhost:3000/_next/data//dashboard.json\n{\"pageProps\":{\"message\":\"private dashboard\",\"user\":{...}},\"__N_SSP\":true}\n```\n\n200 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.\n\nThe 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.\n\nThis 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//dashboard.json` since i18n routing landed.\n\n## The patch is the missing else-branch\n\nThe fix is in the same function. v15.5.16 modifies the second locale-resolution site to mirror the first:\n\n```ts\nif (config.i18n) {\n const curLocaleResult = normalizeLocalePath(\n normalized,\n config.i18n.locales\n )\n\n if (curLocaleResult.detectedLocale) {\n addRequestMeta(req, 'locale', curLocaleResult.detectedLocale)\n } else if (\n defaultLocale &&\n !curLocaleResult.pathname.startsWith('/_next/')\n ) {\n // Match normalized _next/data requests against the same\n // locale-prefixed internal pathname shape used by direct page\n // requests when the default locale was inferred.\n normalized = addPathPrefix(\n curLocaleResult.pathname === '/'\n ? `/${defaultLocale}`\n : addPathPrefix(curLocaleResult.pathname || '', `/${defaultLocale}`)\n )\n }\n}\n```\n\nRead 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.\n\nThe 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:\n\n```ts\nconst res3 = await fetchViaHTTP(\n next.url,\n `/_next/data/${next.buildId}/middleware/works.json`\n)\nexpect(await res3.json()).toMatchObject({\n pageProps: { message: '(en) Hello from /middleware/works' },\n})\nexpect(res3.headers.get('X-From-Middleware')).toBe('true')\n```\n\nThe 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.\n\nThere 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.\n\n## The pattern: parallel implementation, same function, drift\n\nThe 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.\n\nThere is a sibling exhibit in the same Next.js release, [CVE-2026-44575](https://nefariousplan.com/posts/nextjs-cve-2026-44575-matcher-recognized-json-not-rsc). 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.\n\nThere 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//` 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.\n\nThe whole vulnerability is the gap between those two views. From the inside, `/_next/data//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.\n\n## What this CVE costs\n\nA 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.\n\nThe 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.\n\nThree 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.\n\nThe 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.","closing_line":"The patch is the eleven-line fallback at line 230 of the same file, re-typed at line 425.","hook_md":"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//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.","post_id":382,"slug":"nextjs-cve-2026-44573-resolveroutes-prefixed-pages-not-data","title":"CVE-2026-44573: Next.js's resolveRoutes Prefixed Direct Pages With the Default Locale. It Did Not Prefix Data Routes.","type":"initial","unreadable_sentence":"The renderer falls back to the default locale on its own. The matcher does not. That gap is the data route."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCalaIcAAKCRDeZjl4jgkQ JrNgAP4hwypasiDRFRRF3ePf4pmluc6EMPLw9WKWPQIvOPJR7AEAjwt4cPdgxB56 hd3H8T63ILNwjmz5SdEaQQKhtKeMIAI= =2F7p -----END PGP SIGNATURE-----