fix(api): accept proxied same-origin requests in CSRF middleware#48
Merged
fix(api): accept proxied same-origin requests in CSRF middleware#48
Conversation
Behind a reverse proxy (nginx, Cloudflare, tunnel, etc.) the browser sends Origin set to the public URL, which won't be in `corsOrigins` unless the operator keeps `APP_BASE_URL`/`CORS_ORIGINS` in sync — every mutation then fails with "Forbidden: invalid request origin". Allow Origin to also match the public origin derived from the standard `X-Forwarded-Proto` + `X-Forwarded-Host` headers set by the upstream proxy. A genuine same-origin request is by definition not CSRF, and a foreign attacker still cannot forge a same-origin Origin header. The bare `Host` header is intentionally not trusted; direct deployments are expected to configure `APP_BASE_URL`. Made-with: Cursor
|
🚅 Deployed to the archmax-pr-48 environment in archmax SemLayer
|
Docker image readydocker pull ghcr.io/archmaxai/archmax:pr-48 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Originset to the public URL, which won't be incorsOriginsunless the operator keepsAPP_BASE_URL/CORS_ORIGINSin sync — every mutation then 403s withForbidden: invalid request origin.Originthat matches the public origin derived from the standardX-Forwarded-Proto+X-Forwarded-Hostheaders set by the upstream proxy. A genuine same-origin request is by definition not CSRF, and a foreign attacker still cannot forge a same-originOriginheader.Hostheader is intentionally not trusted; direct deployments are expected to configureAPP_BASE_URL.Test plan
X-Forwarded-HostHost(noX-Forwarded-Host) matches OriginX-Forwarded-Hostmatches the foreign originForbidden: invalid request origin.Made with Cursor