Unverified Commit b149514e authored by Andrew Clark's avatar Andrew Clark Committed by GitHub

Add experimental flag for RSC request validation (#80157)

We're going to expand this to cover all RSC requests, not just segment
prefetches. To decouple this from clientSegmentCache, I've added a new
flag to control it. (Although for now, the behavior is still gated
behind both flags, until we've made the check more robust.)
parent 10928dfa
......@@ -2084,6 +2084,8 @@ export default abstract class Server<
// TODO: Consider not using custom request headers at all, and instead fully
// encode everything into the search param.
if (
!this.minimalMode &&
this.nextConfig.experimental.validateRSCRequestHeaders &&
this.isAppSegmentPrefetchEnabled &&
getRequestMeta(req, 'segmentPrefetchRSCRequest')
) {
......@@ -3746,11 +3748,17 @@ export default abstract class Server<
let page = pathname
const bubbleNoFallback =
getRequestMeta(ctx.req, 'bubbleNoFallback') ?? false
addRequestMeta(
ctx.req,
'cacheBustingSearchParam',
query[NEXT_RSC_UNION_QUERY]
)
if (
!this.minimalMode &&
this.nextConfig.experimental.validateRSCRequestHeaders
) {
addRequestMeta(
ctx.req,
'cacheBustingSearchParam',
query[NEXT_RSC_UNION_QUERY]
)
}
delete query[NEXT_RSC_UNION_QUERY]
const options: MatchOptions = {
......
......@@ -406,6 +406,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
proxyTimeout: z.number().gte(0).optional(),
routerBFCache: z.boolean().optional(),
removeUncaughtErrorAndRejectionListeners: z.boolean().optional(),
validateRSCRequestHeaders: z.boolean().optional(),
scrollRestoration: z.boolean().optional(),
sri: z
.object({
......
......@@ -539,6 +539,12 @@ export interface ExperimentalConfig {
*/
removeUncaughtErrorAndRejectionListeners?: boolean
/**
* During an RSC request, validates that the request headers match the
* cache-busting search parameter sent by the client.
*/
validateRSCRequestHeaders?: boolean
serverActions?: {
/**
* Allows adjusting body parser size limit for server actions.
......@@ -1368,6 +1374,7 @@ export const defaultConfig = {
viewTransition: false,
routerBFCache: false,
removeUncaughtErrorAndRejectionListeners: false,
validateRSCRequestHeaders: false,
staleTimes: {
dynamic: 0,
static: 300,
......
......@@ -4,6 +4,7 @@
const nextConfig = {
experimental: {
clientSegmentCache: true,
validateRSCRequestHeaders: true,
},
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment