Skip to content

Commit 9f766c8

Browse files
committed
fix: add Next.js RSC headers to CloudFront CachePolicy to prevent cache poisoning
Add RSC, Next-Router-Prefetch, Next-Router-State-Tree, and Next-URL headers to CacheHeaderBehavior.allowList so that CloudFront distinguishes RSC flight responses from HTML responses in the cache key. Without these headers, static/ISR pages can serve text/x-component data for normal HTML requests (or vice versa) when CloudFront caching is active. Closes #100
1 parent 764a4fa commit 9f766c8

File tree

1 file changed

+7
-0
lines changed
  • cdk/lib/constructs/cf-lambda-furl-service

1 file changed

+7
-0
lines changed

cdk/lib/constructs/cf-lambda-furl-service/service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ export class CloudFrontLambdaFunctionUrlService extends Construct {
8989
'X-HTTP-Method-Override',
9090
'X-HTTP-Method',
9191
'X-Method-Override',
92+
// Next.js App Router RSC headers to prevent cache poisoning.
93+
// Without these, RSC flight responses (text/x-component) and HTML responses
94+
// share the same cache key, causing wrong content to be served.
95+
'RSC',
96+
'Next-Router-Prefetch',
97+
'Next-Router-State-Tree',
98+
'Next-URL',
9299
),
93100
defaultTtl: Duration.seconds(0),
94101
cookieBehavior: CacheCookieBehavior.all(),

0 commit comments

Comments
 (0)