Middleware: Don't require HTTPS for HSTS headers to be emitted (#35147)
Grafana itself may not be serving content over HTTPS, but it may be behind a transparent proxy which does. Fixes #26770. Based on #26868.
This commit is contained in:
@@ -47,7 +47,7 @@ func AddDefaultResponseHeaders(cfg *setting.Cfg) web.Handler {
|
||||
|
||||
// addSecurityHeaders adds HTTP(S) response headers that enable various security protections in the client's browser.
|
||||
func addSecurityHeaders(w web.ResponseWriter, cfg *setting.Cfg) {
|
||||
if (cfg.Protocol == setting.HTTPSScheme || cfg.Protocol == setting.HTTP2Scheme) && cfg.StrictTransportSecurity {
|
||||
if cfg.StrictTransportSecurity {
|
||||
strictHeaderValues := []string{fmt.Sprintf("max-age=%v", cfg.StrictTransportSecurityMaxAge)}
|
||||
if cfg.StrictTransportSecurityPreload {
|
||||
strictHeaderValues = append(strictHeaderValues, "preload")
|
||||
|
||||
@@ -68,7 +68,6 @@ func TestMiddleWareSecurityHeaders(t *testing.T) {
|
||||
sc.fakeReq("GET", "/api/").exec()
|
||||
assert.Equal(t, "max-age=64000; preload; includeSubDomains", sc.resp.Header().Get("Strict-Transport-Security"))
|
||||
}, func(cfg *setting.Cfg) {
|
||||
cfg.Protocol = setting.HTTPSScheme
|
||||
cfg.StrictTransportSecurity = true
|
||||
cfg.StrictTransportSecurityMaxAge = 64000
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user