Skip to content

fix(dev): respect forwarded proxy headers - #15462

Closed
wangxpych wants to merge 2 commits into
remix-run:mainfrom
wangxpych:wangxpych/fix-dev-proxy-protocol
Closed

fix(dev): respect forwarded proxy headers#15462
wangxpych wants to merge 2 commits into
remix-run:mainfrom
wangxpych:wangxpych/fix-dev-proxy-protocol

Conversation

@wangxpych

@wangxpych wangxpych commented Sep 2, 2026

Copy link
Copy Markdown

Use the forwarded protocol in the Vite development server's Node request adapter so action requests behind an HTTPS reverse proxy retain their public scheme.

Keep the original Host header, which Vite validates against server.allowedHosts, instead of trusting a client-controlled forwarded host. Adds an HTTP-level regression test covering a valid forwarded protocol alongside a spoofed X-Forwarded-Host.

Closes #15454

@kdelay kdelay left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The dev server is not always behind a proxy, and trustProxy in 0.14.1 has no trust boundary: calling createRequest(req, res, { trustProxy: true }) directly, x-forwarded-host: evil.example.com, real.example.com yields http://evil.example.com/.

Vite's own host check reads only Host (isHostAllowed), so server.allowedHosts stops constraining the origin that throwIfPotentialCSRFAttack compares with Origin.

Could the forwarded host be validated against the resolved server.allowedHosts, or gated behind an opt-in? viteConfig is in scope at both call sites.

@wangxpych

Copy link
Copy Markdown
Author

Good catch. I kept the Host header that Vite has already validated and only use proxy metadata for the forwarded protocol. The regression now sends X-Forwarded-Host: evil.example.com and verifies the request URL remains on the validated host.

Validated with all 10 @react-router/dev suites (188 tests / 184 snapshots), package typecheck, targeted ESLint, Prettier, and git diff --check.

@wangxpych

Copy link
Copy Markdown
Author

Closing because I’m stepping back from maintaining this contribution. Thanks for your time.

@wangxpych wangxpych closed this Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

react-router/dev incorrect action request url origin (always http)

3 participants