Prevent clients from selecting a Variants combination
A client could request `/__variants/<hash>/page` or `/page?nxtV=<hash>` and receive the artifact of a static variant combination it did not resolve to. Only the proxy writes the prefix, and routing derives the query parameter from it after a request arrives, so either one on an incoming request came from the client. This change rejects such a request in both modes and answers it as a 404, like any request for a pathname no route serves. When self-hosting, `resolveRoutes` checks the request before headers, redirects, the proxy, and every route. That also covers a route that declares combinations while the proxy's `config.matcher` leaves it out. The check reads the decoded and slash-normalized pathname and every spelling of the parameter that `normalizeNextQueryParam` folds into `nxtV`. Minimal mode skips it, because the platform writes the parameter itself there. On a deployment, the web adapter checks the URL as it arrived, not the proxy's rewrite target, because a proxy that rewrites to `request.nextUrl` carries a normalized `nxtV` into its target. A rejected request is rewritten to `/__variants/not-routed` and the user's proxy does not run. The adapter marks a prefix it writes with `x-next-internal-variants-prefix`, and `handleBuildComplete` emits `beforeFiles` rules that rewrite an unmarked prefixed request, or one carrying the parameter, to the same pathname. The rejection is a rewrite rather than a status, because a routing rule with only a status still serves the output the pathname matches. The prefix rule admits percent-encoded spellings, because a deployment matches a rule against the pathname as sent and decodes it before it looks an artifact up. The rejection pathname lies inside the artifact namespace, so the exclusion that already keeps ordinary matchers out of `/__variants/` also keeps them off it. The exclusion now applies to data routes and to user rewrites as well, so a catch-all rewrite no longer matches a prefixed request. Its segment contains a hyphen, which the hash alphabet does not, and the route aliases in the routes manifest now match a hash as `[0-9a-z]+` like every other matcher, so no matcher can take it for a hash. A build fails when a route, a generated static param, or a `public/` entry lies under `/__variants/`, because content there would answer a rejected request. The marker header joins `INTERNAL_HEADERS` and the headers hidden from `headers()`.
Showing
Please
register
or
sign in
to comment