Skip to content

Commit e5017a9

Browse files
committed
net/http: don't strip whitespace from Transfer-Encoding headers
Do not accept "Transfer-Encoding: \rchunked" as a valid TE header setting chunked encoding. Thanks to Zeyu Zhang (https://www.zeyu2001.com/) for identifying the issue. Fixes #53188 Fixes CVE-2022-1705 Change-Id: I1a16631425159267f2eca68056b057192a7edf6c Reviewed-on: https://go-review.googlesource.com/c/go/+/409874 Reviewed-by: Roland Shoemaker <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 20760cf commit e5017a9

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/net/http/serve_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -6245,6 +6245,7 @@ func TestUnsupportedTransferEncodingsReturn501(t *testing.T) {
62456245
"fugazi",
62466246
"foo-bar",
62476247
"unknown",
6248+
"\rchunked",
62486249
}
62496250

62506251
for _, badTE := range unsupportedTEs {

src/net/http/transfer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ func (t *transferReader) parseTransferEncoding() error {
642642
if len(raw) != 1 {
643643
return &unsupportedTEError{fmt.Sprintf("too many transfer encodings: %q", raw)}
644644
}
645-
if !ascii.EqualFold(textproto.TrimString(raw[0]), "chunked") {
645+
if !ascii.EqualFold(raw[0], "chunked") {
646646
return &unsupportedTEError{fmt.Sprintf("unsupported transfer encoding: %q", raw[0])}
647647
}
648648

0 commit comments

Comments
 (0)