Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
bd08d8ce
Unverified
Commit
bd08d8ce
authored
Jun 18, 2019
by
Kyle Brandt
Committed by
GitHub
Jun 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
middleware: fix Strict-Transport-Security header (#17644)
fixes #17641
parent
40161584
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
4 deletions
+37
-4
pkg/middleware/middleware.go
+4
-4
pkg/middleware/middleware_test.go
+33
-0
No files found.
pkg/middleware/middleware.go
View file @
bd08d8ce
...
@@ -255,14 +255,14 @@ func AddDefaultResponseHeaders() macaron.Handler {
...
@@ -255,14 +255,14 @@ func AddDefaultResponseHeaders() macaron.Handler {
// AddSecurityHeaders adds various HTTP(S) response headers that enable various security protections behaviors in the client's browser.
// AddSecurityHeaders adds various HTTP(S) response headers that enable various security protections behaviors in the client's browser.
func
AddSecurityHeaders
(
w
macaron
.
ResponseWriter
)
{
func
AddSecurityHeaders
(
w
macaron
.
ResponseWriter
)
{
if
setting
.
Protocol
==
setting
.
HTTPS
&&
setting
.
StrictTransportSecurity
{
if
setting
.
Protocol
==
setting
.
HTTPS
&&
setting
.
StrictTransportSecurity
{
strictHeader
:=
"Strict-Transport-Security"
strictHeaderValues
:=
[]
string
{
fmt
.
Sprintf
(
"max-age=%v"
,
setting
.
StrictTransportSecurityMaxAge
)}
w
.
Header
()
.
Add
(
strictHeader
,
fmt
.
Sprintf
(
"max-age=%v"
,
setting
.
StrictTransportSecurityMaxAge
))
if
setting
.
StrictTransportSecurityPreload
{
if
setting
.
StrictTransportSecurityPreload
{
w
.
Header
()
.
Add
(
strictHeader
,
"preload"
)
strictHeaderValues
=
append
(
strictHeaderValues
,
"preload"
)
}
}
if
setting
.
StrictTransportSecuritySubDomains
{
if
setting
.
StrictTransportSecuritySubDomains
{
w
.
Header
()
.
Add
(
strictHeader
,
"includeSubDomains"
)
strictHeaderValues
=
append
(
strictHeaderValues
,
"includeSubDomains"
)
}
}
w
.
Header
()
.
Add
(
"Strict-Transport-Security"
,
strings
.
Join
(
strictHeaderValues
,
"; "
))
}
}
if
setting
.
ContentTypeProtectionHeader
{
if
setting
.
ContentTypeProtectionHeader
{
...
...
pkg/middleware/middleware_test.go
View file @
bd08d8ce
...
@@ -21,6 +21,39 @@ import (
...
@@ -21,6 +21,39 @@ import (
"gopkg.in/macaron.v1"
"gopkg.in/macaron.v1"
)
)
func
TestMiddleWareSecurityHeaders
(
t
*
testing
.
T
)
{
setting
.
ERR_TEMPLATE_NAME
=
"error-template"
Convey
(
"Given the grafana middleware"
,
t
,
func
()
{
middlewareScenario
(
t
,
"middleware should get correct x-xss-protection header"
,
func
(
sc
*
scenarioContext
)
{
setting
.
XSSProtectionHeader
=
true
sc
.
fakeReq
(
"GET"
,
"/api/"
)
.
exec
()
So
(
sc
.
resp
.
Header
()
.
Get
(
"X-XSS-Protection"
),
ShouldEqual
,
"1; mode=block"
)
})
middlewareScenario
(
t
,
"middleware should not get x-xss-protection when disabled"
,
func
(
sc
*
scenarioContext
)
{
setting
.
XSSProtectionHeader
=
false
sc
.
fakeReq
(
"GET"
,
"/api/"
)
.
exec
()
So
(
sc
.
resp
.
Header
()
.
Get
(
"X-XSS-Protection"
),
ShouldBeEmpty
)
})
middlewareScenario
(
t
,
"middleware should add correct Strict-Transport-Security header"
,
func
(
sc
*
scenarioContext
)
{
setting
.
StrictTransportSecurity
=
true
setting
.
Protocol
=
setting
.
HTTPS
setting
.
StrictTransportSecurityMaxAge
=
64000
sc
.
fakeReq
(
"GET"
,
"/api/"
)
.
exec
()
So
(
sc
.
resp
.
Header
()
.
Get
(
"Strict-Transport-Security"
),
ShouldEqual
,
"max-age=64000"
)
setting
.
StrictTransportSecurityPreload
=
true
sc
.
fakeReq
(
"GET"
,
"/api/"
)
.
exec
()
So
(
sc
.
resp
.
Header
()
.
Get
(
"Strict-Transport-Security"
),
ShouldEqual
,
"max-age=64000; preload"
)
setting
.
StrictTransportSecuritySubDomains
=
true
sc
.
fakeReq
(
"GET"
,
"/api/"
)
.
exec
()
So
(
sc
.
resp
.
Header
()
.
Get
(
"Strict-Transport-Security"
),
ShouldEqual
,
"max-age=64000; preload; includeSubDomains"
)
})
})
}
func
TestMiddlewareContext
(
t
*
testing
.
T
)
{
func
TestMiddlewareContext
(
t
*
testing
.
T
)
{
setting
.
ERR_TEMPLATE_NAME
=
"error-template"
setting
.
ERR_TEMPLATE_NAME
=
"error-template"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment