Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for hsts #4941

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ and this project adheres to
- The ability to put [ClientIDs][clientid] into DNS-over-HTTPS hostnames as
opposed to URL paths ([#3418]). Note that AdGuard Home checks the server name
only if the URL does not contain a ClientID.
- Support for [HSTS][hsts], if `tls.force_https` is enabled ([#4941]).

[#3418]: https://github.com/AdguardTeam/AdGuardHome/issues/3418
[#4941]: https://github.com/AdguardTeam/AdGuardHome/pull/4941

[clientid]: https://github.com/AdguardTeam/AdGuardHome/wiki/Clients#clientid
[hsts]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security



Expand Down
10 changes: 10 additions & 0 deletions internal/home/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,16 @@ func handleHTTPSRedirect(w http.ResponseWriter, r *http.Request) (ok bool) {
return false
}

// Add headers for HSTS
// This informs browsers that the site should only be accessed using HTTPS,
// and that any future attempts to access it using HTTP should automatically be
// converted to HTTPS.
//
// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security
if config.TLS.ForceHTTPS {
w.Header().Add("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
ssrahul96 marked this conversation as resolved.
Show resolved Hide resolved
}

if r.TLS == nil && web.forceHTTPS {
hostPort := host
if port := web.conf.PortHTTPS; port != defaultPortHTTPS {
Expand Down