You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're building an application using React Router v7 deployed on AWS Lambda behind a CDN/proxy layer. We upgraded to v7.12 and are looking to implement a proper solution for the CSRF validation introduced.
In our architecture:
Client → sends request to public domain (e.g., www.example.com)
CDN/Proxy → forwards to AWS Lambda via API Gateway
API Gateway → modifies the Host header to the internal Lambda endpoint
Lambda → runs Express.js with React Router SSR
The Problem
React Router's CSRF protection compares the Origin header (set by the browser to the public domain) against the Host header (modified by API Gateway to the internal endpoint). This causes legitimate form submissions to fail:
X-Forwarded-Host can be spoofed if not properly validated
Requires trusting proxy headers without cryptographic verification
Doesn't feel like an "official" solution for this common architecture
Questions for the Team
Is there a recommended pattern for React Router CSRF validation behind proxies/CDNs in serverless environments?
Could React Router support a CSRF token approach instead of (or in addition to) origin/host comparison? Something like:
Server generates a cryptographically secure token
Token is embedded in forms (similar to traditional CSRF protection)
React Router validates the token on submission
This would be immune to header manipulation
Could there be a runtime-evaluated validation function? Instead of a static list, something like:
validateActionOrigin: (request,origin)=>{// Custom validation logic that can access runtime environmentreturnisValidOrigin(origin,request.headers);}
Are there plans to make the CSRF validation more flexible for infrastructures where the Host header is legitimately different from the Origin due to proxying?
What we're looking for is a solution that:
Works with proxy/CDN infrastructure out of the box
Doesn't require header manipulation workarounds
Provides cryptographic verification rather than just header comparison
Can be configured at runtime based on deployment environment
Maintains strong security guarantees
This architecture pattern (CDN → API Gateway → Lambda) is very common in modern serverless deployments and a first-class solution would benefit the entire ecosystem.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hey Maintainers,
Context
We're building an application using React Router v7 deployed on AWS Lambda behind a CDN/proxy layer. We upgraded to v7.12 and are looking to implement a proper solution for the CSRF validation introduced.
In our architecture:
www.example.com)Hostheader to the internal Lambda endpointThe Problem
React Router's CSRF protection compares the
Originheader (set by the browser to the public domain) against theHostheader (modified by API Gateway to the internal endpoint). This causes legitimate form submissions to fail:Origin: https://www.example.comHost: abcd1234.execute-api.us-east-1.amazonaws.comCurrent Solutions & Their Issues:
Option 1: Using
allowActionOriginConcerns:
Option 2: Normalizing Host Header via Middleware
Concerns:
Questions for the Team
Is there a recommended pattern for React Router CSRF validation behind proxies/CDNs in serverless environments?
Could React Router support a CSRF token approach instead of (or in addition to) origin/host comparison? Something like:
Could there be a runtime-evaluated validation function? Instead of a static list, something like:
Are there plans to make the CSRF validation more flexible for infrastructures where the Host header is legitimately different from the Origin due to proxying?
What we're looking for is a solution that:
This architecture pattern (CDN → API Gateway → Lambda) is very common in modern serverless deployments and a first-class solution would benefit the entire ecosystem.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions