aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/httputil/reverseproxy.go
AgeCommit message (Collapse)Author
2025-11-20net/http/httputil: wrap ReverseProxy's outbound request body so Close is a noopNicholas S. Husin
Within ReverseProxy, we are currently sending a clone of our inbound request (from client) as our outbound request (to upstream). However, the clone of the request has a shallow copy of the request body. As a result, when the outbound request body is closed, the inbound request body (i.e. the outbound request body of the client) will also be closed. This causes an unfortunate effect where we would infinitely hang when a client sends a request with a 100-continue header via a ReverseProxy, but the ReverseProxy fails to make a connection to the upstream server. When this happens, the ReverseProxy's outbound request body would be closed, which in turns also closes the client's request body. Internally, when we close a request body, we would try to consume and discard the content. Since the client has yet to actually send the body content (due to 100-continue header) though, an infinite hang occurs. To prevent this, we make sure that closing an outbound request body from a ReverseProxy is a noop. For #75933 Change-Id: I52dc7247f689f35a6e93d1f32b2d003d90e9d2c6 Reviewed-on: https://go-review.googlesource.com/c/go/+/722160 Reviewed-by: Nicholas Husin <husin@google.com> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-02net/http/httputil: deprecate ReverseProxy.DirectorDamien Neil
The Director function has been superseded by Rewrite. Rewrite avoids fundamental security issues with hop-by-hop header handling in the Director API and has better default handling of X-Forwarded-* headers. Fixes #73161 Change-Id: Iadaf3070e0082458f79fb892ade51cb7ce832802 Reviewed-on: https://go-review.googlesource.com/c/go/+/708615 Reviewed-by: Nicholas Husin <husin@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Nicholas Husin <nsh@golang.org>
2025-03-20net/http/httputil: document ReverseProxy removal of response headersSean Liao
Fixes #30359 Change-Id: I5dfb2cd63c737959fd2f6a0dbf50ff8de18bb15d Reviewed-on: https://go-review.googlesource.com/c/go/+/658535 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
2025-03-19net/http/httputil: don't call WriteHeader after HijackDamien Neil
CL 637939 changed ReverseProxy to report errors encountered when copying data on an hijacked connection. This is generally not useful, and when using the default error handler results in WriteHeader being called on a hijacked connection. While this is harmless with standard net/http ResponseWriter implementations, it can confuse middleware layers. Fixes #72954 Change-Id: I21f3d3d515e114dc5c298d7dbc3796c505d3c82f Reviewed-on: https://go-review.googlesource.com/c/go/+/659255 Reviewed-by: Jonathan Amsterdam <jba@google.com> Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-18net/http/httputil: document ProxyRequest.SetURL limitationsSean Liao
Fixes #50337 Change-Id: I898ff6352f46f0f9b540b053049c5116e2165827 Reviewed-on: https://go-review.googlesource.com/c/go/+/658536 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-03-10net/http/httputil: close hijacked connections when CloseWrite not availableDamien Neil
CL 637939 changed ReverseProxy's handling of hijacked connections: After copying all data in one direction, it half-closes the outbound connection rather than fully closing both. Revert to the old behavior when the outbound connection does not support CloseWrite, avoiding a case where one side of the proxied connection closes but the other remains open. Fixes #72140 Change-Id: Ic0cacaa6323290f89ba48fd6cae737e86045a435 Reviewed-on: https://go-review.googlesource.com/c/go/+/655595 Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com>
2025-03-04net/http: support TCP half-close when HTTP is upgraded in ReverseProxyMark Wakefield
This CL propagates closing the write stream from either side of the reverse proxy and ensures the proxy waits for both copy-to and the copy-from the backend to complete. The new unit test checks communication through the reverse proxy when the backend or frontend closes either the read or write streams. That closing the write stream is propagated through the proxy from either the backend or the frontend. That closing the read stream is not propagated through the proxy. Fixes #35892 Change-Id: I83ce377df66a0f17b9ba2b53caf9e4991a95f6a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/637939 Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Sean Liao <sean@liao.dev> Auto-Submit: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Matej Kramny <matejkramny@gmail.com>
2025-02-04net: use strings.SplitSeq and bytes.SplitSeqapocelipes
Replace `for _, s := range {strings, bytes}.Split(v, sep)` with `for s := range {strings, bytes}.SplitSeq(v, sep)`, to simplify the code and reduce some memory allocations. Change-Id: Idead4de1e3928fc75cc5ba8caeff85542f1243d5 GitHub-Last-Rev: 5fb196a073e7583b23b1ebb446d6c067580ed63a GitHub-Pull-Request: golang/go#71554 Reviewed-on: https://go-review.googlesource.com/c/go/+/646216 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-18net/http/httputil: return after handling errorSean Liao
Fixes #70237 Change-Id: Ieb22b6e7284cb4a40d4987b0e4b9cfb6e5158161 Reviewed-on: https://go-review.googlesource.com/c/go/+/627635 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-02-27net/http/httputil: avoid ReverseProxy data race on 1xx response and errorDamien Neil
ReverseProxy uses a httptrace.ClientTrace.Got1xxResponse trace hook to capture 1xx response headers for proxying. This hook can be called asynchrnously after RoundTrip returns. (This should only happen when RoundTrip has failed for some reason.) Add synchronization so we don't attempt to modifying the ResponseWriter headers map from the hook after another goroutine has begun making use of it. Fixes #65123 Change-Id: I8b7ecb1a140f7ba7e37b9d27b8a20bca41a118b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/567216 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Auto-Submit: Damien Neil <dneil@google.com>
2024-01-10net: add available godoc linkcui fliter
Change-Id: Ib7c4baf0247c421954aedabfbb6a6af8a08a8936 Reviewed-on: https://go-review.googlesource.com/c/go/+/540021 Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-07-27all: use built-in clear to clear mapsJes Cok
Change-Id: I7f4ac72fe3230d8b7486fab0c925015cefcbe355 GitHub-Last-Rev: 54455839b674f980fb6c3afceb433db4833d340e GitHub-Pull-Request: golang/go#61544 Reviewed-on: https://go-review.googlesource.com/c/go/+/512376 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-03-17net/http/httputil: use response controller in reverse proxyShang Ding
Previously, the reverse proxy is unable to detect the support for hijack or flush if those things are residing in the response writer in a wrapped manner. The reverse proxy now makes use of the new http response controller as the means to discover the underlying flusher and hijacker associated with the response writer, allowing wrapped flusher and hijacker become discoverable. Change-Id: I53acbb12315c3897be068e8c00598ef42fc74649 Reviewed-on: https://go-review.googlesource.com/c/go/+/468755 Run-TryBot: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-02-04net/http/httputil: fix syntax in ReverseProxy example commentEthan Lowman
Change-Id: I7e71626246af94047fbd1abb9bb77f2cd9b281fb Reviewed-on: https://go-review.googlesource.com/c/go/+/465195 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
2022-12-21net/http/httputil: don't add X-Forwarded-{Host,Proto} after invoking ↵Damien Neil
Director funcs This reverts CL 407414. When forwarding an inbound request that contains an existing X-Forwarded-Host or X-Forwarded-Proto header, a proxy might want to preserve the header from the inbound request, replace it with its own header, or not include any header at all. CL 407414 replaces inbound X-Forwarded-{Host,Proto} headers by default, and allows a Director func to disable sending these headers at all. However, the Director hook API isn't sufficiently flexible to permit the previous behavior of preserving inbound values unchanged. The new Rewrite API does have this flexibility; users of Rewrite can easily pick the exact behavior they want. Revert the change to ReverseProxy when using a Director func. Users who want a convenient way to set X-Forwarded-* headers to reasonable values can migrate to Rewrite at their convenience, and users depending on the current behavior will be unaffected. For #50465. Fixes #57132. Change-Id: Ic42449c1bb525d6c9920bf721efbc519697f4f20 Reviewed-on: https://go-review.googlesource.com/c/go/+/457595 Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-11-22Revert "net/url, net/http/httputil: accept invalid percent encodings"Damien Neil
This reverts CL 450375. Reason for revert: This change causes test failures (and possibly other problems) for users depending on the existing validation behavior. Rolling back the change for now to give us more time to consider its impact. This landed late in the cycle and isn't urgent; it can wait for 1.21 if we do want to make the change. Fixes #56884 For #56732 Change-Id: I082023c67f1bbb933a617453ab92b67abba876ef Reviewed-on: https://go-review.googlesource.com/c/go/+/452795 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
2022-11-15net/url, net/http/httputil: accept invalid percent encodingsIan Lance Taylor
Per https://url.spec.whatwg.org/#percent-encoded-bytes an invalid percent encoding should be handled as ordinary text. Fixes #56732 Change-Id: Ib0259dfd704922905289eebaacbf722e28f6d636 Reviewed-on: https://go-review.googlesource.com/c/go/+/450375 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-23net/http/httputil: avoid query parameter smugglingDamien Neil
Query parameter smuggling occurs when a proxy's interpretation of query parameters differs from that of a downstream server. Change ReverseProxy to avoid forwarding ignored query parameters. Remove unparsable query parameters from the outbound request * if req.Form != nil after calling ReverseProxy.Director; and * before calling ReverseProxy.Rewrite. This change preserves the existing behavior of forwarding the raw query untouched if a Director hook does not parse the query by calling Request.ParseForm (possibly indirectly). Fixes #54663 Fixes CVE-2022-2880 Change-Id: If1621f6b0e73a49d79059dae9e6b256e0ff18ca9 Reviewed-on: https://go-review.googlesource.com/c/go/+/432976 Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
2022-09-16net/http/httputil: remove duplicated code blockDamien Neil
Remove a harmless but redundant section of code introduced in CL 407214. Change-Id: Id6522e6ff13a283d726b3b97dfc72f101884f733 Reviewed-on: https://go-review.googlesource.com/c/go/+/431395 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Tatiana Bradley <tatiana@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
2022-09-14net/http/httputil: forward 1xx responses in ReverseProxyKévin Dunglas
Support for 1xx responses has recently been merged in net/http (CL 269997). As discussed in this CL (https://go-review.googlesource.com/c/go/+/269997/comments/1ff70bef_c25a829a), support for forwarding 1xx responses in ReverseProxy has been extracted in this separate patch. According to RFC 7231, "a proxy MUST forward 1xx responses unless the proxy itself requested the generation of the 1xx response". Consequently, all received 1xx responses are automatically forwarded as long as the underlying transport supports ClientTrace.Got1xxResponse. Fixes #26088 Fixes #51914 Change-Id: I3a35ea023b798bfe56b7fb8696d5a49695229cfd GitHub-Last-Rev: dab8a461fb65b547306cae9b4c664e60020a8fa6 GitHub-Pull-Request: golang/go#53164 Reviewed-on: https://go-review.googlesource.com/c/go/+/409536 Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Rhys Hiltner <rhys@justin.tv> Run-TryBot: hopehook <hopehook@golangcn.org>
2022-08-18all: remove duplicate "the" words in commentsAbirdcfly
Following CL 424454, using command rg --multiline " the\s{1,}the " * rg --multiline " the\s{1,}//\s{1,}the " * all the words "the" that are repeated in comments are found. Change-Id: I60b769b98f04c927b4c228e10f37faf190964069 Reviewed-on: https://go-review.googlesource.com/c/go/+/423836 Auto-Submit: Filippo Valsorda <filippo@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2022-08-16net/http/httputil: add ReverseProxy.RewriteDamien Neil
Add a new Rewrite hook to ReverseProxy, superseding the Director hook. Director does not distinguish between the inbound and outbound request, which makes it possible for headers added by Director to be inadvertently removed before forwarding if they are listed in the inbound request's Connection header. Rewrite accepts a value containing the inbound and outbound requests, with hop-by-hop headers already removed from the outbound request, avoiding this problem. ReverseProxy's appends the client IP to the inbound X-Forwarded-For header by default. Users must manually delete untrusted X-Forwarded-For values. When used with a Rewrite hook, ReverseProxy now strips X-Forwarded-* headers by default. NewSingleHostReverseProxy creates a proxy that does not rewrite the Host header of inbound requests. Changing this behavior is cumbersome, as it requires wrapping the Director function created by NewSingleHostReverseProxy. The Rewrite hook's ProxyRequest parameter provides a SetURL method that provides equivalent functionality to NewSingleHostReverseProxy, rewrites the Host header by default, and can be more easily extended with additional customizations. Fixes #28168. Fixes #50580. Fixes #53002. Change-Id: Ib84e2fdd1d52c610e3887af66f517d4a74e594d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/407214 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
2022-08-12net/http/httputil: don't insert default User-Agent header in proxied requestsDamien Neil
When ReverseProxy forwards a request with no User-Agent header, leave the header in the forwarded request blank rather than inserting the default Go HTTP clent User-Agent. We already did this for NewSingleHostReverseProxy; generalize it to every ReverseProxy. Change-Id: Id81a230cb8d384acdfae190b78a4265d80720388 Reviewed-on: https://go-review.googlesource.com/c/go/+/407375 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-08-12net/http/httputil: add X-Forwarded-{Host,Proto} headers in ReverseProxyDamien Neil
X-Forwarded-Host contains the original request's host. X-Forwarded-Proto contains "http" or "https", depending on whether the original request was made on a TLS-secured connection. Setting either header to nil in Director disables adding the header, same as for X-Forwarded-For. Fixes #50465. Change-Id: If8ed1f48d83f8ea0389c53519bc7994cb53891db Reviewed-on: https://go-review.googlesource.com/c/go/+/407414 Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2022-05-17all: fix spellingJohn Bampton
Change-Id: Iee18987c495d1d4bde9da888d454eea8079d3ebc GitHub-Last-Rev: ff5e01599ddf7deb3ab6ce190ba92eb02ae2cb15 GitHub-Pull-Request: golang/go#52949 Reviewed-on: https://go-review.googlesource.com/c/go/+/406915 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-05-08all: fix some lint issuesRyan Leung
Make some code more simple. Change-Id: I801adf0dba5f6c515681345c732dbb907f945419 GitHub-Last-Rev: a505146baca00a1b3268d11d10510afa8cea6f1d GitHub-Pull-Request: golang/go#49626 Reviewed-on: https://go-review.googlesource.com/c/go/+/364634 Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2022-03-24net/http/httputil: ignore CloseNotify when a non-background context is presentDamien Neil
If the http.Request passed to ReverseProxy.ServeHTTP has a context with a non-nil Done channel, don't watch the ResponseWriter's CloseNotify channel. Avoids starting an extra background goroutine in the common case. Change-Id: I1328f3e02d3025caa0f446a2f20dfc14ef604c64 Reviewed-on: https://go-review.googlesource.com/c/go/+/376415 Trust: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Trust: Damien Neil <dneil@google.com>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-10-13net/http/httputil: allow MIME parameters when detecting SSE in ReverseProxyJames Harris
This change allows httputil.ReverseProxy to detect SSE (server-sent events) content when the response's Content-Type header includes MIME parameters, such as "text/event-stream;charset=utf-8". Prior to this change the value of the Content-Type header was compared directly to the literal "text/event-stream". This caused a false-negative which failed to set the FlushInterval correctly when MIME parameters were present. Change-Id: If8bb43efb78787b6519d7fe7599ca018a0da0023 GitHub-Last-Rev: 224518c5eb9686ee050c79f5f853ebacfdf6fc42 GitHub-Pull-Request: golang/go#48427 Reviewed-on: https://go-review.googlesource.com/c/go/+/350509 Trust: Alexander Rakoczy <alex@golang.org> Trust: Damien Neil <dneil@google.com> Run-TryBot: Alexander Rakoczy <alex@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2021-07-30net/http/httputil: close incoming ReverseProxy request bodyDamien Neil
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 <dneil@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2021-05-27net/http/httputil: always remove hop-by-hop headersFilippo Valsorda
Previously, we'd fail to remove the Connection header from a request like this: Connection: Connection: x-header Fixes #46313 Fixes CVE-2021-33197 Change-Id: Ie3009e926ceecfa86dfa6bcc6fe14ff01086be7d Reviewed-on: https://go-review.googlesource.com/c/go/+/321929 Run-TryBot: Filippo Valsorda <filippo@golang.org> Reviewed-by: Katie Hockman <katie@golang.org> Trust: Katie Hockman <katie@golang.org> Trust: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2021-05-10net/http: switch HTTP1 to ASCII equivalents of string functionsRoberto Clapis
The current implementation uses UTF-aware functions like strings.EqualFold and strings.ToLower. This could, in some cases, cause http smuggling. Change-Id: I0e76a993470a1e1b1b472f4b2859ea0a2b22ada0 Reviewed-on: https://go-review.googlesource.com/c/go/+/308009 Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Roberto Clapis <roberto@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2021-04-10all: fix spellingsNaman Gera
This follows the spelling choices that the Go project has made for English words. https://github.com/golang/go/wiki/Spelling Change-Id: Ie7c586d2cf23020cb492cfff58c0831d2d8d3a78 GitHub-Last-Rev: e16a32cd225a275f73d236bcb33703986d110ded GitHub-Pull-Request: golang/go#45442 Reviewed-on: https://go-review.googlesource.com/c/go/+/308291 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2020-10-19net/http/httputil: copy response header back to http.ResponseWriter in ↵Aofei Sheng
ReverseProxy.handleUpgradeResponse Fixes: #41634 Change-Id: Ib78cc37a4d2ca0753d567eafb616238e4103484e Reviewed-on: https://go-review.googlesource.com/c/go/+/257777 Reviewed-by: Damien Neil <dneil@google.com> Trust: Damien Neil <dneil@google.com> Trust: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-10-12net/http/httputil: flush ReverseProxy immediately if Content-Length is -1Ignacio Hagopian
Finish up a prior TODO by making ReverseProxy flush immediately if Content-Length is -1, which is a case that can occur if for example we have a streamed response, or chunked encoding, or when the body's length wasn't known. Fixes #41642 Change-Id: I30babaaf3e14837b99e3ecdc562a0a0e50c579bf GitHub-Last-Rev: efc019a9fe361082d40bee77317018c3b80451a3 GitHub-Pull-Request: golang/go#41858 Reviewed-on: https://go-review.googlesource.com/c/go/+/260637 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Ian Lance Taylor <iant@golang.org> Trust: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-05-06net/http: use ASCII space trimming throughoutFilippo Valsorda
Security hardening against HTTP request smuggling. Thank you to ZeddYu for reporting this issue. Change-Id: I98bd9f8ffe58360fc3bca9dc5d9a106773e55373 Reviewed-on: https://go-review.googlesource.com/c/go/+/231419 Reviewed-by: Katie Hockman <katie@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-05-02net/http/httputil: handle escaped paths in SingleHostReverseProxyDaniel Kumor
When forwarding a request, a SingleHostReverseProxy appends the request's path to the target URL's path. However, if certain path elements are encoded, (such as %2F for slash in either the request or target path), simply joining the URL.Path elements is not sufficient, since the field holds the decoded path. Since 87a605, the RawPath field was added which holds a decoding hint for the URL. When joining URL paths, this decoding hint needs to be taken into consideration. As an example, if the target URL.Path is /a/b, and URL.RawPath is /a%2Fb, joining the path with /c should result in /a/b/c in URL.Path, and /a%2Fb/c in RawPath. The added joinURLPath function combines the two URL's Paths, while taking into account escaping, and replaces the previously used singleJoiningSlash in NewSingleHostReverseProxy. Fixes #35908 Change-Id: I45886aee548431fe4031883ab1629a41e35f1727 GitHub-Last-Rev: 7be6b8d421c63928639f499b984a821585992c2b GitHub-Pull-Request: golang/go#36378 Reviewed-on: https://go-review.googlesource.com/c/go/+/213257 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-04-30net/http/httputil: don't append to X-Forwarded-For in ReverseProxy when nilBrad Fitzpatrick
Fixes #38079 Change-Id: Iac02d7f9574061bb26d1d9a41bb6ee6cc38934e5 Reviewed-on: https://go-review.googlesource.com/c/go/+/230937 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-04-26net/http/httputil: make Switching Protocol requests (e.g. Websockets) cancelablePierre Carru
Ensures that a canceled client request for Switching Protocols (e.g. h2c, Websockets) will cause the underlying connection to be terminated. Adds a goroutine in handleUpgradeResponse in order to select on the incoming client request's context and appropriately cancel it. Fixes #35559 Change-Id: I1238e18fd4cce457f034f78d9cdce0e7f93b8bf6 GitHub-Last-Rev: 3629c78493f667703ea99f9f4db5e63ddaaa0e6b GitHub-Pull-Request: golang/go#38021 Reviewed-on: https://go-review.googlesource.com/c/go/+/224897 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-01-21net/http/httputil: add docs about X-Forwarded-For in ReverseProxyKévin Dunglas
ReverseProxy automatically sets the X-Forwarded-For header, if the request already contains a X-Forwarded-For header, the value of the client IP is appended to the existing header value. This behavior isn't documented anywhere, and can lead to IP spoofing security issues is the client is untrusted (the most common situation). This PR documents this behavior. For future versions, I proposed #36678 that implements a more secure default behavior and adds support for other forwarded headers. Change-Id: Ief14f5063caebfccb87714f54cffa927c714e5fd GitHub-Last-Rev: fd0bd29a181861ffdb1106b42f59f9489999ccb3 GitHub-Pull-Request: golang/go#36672 Reviewed-on: https://go-review.googlesource.com/c/go/+/215617 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-07-17net/http/httputil: fix regression in ReverseProxy.ServeHTTPJoe Tsai
In Go1.12 and below, the logic in ReverseProxy.ServeHTTP would always allocate request.Header even if it were not present in the incoming request. CL 174324 added http.Request.Clone and re-factors ReverseProxy.ServeHTTP to use the new Clone method. However, the new Clone logic is not equivalent to the former logic. We preserve former semantics by explicitly allocating the Header map if nil. Fixes #33142 Change-Id: I356f94a915dd9779584ce3fe31e56e5474b9ad37 Reviewed-on: https://go-review.googlesource.com/c/go/+/186437 Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Bonventre <andybons@golang.org>
2019-05-17net/http/httputil: remove os.Stderr claim in ReverseProxy.ErrorLog docsDmitri Shuralyov
The motivation for doing so is to avoid making inaccurate claims. Logging may not go to os.Stderr if anyone overrides the log package's default output via https://godoc.org/log#SetOutput. Saying that the standard logger is used should be sufficient to explain the behavior, and users can infer that os.Stderr is used by default, unless it's changed. This change is the same as what was applied to http.Server.ErrorLog documentation in CL 53950. Change-Id: I32873fc548ceee573f8616b4d49b8a8b98881803 Reviewed-on: https://go-review.googlesource.com/c/go/+/176817 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-14net/http/httputil: remove all fields in Connection headerJonathon Lacher
In the reverseproxy, replace use (Header).Get, which returns only one value of a multiple value header, with using the Header map directly. Also fixes corresponding tests which hid the bug, and adds more tests. Fixes #30303 Change-Id: Ic9094b5983043460697748759f6dfd95fc111db7 GitHub-Last-Rev: b41038143f602d4286cb46c542d40de02e6e639d GitHub-Pull-Request: golang/go#30687 Reviewed-on: https://go-review.googlesource.com/c/go/+/166298 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-03net/http: add func NewRequestWithContext, Request.CloneBrad Fitzpatrick
Fixes #23544 Change-Id: Iaa31d76c4cda8ce22412d73c9025fc57e4fb1967 Reviewed-on: https://go-review.googlesource.com/c/go/+/174324 Reviewed-by: Andrew Bonventre <andybons@golang.org>
2019-04-24net/http: export Header.Clone, reduce its allocations, use it everywhereBrad Fitzpatrick
Fixes #29915 Change-Id: I6e6edf4f9a0e062211f74d120ae1a242bce1b274 Reviewed-on: https://go-review.googlesource.com/c/go/+/173658 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ingo Oeser <nightlyone@googlemail.com> Reviewed-by: Benny Siegert <bsiegert@gmail.com>
2019-03-29net/http/httputil: make ReverseProxy flush headers on FlushIntervalJordan Liggitt
A regression was introduced in CL 137335 (5440bfc) that caused FlushInterval to not be honored until the first Write() call was encountered. This change starts the flush timer as part of setting up the maxLatencyWriter. Fixes #31125 Fixes #31126 Change-Id: I75325bd926652922219bd1457b2b00ac6d0d41b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/170066 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-11all: move internal/x to vendor/golang.org/x and revendor using 'go mod vendor'Bryan C. Mills
This also updates the vendored-in versions of several packages: 'go mod vendor' selects a consistent version of each module, but we had previously vendored an ad-hoc selection of packages. Notably, x/crypto/hkdf was previously vendored in at a much newer commit than the rest of x/crypto. Bringing the rest of x/crypto up to that commit introduced an import of golang.org/x/sys/cpu, which broke the js/wasm build, requiring an upgrade of x/sys to pick up CL 165749. Updates #30228 Updates #30241 Updates #25822 Change-Id: I5b3dbc232b7e6a048a158cbd8d36137af1efb711 Reviewed-on: https://go-review.googlesource.com/c/go/+/164623 Reviewed-by: Filippo Valsorda <filippo@golang.org>
2019-01-09net/http/httputil: run the ReverseProxy.ModifyResponse hook for upgradesBrad Fitzpatrick
Fixes #29627 Change-Id: I08a5b45151a11b5a4f3b5a2d984c0322cf904697 Reviewed-on: https://go-review.googlesource.com/c/157098 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-01-09net/http/httputil: fix typo in ReverseProxy godocTobias Klauser
Change-Id: Iea33fe64403ca2e6f87a4e070af5e97d96506e41 Reviewed-on: https://go-review.googlesource.com/c/157118 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-02net/http/httputil: fix missing previous headers in response when switching ↵Julien Salleyron
protocol in ReverseProxy When using switching protocol, previous headers set before the reverse proxy are lost. Fixes #29407 Change-Id: Ia2b9784022d9bccef8625519ccbabbe8a276dfc0 GitHub-Last-Rev: 79bb493dcbb9b76d9d2ff9cd0854b29d634f8b73 GitHub-Pull-Request: golang/go#29408 Reviewed-on: https://go-review.googlesource.com/c/155741 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>