Skip to content

Commit

Permalink
Validate x-forwarded-proto and connection scheme before redirecting t…
Browse files Browse the repository at this point in the history
…o https (#1844)
  • Loading branch information
aledbf authored Dec 21, 2017
1 parent 18a4e63 commit fead908
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ http {
'' $scheme;
}

# validate $pass_access_scheme and $scheme are http to force a redirect
map "$scheme:$pass_access_scheme" $redirect_to_https {
default 0;
"http:http" 1;
}

map $http_x_forwarded_port $pass_server_port {
default $http_x_forwarded_port;
'' $server_port;
Expand Down Expand Up @@ -685,7 +691,7 @@ stream {

{{ if (or $location.Rewrite.ForceSSLRedirect (and (not (empty $server.SSLCertificate)) $location.Rewrite.SSLRedirect)) }}
# enforce ssl on server side
if ($pass_access_scheme = http) {
if ($redirect_to_https) {
{{ if ne $all.ListenPorts.HTTPS 443 }}
{{ $redirect_port := (printf ":%v" $all.ListenPorts.HTTPS) }}
return {{ $all.Cfg.HTTPRedirectCode }} https://$best_http_host{{ $redirect_port }}$request_uri;
Expand Down

0 comments on commit fead908

Please sign in to comment.