Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
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
0
Merge Requests
0
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
Kirill Smelkov
go
Commits
f06b12f0
Commit
f06b12f0
authored
Jun 30, 2012
by
Brad Fitzpatrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net/http: ignore malicious or dumb Range requests
R=golang-dev, adg CC=golang-dev
https://golang.org/cl/6356050
parent
ccbac5a4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
0 deletions
+15
-0
src/pkg/net/http/fs.go
src/pkg/net/http/fs.go
+14
-0
src/pkg/net/http/fs_test.go
src/pkg/net/http/fs_test.go
+1
-0
No files found.
src/pkg/net/http/fs.go
View file @
f06b12f0
...
@@ -152,6 +152,13 @@ func serveContent(w ResponseWriter, r *Request, name string, modtime time.Time,
...
@@ -152,6 +152,13 @@ func serveContent(w ResponseWriter, r *Request, name string, modtime time.Time,
Error
(
w
,
err
.
Error
(),
StatusRequestedRangeNotSatisfiable
)
Error
(
w
,
err
.
Error
(),
StatusRequestedRangeNotSatisfiable
)
return
return
}
}
if
sumRangesSize
(
ranges
)
>=
size
{
// The total number of bytes in all the ranges
// is larger the the size of the file by
// itself, so this is probably an attack, or a
// dumb client. Ignore the range request.
ranges
=
nil
}
switch
{
switch
{
case
len
(
ranges
)
==
1
:
case
len
(
ranges
)
==
1
:
// RFC 2616, Section 14.16:
// RFC 2616, Section 14.16:
...
@@ -446,3 +453,10 @@ func rangesMIMESize(ranges []httpRange, contentType string, contentSize int64) (
...
@@ -446,3 +453,10 @@ func rangesMIMESize(ranges []httpRange, contentType string, contentSize int64) (
encSize
+=
int64
(
w
)
encSize
+=
int64
(
w
)
return
return
}
}
func
sumRangesSize
(
ranges
[]
httpRange
)
(
size
int64
)
{
for
_
,
ra
:=
range
ranges
{
size
+=
ra
.
length
}
return
}
src/pkg/net/http/fs_test.go
View file @
f06b12f0
...
@@ -50,6 +50,7 @@ var ServeFileRangeTests = []struct {
...
@@ -50,6 +50,7 @@ var ServeFileRangeTests = []struct {
{
r
:
"bytes=0-0,-2"
,
code
:
StatusPartialContent
,
ranges
:
[]
wantRange
{{
0
,
1
},
{
testFileLen
-
2
,
testFileLen
}}},
{
r
:
"bytes=0-0,-2"
,
code
:
StatusPartialContent
,
ranges
:
[]
wantRange
{{
0
,
1
},
{
testFileLen
-
2
,
testFileLen
}}},
{
r
:
"bytes=0-1,5-8"
,
code
:
StatusPartialContent
,
ranges
:
[]
wantRange
{{
0
,
2
},
{
5
,
9
}}},
{
r
:
"bytes=0-1,5-8"
,
code
:
StatusPartialContent
,
ranges
:
[]
wantRange
{{
0
,
2
},
{
5
,
9
}}},
{
r
:
"bytes=0-1,5-"
,
code
:
StatusPartialContent
,
ranges
:
[]
wantRange
{{
0
,
2
},
{
5
,
testFileLen
}}},
{
r
:
"bytes=0-1,5-"
,
code
:
StatusPartialContent
,
ranges
:
[]
wantRange
{{
0
,
2
},
{
5
,
testFileLen
}}},
{
r
:
"bytes=0-,1-,2-,3-,4-"
,
code
:
StatusOK
},
// ignore wasteful range request
}
}
func
TestServeFile
(
t
*
testing
.
T
)
{
func
TestServeFile
(
t
*
testing
.
T
)
{
...
...
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