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< ...@@ -2084,6 +2084,8 @@ export default abstract class Server<
// TODO: Consider not using custom request headers at all, and instead fully // TODO: Consider not using custom request headers at all, and instead fully
// encode everything into the search param. // encode everything into the search param.
if ( if (
!this.minimalMode &&
this.nextConfig.experimental.validateRSCRequestHeaders &&
this.isAppSegmentPrefetchEnabled && this.isAppSegmentPrefetchEnabled &&
getRequestMeta(req, 'segmentPrefetchRSCRequest') getRequestMeta(req, 'segmentPrefetchRSCRequest')
) { ) {
...@@ -3746,11 +3748,17 @@ export default abstract class Server< ...@@ -3746,11 +3748,17 @@ export default abstract class Server<
let page = pathname let page = pathname
const bubbleNoFallback = const bubbleNoFallback =
getRequestMeta(ctx.req, 'bubbleNoFallback') ?? false getRequestMeta(ctx.req, 'bubbleNoFallback') ?? false
addRequestMeta(
ctx.req, if (
'cacheBustingSearchParam', !this.minimalMode &&
query[NEXT_RSC_UNION_QUERY] this.nextConfig.experimental.validateRSCRequestHeaders
) ) {
addRequestMeta(
ctx.req,
'cacheBustingSearchParam',
query[NEXT_RSC_UNION_QUERY]
)
}
delete query[NEXT_RSC_UNION_QUERY] delete query[NEXT_RSC_UNION_QUERY]
const options: MatchOptions = { const options: MatchOptions = {
......
...@@ -406,6 +406,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() => ...@@ -406,6 +406,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
proxyTimeout: z.number().gte(0).optional(), proxyTimeout: z.number().gte(0).optional(),
routerBFCache: z.boolean().optional(), routerBFCache: z.boolean().optional(),
removeUncaughtErrorAndRejectionListeners: z.boolean().optional(), removeUncaughtErrorAndRejectionListeners: z.boolean().optional(),
validateRSCRequestHeaders: z.boolean().optional(),
scrollRestoration: z.boolean().optional(), scrollRestoration: z.boolean().optional(),
sri: z sri: z
.object({ .object({
......
...@@ -539,6 +539,12 @@ export interface ExperimentalConfig { ...@@ -539,6 +539,12 @@ export interface ExperimentalConfig {
*/ */
removeUncaughtErrorAndRejectionListeners?: boolean removeUncaughtErrorAndRejectionListeners?: boolean
/**
* During an RSC request, validates that the request headers match the
* cache-busting search parameter sent by the client.
*/
validateRSCRequestHeaders?: boolean
serverActions?: { serverActions?: {
/** /**
* Allows adjusting body parser size limit for server actions. * Allows adjusting body parser size limit for server actions.
...@@ -1368,6 +1374,7 @@ export const defaultConfig = { ...@@ -1368,6 +1374,7 @@ export const defaultConfig = {
viewTransition: false, viewTransition: false,
routerBFCache: false, routerBFCache: false,
removeUncaughtErrorAndRejectionListeners: false, removeUncaughtErrorAndRejectionListeners: false,
validateRSCRequestHeaders: false,
staleTimes: { staleTimes: {
dynamic: 0, dynamic: 0,
static: 300, static: 300,
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
const nextConfig = { const nextConfig = {
experimental: { experimental: {
clientSegmentCache: true, 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