Summary
A missing authorization check in certain Next.js Pages Router configurations allows locale-less /_next/data/<buildId>/<page>.json requests to bypass middleware or proxy-based access controls.
When internationalization (i18n) is enabled and authorization relies on middleware or reverse proxies, attackers may retrieve server-side rendered JSON data for protected pages without passing the intended checks.
Affected context
This vulnerability arises in Next.js applications that:
- Use the Pages Router (not purely the App Router),
- Have i18n (internationalization) configured, and
- Rely on middleware-based or proxy-based authorization for route protection.
In these setups, page data is exposed through /_next/data/<buildId>/<page>.json endpoints. While localized routes are typically subject to middleware, the unprefixed (locale-less) data route may not trigger the same authorization logic, leaving protected content accessible without authentication or authorization in certain configurations.
Exploit preconditions
- Attack surface: Public HTTP endpoints of the Next.js application.
- Required access: Network access to the target application; no prior authentication necessarily required if public endpoints are reachable.
- Trigger point: Direct requests to locale-less data URLs such as:
/_next/data/<buildId>/<page>.json
that correspond to pages normally protected by middleware or proxy-based checks.
- Why exploitation is possible: The i18n configuration and routing behavior cause middleware or upstream authorization layers to run on localized paths (for example,
/en/protected) but not on the underlying locale-less data route. As a result, the server renders and returns SSR JSON for protected pages without enforcing the intended access controls.
Why this happens
The core issue is a missing authorization check on an alternative data-fetching endpoint that serves the same sensitive content as the protected page route.
In Next.js Pages Router setups with i18n, localized paths and their internal data routes are treated differently by the routing layer and middleware. The middleware/proxy access control is applied to the user-facing, locale-prefixed URL but not consistently to the unprefixed /_next/data/... endpoint. This mismatch creates an authorization gap where the same protected resource is available through another path that lacks enforcement, aligning with CWE-863: Incorrect Authorization.
Potential impact
- Unauthorized retrieval of SSR JSON for pages intended to be protected behind authentication or role-based access control.
- Exposure of sensitive business data embedded in page props (e.g., user profile details, internal identifiers, or configuration).
- Leakage of information useful for further attacks, such as internal API shapes, feature flags, or access tokens mistakenly embedded in page data.
- Potential inference of application logic, authorization decisions, and internal resource relationships.
General mitigation guidance
Risk reduction focuses on removing authorization gaps across all routes that expose protected content:
- Ensure that all routes serving sensitive data, including
/_next/data/...endpoints, are covered by the same authorization checks as their corresponding page URLs. - Favor centralized, declarative authorization per route or resource, instead of relying solely on derived paths or assumptions about routing structure.
- Avoid placing sensitive information directly into SSR JSON unless strictly necessary; minimize data to what is required for rendering.
- When using middleware, design patterns so that data routes and page routes share the same protection logic, for example by matching on underlying pathname patterns rather than specific locales.
- Implement defense in depth by validating session/authorization within the server-side data fetching logic (e.g., server-side handlers) before returning sensitive props.
How teams detect issues like this
Effective detection typically involves a mix of code review, testing, and automated analysis:
- Code review patterns:
- Identify pages that are considered protected but whose data is exposed through
getServerSidePropsor similar mechanisms without in-function authorization checks. - Look for reliance on middleware or proxies as the sole enforcement layer for routes that have corresponding
/_next/data/...endpoints. - Static and configuration analysis:
- Use automated tooling or custom scripts to enumerate all page routes and infer their data endpoints, then cross-check which ones are expected to be protected.
- Flag configurations where i18n and middleware are used together without explicit handling of
/_next/datapaths. - Dynamic testing:
- During security testing, attempt direct access to
/_next/data/<buildId>/<page>.jsonfor protected pages and verify whether data is returned without proper authorization. - Integrate these checks into CI/CD pipeline tests as part of a regression suite for access control.
- Runtime monitoring:
- Add logging or observability around
/_next/data/...requests to detect unusual access patterns to data routes associated with sensitive pages.

