apache: Don't set HSTS for .onion domain

Fixes: #2174.

When HSTS is set, there is no way to override the certificate warnings. LE does
not yet issue certificates for .onion domains. Certificate warnings are
certainly show there. Although browsers don't accept HSTS headers when the
certificate is invalid, it is best be safe and not set them for .onion domains.

Tests:

- Without the patch, on normal and .onion domains, HSTS is set only when using
HTTPS.

- With the patch, HSTS is set only when using HTTPS but only for normal domains
but not .onion domains.

- The patch works when tested with .onion and .ONION hosts.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2022-01-30 17:00:54 -05:00
1 parent 5e4a0f0a38
commit 4fc1844d89
1 file changed
+3 -1
@@ -34,7 +34,9 @@
##
## Enable HSTS, even for subdomains.
##
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains" env=HTTPS
<If "%{HTTP_HOST} !~ /^.*\.onion$/i">
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains" env=HTTPS
</If>
##
## Redirect traffic on home to /plinth as part of turning the machine