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