Skip to content

Commit 5f5a189

Browse files
committed
Document opt-out behavior for #13
1 parent 4f7669f commit 5f5a189

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

.idea/dictionaries/danila.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ In general, the module features sending security HTTP headers in a way that bett
3232
For instance, `Strict-Transport-Security` header should *not* be sent for plain HTTP requests.
3333
The module follows this recommendation.
3434

35+
## Important note on `Strict-Transport-Security`
36+
37+
The module adds several security headers, including `Strinct-Transport-Security`.
38+
Note that `preload` is sent in the value of this header, by default.
39+
This means Chrome may and will include your websites to its preload list of domains which are HTTPS only.
40+
41+
It is *usually* what you want anyway, but bear in mind that in some edge cases you want to access
42+
a subdomain via plan unencrypted connection.
43+
44+
If you absolutely sure that all your domains and subdomains used with the module will ever primarily operate
45+
on HTTPs, proceed without any extra step.
46+
47+
If you are *not sure* if you have or will have a need to access your websites or any of its subdomains over
48+
plain insecure HTTP protocol, ensure `security_headers_hsts_preload off;` in your config before you ever
49+
start NGINX with the module to avoid having your domain preloaded by Chrome.
50+
3551
## Key Features
3652

3753
* Plug-n-Play: the default set of security headers can be enabled with `security_headers on;` in your NGINX configuration

src/ngx_http_security_headers_module.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
typedef struct {
3232
ngx_flag_t enable;
3333
ngx_flag_t hide_server_tokens;
34+
ngx_flag_t hsts_preload;
3435

3536
ngx_uint_t xss;
3637
ngx_uint_t fo;
@@ -116,6 +117,13 @@ static ngx_command_t ngx_http_security_headers_commands[] = {
116117
offsetof(ngx_http_security_headers_loc_conf_t, hide_server_tokens ),
117118
NULL },
118119

120+
{ ngx_string( "security_headers_hsts_preload" ),
121+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
122+
ngx_conf_set_flag_slot,
123+
NGX_HTTP_LOC_CONF_OFFSET,
124+
offsetof(ngx_http_security_headers_loc_conf_t, hsts_preload ),
125+
NULL },
126+
119127
{ ngx_string("security_headers_xss"),
120128
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
121129
ngx_conf_set_enum_slot,
@@ -264,7 +272,11 @@ ngx_http_security_headers_filter(ngx_http_request_t *r)
264272
if (r->schema.len == 5 && ngx_strncmp(r->schema.data, "https", 5) == 0)
265273
{
266274
ngx_str_set(&key, "Strict-Transport-Security");
267-
ngx_str_set(&val, "max-age=63072000; includeSubDomains; preload");
275+
if (1 == slcf->hsts_preload) {
276+
ngx_str_set(&val, "max-age=63072000; includeSubDomains");
277+
} else {
278+
ngx_str_set(&val, "max-age=63072000; includeSubDomains; preload");
279+
}
268280
ngx_set_headers_out_by_search(r, &key, &val);
269281
}
270282
#endif
@@ -330,6 +342,7 @@ ngx_http_security_headers_create_loc_conf(ngx_conf_t *cf)
330342
conf->rp = NGX_CONF_UNSET_UINT;
331343
conf->enable = NGX_CONF_UNSET;
332344
conf->hide_server_tokens = NGX_CONF_UNSET_UINT;
345+
conf->hsts_preload = NGX_CONF_UNSET_UINT;
333346

334347
return conf;
335348
}
@@ -342,9 +355,9 @@ ngx_http_security_headers_merge_loc_conf(ngx_conf_t *cf, void *parent,
342355
ngx_http_security_headers_loc_conf_t *prev = parent;
343356
ngx_http_security_headers_loc_conf_t *conf = child;
344357

345-
ngx_conf_merge_value( conf->enable, prev->enable, 0 );
346-
ngx_conf_merge_value(conf->hide_server_tokens,
347-
prev->hide_server_tokens, 0 );
358+
ngx_conf_merge_value(conf->enable, prev->enable, 0);
359+
ngx_conf_merge_value(conf->hide_server_tokens, prev->hide_server_tokens, 0);
360+
ngx_conf_merge_value(conf->hsts_preload, prev->hsts_preload, 1);
348361

349362
if (ngx_http_merge_types(cf, &conf->text_types_keys, &conf->text_types,
350363
&prev->text_types_keys, &prev->text_types,

0 commit comments

Comments
 (0)