20 Commits

Author SHA1 Message Date
Olivier Mengué
70576f07de http/httpproxy: godoc fixes
Doc improvements:
- use godoc link to net/http
- link use go.dev instead of golang.org
- fix typo in ProxyFunc doc

Change-Id: I7be0ebc78b3c34bc50fac6edc2c20a713478a315
Reviewed-on: https://go-review.googlesource.com/c/net/+/757980
Auto-Submit: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-03-24 07:44:58 -07:00
Dmitri Shuralyov
29181b8c03 all: remove go1.25 and older build constraints
Now that the x/net module requires Go 1.25.0,
the go1.25 build constraint is always satisfied.
Simplify the code accordingly.

Change-Id: I3d6fe4a132a26918455489b998730b494f5273c4
Reviewed-on: https://go-review.googlesource.com/c/net/+/744800
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2026-02-12 07:53:52 -08:00
Damien Neil
cde1dda944 proxy, http/httpproxy: do not mismatch IPv6 zone ids against hosts
When matching against a host "example.com",
don't match an IPv6 address like "[1000::1%25.example.com]:80".

Thanks to Juho Forsén of Mattermost for reporting this issue.

Fixes CVE-2025-22870
For #71984

Change-Id: I0c4fdf18765decc27e6ddf220ebe3a9bf4a6454d
Reviewed-on: https://go-review.googlesource.com/c/net/+/654697
Auto-Submit: Roland Shoemaker <roland@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Roland Shoemaker <roland@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2025-03-04 11:00:06 -08:00
Julien Cretel
0a24555f5c http/httpguts: speed up ValidHeaderFieldName
Eliminate bounds checks and eschews UTF-8 decoding in ValidHeaderFieldName,
thereby doubling its speed without introducing any allocations.
Also eliminate bounds checks in IsTokenRune.

Add tests and benchmarks for both ValidHeaderFieldName and IsTokenRune.

goos: darwin
goarch: amd64
pkg: golang.org/x/net/http/httpguts
cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
                       │   before    │                after                │
                       │   sec/op    │   sec/op     vs base                │
IsTokenRune-8            315.2n ± 0%   316.2n ± 1%        ~ (p=0.245 n=20)
ValidHeaderFieldName-8   62.77n ± 0%   29.16n ± 0%  -53.55% (p=0.000 n=20)
geomean                  140.7n        96.02n       -31.73%

                       │    before    │                after               │
                       │     B/op     │    B/op     vs base                │
IsTokenRune-8            0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=20)
ValidHeaderFieldName-8   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=20)
geomean                             ²               +0.00%

                       │    before    │                after               │
                       │  allocs/op   │ allocs/op   vs base                │
IsTokenRune-8            0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=20)
ValidHeaderFieldName-8   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=20)
geomean                             ²               +0.00%

Fixes golang/go#66700

Change-Id: Ia3ea80e5f0d173e3a69eb7429023587fd7bc5933
GitHub-Last-Rev: 1f1d25d1ec
GitHub-Pull-Request: golang/net#207
Reviewed-on: https://go-review.googlesource.com/c/net/+/578075
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-15 20:43:53 +00:00
胡玮文
8c07e20f92 httpproxy: allow any scheme
currently only http/https/socks5 scheme are allowed. However, any scheme
could be possible if user provides their own implementation.
Specifically, the widely used "socks5h://localhost" is parsed as
Scheme="http" Host="socks5h:", which does not make sense because host
name cannot contain ":".

This patch allows any scheme to appear in the proxy config. And only
fallback to http scheme if parsed scheme or host is empty.

url.Parse() result of fallback cases:

localhost      => Scheme="localhost"
localhost:1234 => Scheme="localhost" Opaque="1234"
example.com    => Path="example.com"

Updates golang/go#24135

Change-Id: Ia2c041e37e2ac61be16220fd41d6cb6fabeeca3d
Reviewed-on: https://go-review.googlesource.com/c/net/+/525257
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Damien Neil <dneil@google.com>
2024-03-08 01:59:37 +00:00
Dmitri Shuralyov
d23d9bc549 all: update go directive to 1.18
Done with:

go get go@1.18
go mod tidy
go fix ./...

Using go1.21.3.

With a manual change to keep golang.org/x/net/context testing itself,
not context in the standard library.

For golang/go#60268.

Change-Id: I00682bf7cf1e3ba4370e2a3e7f63dc245b294a36
Reviewed-on: https://go-review.googlesource.com/c/net/+/534241
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
2023-10-11 21:58:12 +00:00
Sean Liao
1e95f45603 http/httpproxy: remove comment on https proxy precedance
For golang/go#40909
For golang/go#54890

Change-Id: I1de1803f8fd00f54290404a8760d9f704ff766c3
Reviewed-on: https://go-review.googlesource.com/c/net/+/428795
Auto-Submit: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-09-07 13:56:53 +00:00
Russ Cox
290c469a71 all: gofmt
Gofmt to update doc comments to the new formatting.

For golang/go#51082.

Change-Id: Iae68a9cd600060577271575e893ecb23bed1e509
Reviewed-on: https://go-review.googlesource.com/c/net/+/399599
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-12 02:06:05 +00:00
Shiming Zhang
de3da57026 net/http/httpproxy: support non-ASCII characters in NO_PROXY
Change-Id: I4b3a97a2046fcc2619535a508c9d71ffa4ca75df
GitHub-Last-Rev: 5e2316523c
GitHub-Pull-Request: golang/net#105
Reviewed-on: https://go-review.googlesource.com/c/net/+/326269
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-25 17:00:49 +00:00
Alexander Yastrebov
c6ed85c7a1 http/httpproxy: document all loopbacks are special cased not just localhost
Fixes golang/go#33695

Change-Id: I2f7598da7c6fda161ba357a75bba72de2fee8226
GitHub-Last-Rev: 443dbb13b1
GitHub-Pull-Request: golang/net#116
Reviewed-on: https://go-review.googlesource.com/c/net/+/356510
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Damien Neil <dneil@google.com>
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
2021-10-19 23:23:29 +00:00
Katie Hockman
89ef3d95e7 http/httpguts: remove recursion in HeaderValuesContainsToken
Previously, httpguts.HeaderValuesContainsToken called a
function which could recurse to the point of a stack
overflow when given a very large header (~10MB).

Credit to Guido Vranken who reported the crash as
part of the Ethereum 2.0 bounty program.

Fixes CVE-2021-31525

Fixes golang/go#45710

Change-Id: I2c54ce3b2acf1c5efdea66db0595b93a3f5ae5f3
Reviewed-on: https://go-review.googlesource.com/c/net/+/313069
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2021-04-28 14:07:49 +00:00
Russ Cox
5f55cee0dc all: go fmt ./...
Make all our package sources use Go 1.17 gofmt format
(adding //go:build lines).

Not strictly necessary but will avoid spurious changes
as files are edited.

Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild

Change-Id: I5b2b7d93424e828a3c5f76ae3f30ab825aca388e
Reviewed-on: https://go-review.googlesource.com/c/net/+/294371
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-02-20 03:31:24 +00:00
Michael Fraenkel
7b1cca2348 http/httpproxy: match http scheme when selecting http_proxy
Protocol specific proxies must match based on scheme.

If the https proxy is no configured, and the proxy for a https URL is
requested, no proxy should be returned.

Updates golang/go#40909

Change-Id: I62dfcf95d819c634e8f2862e891877a4eb55fca7
Reviewed-on: https://go-review.googlesource.com/c/net/+/249440
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2020-10-16 16:51:38 +00:00
Michael Fraenkel
c21de06aaf http/httpproxy: support CIDR notation and ports with NO_PROXY
NO_PROXY includes support for CIDR, and notations can also
match exactly on port information if provided.
When specifying a port with IPv6, the address must be enclosed with
square brackets, [IPv6 address]:port.

Updates golang/go#16704 (fixes after vendor into std)

Change-Id: Ideb61a9ec60a6b1908f5a2c885cd6d9dd10c37cf
Reviewed-on: https://go-review.googlesource.com/115255
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-07-09 17:18:25 +00:00
Filippo Valsorda
db08ff08e8 Revert "http2: add X-Content-Type-Options automatically to prevent sniffing"
This reverts commit f73e4c9ed3.

Reason for revert: This turned out to cause more churn and provide less
security than expected.

Updates golang/go#24513

Change-Id: I2c8d0c39f8759ec8895a3261c91a98aeb2303ede
Reviewed-on: https://go-review.googlesource.com/117955
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-11 18:26:52 +00:00
Filippo Valsorda
f73e4c9ed3 http2: add X-Content-Type-Options automatically to prevent sniffing
When a Content-Type that triggers content sniffing in old (but still in
significant use) browsers is sent, add the
X-Content-Type-Options: nosniff header, unless explicitly disabled.

Expose httpguts.SniffedContentType for use in the HTTP 1 implementation.

Will be tested by net/http.TestNoSniffHeader_h2.

Updates golang/go#24513

Change-Id: Id1ffea867a496393cb52c5a9f45af97d4b2fcf12
Reviewed-on: https://go-review.googlesource.com/112015
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-05-09 00:22:18 +00:00
Brad Fitzpatrick
cbb82b59bc lex/httplex, http/httpguts: merge the httplex package into httpguts
httplex was the original package name for shared code between net/http
and x/net/http2, but its name was too specific, and http/httpguts was
added later for other shared code.

We discussed merging httplex into httpguts at the time, but it didn't
happen earlier. This finishes the move.

Updates golang/go#23908

Change-Id: Ic7d6f39e584ca579d34b5ef5ec6a0c002a38a83c
Reviewed-on: https://go-review.googlesource.com/111875
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-05-07 19:00:48 +00:00
David Url
a35a21de97 http2, http/httpguts: move ValidTrailerHeader to new common package http/httpguts
Introduce a common package x/net/http/httpguts which can be vendored by
net/http to share detail implementations of the HTTP specification with
x/net/http2.

Updates golang/go#23908

Change-Id: Id5a2d51e05135436cf406c4c4d1b13fca7f84a32
Reviewed-on: https://go-review.googlesource.com/104042
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-16 17:11:10 +00:00
Brad Fitzpatrick
fc492d2e10 http/httpproxy: fix build on Go 1.8
Go 1.8 doesn't have t.Helper.

Fix the row of red on the dashboard.

Change-Id: I85d4bb9fe38e989dc3b6a4e99705599745b83cef
Reviewed-on: https://go-review.googlesource.com/80140
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Tom Bergan <tombergan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-11-28 02:42:22 +00:00
Roger Peppe
c7086645de http/httpproxy: new package
This factors out the HTTP proxy functionality from net/http,
with a view to vendoring it into net/http later.

See discussion in https://go-review.googlesource.com/c/go/+/68091

Change-Id: I8df8a92a13bca03504edd24b71a9a184f290b87d
Reviewed-on: https://go-review.googlesource.com/76910
Reviewed-by: roger peppe <rogpeppe@gmail.com>
2017-11-23 08:18:56 +00:00