Skip to content

fix(deploy): add ProxyFix middleware for correct redirect URLs#582

Merged
nycomp merged 1 commit intoweeklyfrom
bugfix/oauth-redirect-scheme-fix
May 6, 2026
Merged

fix(deploy): add ProxyFix middleware for correct redirect URLs#582
nycomp merged 1 commit intoweeklyfrom
bugfix/oauth-redirect-scheme-fix

Conversation

@nycomp
Copy link
Copy Markdown
Contributor

@nycomp nycomp commented May 6, 2026

Summary

When running behind a reverse proxy (Railway, Nginx, etc.), Flask's url_for(..., _external=True) was generating HTTP URLs instead of HTTPS, causing redirect scheme mismatch issues.

This commit adds werkzeug.middleware.proxy_fix.ProxyFix to handle X-Forwarded-* headers sent by Railway:

  • X-Forwarded-Proto: sets correct URL scheme (https vs http)
  • X-Forwarded-Host: preserves original host
  • X-Forwarded-For: passes through client IP
  • X-Forwarded-Prefix: handles subpath routing

This ensures OAuth redirect URLs use the correct HTTPS scheme, fixing login flows and other redirects in production deployment.

Test plan

  • Local tests pass (ProxyFix is transparent in local dev)
  • Deploy to Railway and verify OAuth redirects use HTTPS
  • Test device authorization flow end-to-end
  • Verify other redirects (login, callbacks) use correct scheme

Investigation notes

The OAuth redirect codepath was working correctly (tests pass, 302 redirect happens), but the generated redirect URL used http instead of https. This is a common issue when Flask runs behind a reverse proxy that terminates SSL.

🤖 Generated with Claude Code

When running behind a reverse proxy (Railway, Nginx, etc.), Flask's
url_for(..., _external=True) was generating HTTP URLs instead of HTTPS,
causing redirect scheme mismatch issues.

This commit adds werkzeug.middleware.proxy_fix.ProxyFix to handle
X-Forwarded-* headers sent by Railway:
- X-Forwarded-Proto: sets correct URL scheme (https vs http)
- X-Forwarded-Host: preserves original host
- X-Forwarded-For: passes through client IP
- X-Forwarded-Prefix: handles subpath routing

This ensures OAuth redirect URLs use the correct HTTPS scheme,
fixing login flows and other redirects in production deployment.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@nycomp nycomp merged commit 634adff into weekly May 6, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants