Skip to content

Commit b1a52f4

Browse files
committed
feat(router): enable HSTS when enforceHTTPS is set
When browsers see the HSTS header on an HTTPS request then they rewrite all links for the current domain that point at HTTP resources to point to HTTPS resources. When /deis/router/enforceHTTPS is set, using HSTS avoids the extranneous 301 redirect to the HTTPS resource and prevents [some threats][1]. The HTTPS Strict Transport Security header mechanism is defined in [RFC-6797][2] [1]: https://www.owasp.org/index.php/HTTP_Strict_Transport_Security [2]: https://tools.ietf.org/html/rfc6797
1 parent 68415ae commit b1a52f4

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

docs/customizing_deis/router_settings.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ setting description
6060
/deis/router/gzipDisable nginx gzipDisable setting (default: "msie6")
6161
/deis/router/gzipTypes nginx gzipTypes setting (default: "application/x-javascript application/xhtml+xml application/xml application/xml+rss application/json text/css text/javascript text/plain text/xml")
6262
/deis/router/maxWorkerConnections maximum number of simultaneous connections that can be opened by a worker process (default: 768)
63+
/deis/router/secondsToEnforceHSTS maximum time to observe HSTS when enforceHTTPS is enabled (default: 2628000)
6364
/deis/router/serverNameHashMaxSize nginx server_names_hash_max_size setting (default: 512)
6465
/deis/router/serverNameHashBucketSize nginx server_names_hash_bucket_size (default: 64)
6566
/deis/router/sslCert cluster-wide SSL certificate

router/image/templates/nginx.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ http {
7171

7272
{{ $enforceHTTPS := or (getv "/deis/router/enforceHTTPS") "false" }}
7373

74+
{{ $secondsToEnforceHSTS := or (getv "/deis/router/secondsToEnforceHSTS") "2628000" }}
75+
map $access_scheme $sts {
76+
'https' 'max-age={{ $secondsToEnforceHSTS }}; preload';
77+
}
78+
7479
## start deis-controller
7580
{{ if exists "/deis/controller/host" }}
7681
upstream deis-controller {
@@ -114,6 +119,7 @@ http {
114119
if ($access_scheme != "https") {
115120
return 301 https://$host$request_uri;
116121
}
122+
add_header Strict-Transport-Security $sts always;
117123
{{ end }}
118124
}
119125
## end deis-controller
@@ -224,6 +230,7 @@ http {
224230
if ($access_scheme != "https") {
225231
return 301 https://$host$request_uri;
226232
}
233+
add_header Strict-Transport-Security $sts always;
227234
{{ end }}
228235

229236
## workaround for nginx hashing empty string bug http://trac.nginx.org/nginx/ticket/765
@@ -282,6 +289,7 @@ http {
282289
if ($access_scheme != "https") {
283290
return 301 https://$host$request_uri;
284291
}
292+
add_header Strict-Transport-Security $sts always;
285293
{{ end }}
286294

287295
proxy_pass http://{{ $app }};

0 commit comments

Comments
 (0)