Skip to content

Conversation

@nicknisi
Copy link
Member

@nicknisi nicknisi commented Nov 2, 2025

Summary

Fixes a potential session crossover vulnerability in CDN environments (particularly CloudFront with SST/OpenNext deployments).

Without Vary: Cookie, CDNs can't differentiate between User A and User B, potentially serving User A's cached authenticated content to User B.

Changes

  • Added cache security headers to middleware responses when authentication is detected
  • Added cache security headers to OAuth callback routes
  • Updated README with CDN deployment guidance

Headers now set on authenticated requests:

  • Cache-Control: private, no-store, must-revalidate
  • Vary: Cookie (critical - tells CDNs to differentiate users)
  • CDN-Cache-Control: no-store (CloudFront/Vercel specific)
  • x-middleware-cache: no-cache (OpenNext/SST specific)
  • Pragma: no-cache (HTTP/1.0 compatibility)

Detection logic:

  • Active session with access token
  • Session cookie present in request
  • Authorization header present

Auth callback routes are always protected via direct function call.

@nicknisi nicknisi requested a review from a team as a code owner November 2, 2025 22:43
Without Vary: Cookie, CDNs can't tell User A and User B apart and might
serve cached authenticated content to the wrong person.

We now set proper cache headers (Vary: Cookie, Cache-Control: private,
no-store, etc.) on any request with auth context. Only affects
authenticated
routes - public pages still cache normally.

Vercel handles this fine, but CloudFront/SST/OpenNext needed the
explicit headers.
@nicknisi nicknisi changed the title fix: prevent CloudFront from caching authenticated pages fix: prevent caching issues on authenticated pages Nov 2, 2025
Copy link
Contributor

@dandorman dandorman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall approach seems good. Are there any of the server-action stuff (switchOrganization) that need similar treatment?

@nicknisi
Copy link
Member Author

nicknisi commented Nov 3, 2025

The overall approach seems good. Are there any of the server-action stuff (switchOrganization) that need similar treatment?

Correct me if I'm wrong but I think those should all be fine.

@nicknisi nicknisi closed this Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants