Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
72b2cb32
Commit
72b2cb32
authored
Mar 09, 2022
by
Dominic Couture
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set nosniff header on assets requests
Changelog: security
parent
f480be75
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
0 deletions
+6
-0
workhorse/internal/staticpages/servefile.go
workhorse/internal/staticpages/servefile.go
+3
-0
workhorse/internal/staticpages/servefile_test.go
workhorse/internal/staticpages/servefile_test.go
+3
-0
No files found.
workhorse/internal/staticpages/servefile.go
View file @
72b2cb32
...
...
@@ -67,6 +67,9 @@ func (s *Static) ServeExisting(prefix urlprefix.Prefix, cache CacheMode, notFoun
notFoundHandler
.
ServeHTTP
(
w
,
r
)
return
}
w
.
Header
()
.
Set
(
"X-Content-Type-Options"
,
"nosniff"
)
defer
content
.
Close
()
switch
cache
{
...
...
workhorse/internal/staticpages/servefile_test.go
View file @
72b2cb32
...
...
@@ -78,6 +78,7 @@ func TestServingTheActualFile(t *testing.T) {
w
:=
httptest
.
NewRecorder
()
st
:=
&
Static
{
DocumentRoot
:
dir
}
st
.
ServeExisting
(
"/"
,
CacheDisabled
,
nil
)
.
ServeHTTP
(
w
,
httpRequest
)
testhelper
.
RequireResponseHeader
(
t
,
w
,
"X-Content-Type-Options"
,
"nosniff"
)
require
.
Equal
(
t
,
200
,
w
.
Code
)
if
w
.
Body
.
String
()
!=
fileContent
{
t
.
Error
(
"We should serve the file: "
,
w
.
Body
.
String
())
...
...
@@ -109,6 +110,7 @@ func TestExcludedPaths(t *testing.T) {
st
.
ServeExisting
(
"/"
,
CacheDisabled
,
nil
)
.
ServeHTTP
(
w
,
httpRequest
)
if
tc
.
found
{
testhelper
.
RequireResponseHeader
(
t
,
w
,
"X-Content-Type-Options"
,
"nosniff"
)
require
.
Equal
(
t
,
200
,
w
.
Code
)
require
.
Equal
(
t
,
tc
.
contents
,
w
.
Body
.
String
())
}
else
{
...
...
@@ -144,6 +146,7 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) {
w
:=
httptest
.
NewRecorder
()
st
:=
&
Static
{
DocumentRoot
:
dir
}
st
.
ServeExisting
(
"/"
,
CacheDisabled
,
nil
)
.
ServeHTTP
(
w
,
httpRequest
)
testhelper
.
RequireResponseHeader
(
t
,
w
,
"X-Content-Type-Options"
,
"nosniff"
)
require
.
Equal
(
t
,
200
,
w
.
Code
)
if
enableGzip
{
testhelper
.
RequireResponseHeader
(
t
,
w
,
"Content-Encoding"
,
"gzip"
)
...
...
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