From: Go Compiler Team Date: Fri, 21 Jan 2022 18:45:18 +0000 (+0000) Subject: CVE-2021-36221 X-Git-Tag: archive/raspbian/1.7.4-2+rpi1+deb9u4^2~6 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b77748def8c24089939e4102dabefbe8e8ad9c90;p=golang-1.7.git CVE-2021-36221 Origin: https://github.com/golang/go/commit/b7a85e0003cedb1b48a1fd3ae5b746ec6330102e Reviewed-by: Sylvain Beucler Last-Update: 2022-01-21 From b7a85e0003cedb1b48a1fd3ae5b746ec6330102e Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Wed, 7 Jul 2021 16:34:34 -0700 Subject: [PATCH] net/http/httputil: close incoming ReverseProxy request body Reading from an incoming request body after the request handler aborts with a panic can cause a panic, becuse http.Server does not (contrary to its documentation) close the request body in this case. Always close the incoming request body in ReverseProxy.ServeHTTP to ensure that any in-flight outgoing requests using the body do not read from it. Updates #46866 Fixes CVE-2021-36221 Change-Id: I310df269200ad8732c5d9f1a2b00de68725831df Reviewed-on: https://go-review.googlesource.com/c/go/+/333191 Trust: Damien Neil Reviewed-by: Brad Fitzpatrick Reviewed-by: Filippo Valsorda Gbp-Pq: Name CVE-2021-36221.patch --- diff --git a/src/net/http/httputil/reverseproxy.go b/src/net/http/httputil/reverseproxy.go index 49c120a..04b37a7 100644 --- a/src/net/http/httputil/reverseproxy.go +++ b/src/net/http/httputil/reverseproxy.go @@ -149,6 +149,15 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { outreq := new(http.Request) *outreq = *req // includes shallow copies of maps, but okay + if outreq.Body != nil { + // Reading from the request body after returning from a handler is not + // allowed, and the RoundTrip goroutine that reads the Body can outlive + // this handler. This can lead to a crash if the handler panics (see + // Issue 46866). Although calling Close doesn't guarantee there isn't + // any Read in flight after the handle returns, in practice it's safe to + // read after closing it. + defer outreq.Body.Close() + } if closeNotifier, ok := rw.(http.CloseNotifier); ok { if requestCanceler, ok := transport.(requestCanceler); ok {