Add HTTP to HTTPS redirect in nginx gateway#24
Conversation
When global.publicUrl uses HTTPS, nginx now returns a 301 redirect for requests arriving over plain HTTP. The redirect is detected via the X-Forwarded-Proto header set by TLS-terminating load balancers and ingress controllers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the Helm chart’s nginx gateway configuration to conditionally redirect requests to HTTPS when global.publicUrl is configured with an https:// URL, using X-Forwarded-Proto to detect the original scheme behind a TLS-terminating proxy.
Changes:
- Add a conditional nginx
ifblock to return a permanent redirect to HTTPS whenX-Forwarded-Protoindicateshttp.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| {{- if include "openops.isHttps" . }} | ||
| # Redirect HTTP to HTTPS when behind a TLS-terminating load balancer | ||
| if ($http_x_forwarded_proto = "http") { | ||
| return 301 https://$host$request_uri; |
There was a problem hiding this comment.
return 301 may cause some clients/browsers to change non-GET/HEAD requests into a GET when following the redirect (dropping the request body). For an HTTP→HTTPS upgrade redirect this can break POST/PUT API calls; consider using a 308 (or 307) redirect to preserve method and body semantics.
| return 301 https://$host$request_uri; | |
| return 308 https://$host$request_uri; |
| {{- if include "openops.isHttps" . }} | ||
| # Redirect HTTP to HTTPS when behind a TLS-terminating load balancer | ||
| if ($http_x_forwarded_proto = "http") { | ||
| return 301 https://$host$request_uri; |
There was a problem hiding this comment.
The redirect target uses $host, which is derived from the client-supplied Host header and also strips any port. This can lead to (a) redirects to an attacker-controlled host if Host is spoofed, and (b) broken redirects when global.publicUrl uses a non-443 HTTPS port. Prefer redirecting to the configured canonical host/port derived from global.publicUrl (or a trusted variable like $server_name if it matches the external hostname) rather than $host.
| return 301 https://$host$request_uri; | |
| return 301 https://$server_name$request_uri; |
When
global.publicUrluses HTTPS, nginx now returns a 301 redirect for requests arriving over plain HTTP. The redirect is detected via theX-Forwarded-Protoheader set by TLS-terminating load balancers and ingress controllers.The redirect block is conditionally rendered only when
global.publicUrlstarts withhttps://, so it has no effect on HTTP-only deployments.Resolves CI-175