Forms started failing CSRF verification the moment I put a reverse proxy in front of the app
The application worked fine served directly. I put a reverse proxy in front of it for TLS termination, and now every form submission is rejected — the framework reports a CSRF verification failure, and admin login is refused with the same error.
Nothing about the forms changed. The pages render, the session cookie appears to be set, and only the submissions fail.
I can see this is about the app not recognising where the request came from, but I do not understand which part of the check is failing.
@web_yasemin · 3h ago
The check that is failing is origin comparison, and the proxy broke it by changing what the application sees.
CSRF protection on a form post compares where the browser says the request came from — the
OriginorRefererheader — against where the application believes it is running. That second value is assembled from the request: the host header and whether the connection was secure.Behind a proxy, the browser talks HTTPS to the proxy and the proxy talks plain HTTP to your app. So the application sees an unencrypted request and concludes it is running at
http://..., while the browser reports an origin ofhttps://.... The strings differ, and the request is rejected.That is why nothing you changed in the form matters, and why it appeared exactly when the proxy did.
Reply
Report