Unverified Commit 6d09f0b8 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add experimental.allowedRevalidateHeaderKeys config (#44985)

parent 034ee8ac
......@@ -181,6 +181,7 @@ export async function parseBody(
type ApiContext = __ApiPreviewProps & {
trustHostHeader?: boolean
allowedRevalidateHeaderKeys?: string[]
revalidate?: (_req: IncomingMessage, _res: ServerResponse) => Promise<any>
}
......@@ -353,15 +354,6 @@ function setPreviewData<T>(
return res
}
const filteredRevalidateHeaders = new Set([
'content-type',
'content-encoding',
'accept',
'accept-language',
'accept-encoding',
'connection',
])
async function revalidate(
urlPath: string,
opts: {
......@@ -383,9 +375,15 @@ async function revalidate(
}
: {}),
}
const allowedRevalidateHeaderKeys = [
...(context.allowedRevalidateHeaderKeys || []),
...(context.trustHostHeader
? ['cookie', 'x-vercel-protection-bypass']
: []),
]
for (const key of Object.keys(req.headers)) {
if (!filteredRevalidateHeaders.has(key) && !key.startsWith('x-vercel')) {
if (allowedRevalidateHeaderKeys.includes(key)) {
revalidateHeaders[key] = req.headers[key] as string
}
}
......
......@@ -229,6 +229,9 @@ const configSchema = {
adjustFontFallbacksWithSizeAdjust: {
type: 'boolean',
},
allowedRevalidateHeaderKeys: {
type: 'array',
},
amp: {
additionalProperties: false,
properties: {
......
......@@ -79,6 +79,7 @@ export interface NextJsWebpackConfig {
}
export interface ExperimentalConfig {
allowedRevalidateHeaderKeys?: string[]
fetchCache?: boolean
optimisticClientCache?: boolean
middlewarePrefetch?: 'strict' | 'flexible'
......
......@@ -810,7 +810,10 @@ export default class NextNodeServer extends BaseServer {
new NodeNextResponse(newRes)
),
// internal config so is not typed
trustHostHeader: (this.nextConfig.experimental as any).trustHostHeader,
trustHostHeader: (this.nextConfig.experimental as Record<string, any>)
.trustHostHeader,
allowedRevalidateHeaderKeys:
this.nextConfig.experimental.allowedRevalidateHeaderKeys,
},
this.minimalMode,
this.renderOpts.dev,
......
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