Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(18966)

Issue 4921049: code review 4921049: http: add MaxBytesReader to limit request body size (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 8 months ago by bradfitz
Modified:
12 years, 8 months ago
Reviewers:
rsc
CC:
golang-dev, adg
Visibility:
Public.

Description

http: add MaxBytesReader to limit request body size This adds http.MaxBytesReader, similar to io.LimitReader, but specific to http, and for preventing a class of DoS attacks. This also makes the 10MB ParseForm limit optional (if not already set by a MaxBytesReader), documents it, and also adds "PUT" as a valid verb for parsing forms in the request body. Improves issue 2093 (DoS protection) Fixes issue 2165 (PUT form parsing)

Patch Set 1 #

Patch Set 2 : diff -r f2958b0ad781 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r f2958b0ad781 https://go.googlecode.com/hg/ #

Total comments: 26

Patch Set 4 : diff -r 131e9e06898f https://go.googlecode.com/hg/ #

Total comments: 2

Patch Set 5 : diff -r 131e9e06898f https://go.googlecode.com/hg/ #

Total comments: 3
Unified diffs Side-by-side diffs Delta from patch set Stats (+145 lines, -8 lines) Patch
M src/pkg/http/request.go View 1 2 3 2 chunks +55 lines, -6 lines 3 comments Download
M src/pkg/http/serve_test.go View 1 1 chunk +54 lines, -0 lines 0 comments Download
M src/pkg/http/server.go View 1 2 3 4 3 chunks +25 lines, -2 lines 0 comments Download
M src/pkg/http/transfer.go View 1 2 3 2 chunks +11 lines, -0 lines 0 comments Download

Messages

Total messages: 10
bradfitz
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
12 years, 8 months ago (2011-08-22 08:48:01 UTC) #1
adg
http://codereview.appspot.com/4921049/diff/4001/src/pkg/http/request.go File src/pkg/http/request.go (right): http://codereview.appspot.com/4921049/diff/4001/src/pkg/http/request.go#newcode611 src/pkg/http/request.go:611: // MaxBytesReader is similar to io.LimitReader, but is intended ...
12 years, 8 months ago (2011-08-23 01:06:21 UTC) #2
bradfitz
Hello golang-dev@googlegroups.com, adg@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 8 months ago (2011-08-23 06:28:55 UTC) #3
bradfitz
http://codereview.appspot.com/4921049/diff/4001/src/pkg/http/request.go File src/pkg/http/request.go (right): http://codereview.appspot.com/4921049/diff/4001/src/pkg/http/request.go#newcode611 src/pkg/http/request.go:611: // MaxBytesReader is similar to io.LimitReader, but is intended ...
12 years, 8 months ago (2011-08-23 06:29:01 UTC) #4
adg
http://codereview.appspot.com/4921049/diff/11001/src/pkg/http/serve_test.go File src/pkg/http/serve_test.go (right): http://codereview.appspot.com/4921049/diff/11001/src/pkg/http/serve_test.go#newcode922 src/pkg/http/serve_test.go:922: r.Body = MaxBytesReader(w, r.Body, limit) Should we install this ...
12 years, 8 months ago (2011-08-23 06:44:27 UTC) #5
adg
On 23 August 2011 16:44, <adg@golang.org> wrote: > To customize they could do something like: ...
12 years, 8 months ago (2011-08-23 06:45:16 UTC) #6
bradfitz
On Tue, Aug 23, 2011 at 10:44 AM, <adg@golang.org> wrote: > > http://codereview.appspot.com/**4921049/diff/11001/src/pkg/** > http/serve_test.go<http://codereview.appspot.com/4921049/diff/11001/src/pkg/http/serve_test.go> ...
12 years, 8 months ago (2011-08-23 06:52:02 UTC) #7
adg
LGTM
12 years, 8 months ago (2011-08-23 07:00:33 UTC) #8
bradfitz
*** Submitted as http://code.google.com/p/go/source/detail?r=d67e691bae3f *** http: add MaxBytesReader to limit request body size This adds ...
12 years, 8 months ago (2011-08-23 08:17:29 UTC) #9
rsc
12 years, 8 months ago (2011-08-23 20:11:24 UTC) #10
http://codereview.appspot.com/4921049/diff/14001/src/pkg/http/request.go
File src/pkg/http/request.go (right):

http://codereview.appspot.com/4921049/diff/14001/src/pkg/http/request.go#newc...
src/pkg/http/request.go:615: // underlying io.ReadCloser connection (if
applicable, usually a TCP
I don't understand the 'if applicable'.  It's a ReadCloser, so Close is always
applicable.  Suggestion:

In contrast to io.LimitReader, MaxBytesReader's result is a ReadCloser,
returns a non-EOF error for a Read beyond the limit, and Closes the
underlying reader when its Close method is called.

http://codereview.appspot.com/4921049/diff/14001/src/pkg/http/request.go#newc...
src/pkg/http/request.go:634: if res, ok := l.w.(*response); ok {
This is magic.  Can we avoid it?

http://codereview.appspot.com/4921049/diff/14001/src/pkg/http/request.go#newc...
src/pkg/http/request.go:676: maxFormSize := int64((1 << 63) - 1)
Drop the inner ().  Gofmt will format as 1<<63 - 1 to make the precedence clear.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b