Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/net/http/httpproxy: misleading error for http requests when proxy URL is misconfigured #64206

Open
Izbitzer opened this issue Nov 16, 2023 · 1 comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@Izbitzer
Copy link

Izbitzer commented Nov 16, 2023

What version of Go are you using (go version)?

$ go version
go version go1.21.0 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/pem/.cache/go-build'
GOENV='/home/pem/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/pem/go/bin/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/pem/go/bin/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/pem/git/scribble/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3413766208=/tmp/go-build -gno-record-gcc-switches'

What did you do?

When performing a HTTP request using a proxy URL which is misconfigured, the error message that is returned says:

Get "https://example.com": proxyconnect tcp: dial tcp: lookup http on 127.0.0.53:53: server misbehaving

This error is a bit misleading, and doesn't reveal that the proxy URL is incorrect.

The following program is a minimal test case which reproduces the issue:

package main

import (
	"fmt"
	"net/http"
	"os"
)

func main() {
	os.Setenv("https_proxy", "http://username:pässword@myproxyserver.com:8080")
	os.Setenv("HTTPS_PROXY", "http://username:pässword@myproxyserver.com:8080")
	_, err := http.Get("https://example.com")
	if err != nil {
		fmt.Println(err.Error())
		return
	}
}

And here is a playground link.

In this case, the password contains a character that is not valid (though this URL will work fine in many other non-golang contexts, which makes it even harder to realize that there is something wrong with the URL).

The cause is that the parseProxy() function, which, in case of failing to parse the proxy URL, tries to prepend http:// to the URL and then tries parsing again. This leads to a proxy URL which is parsed with a hostname of http, which will of course not work.

In this case, the URL already has the http:// prefix, so adding it again will not make it work better (and arguably makes it worse). The logic in the parseProxy() function could be modified to take this into account.

What did you expect to see?

A clearer error message, such as Proxy URL is misconfigured: net/url: invalid userinfo would have been clearer and easier to diagnose.

What did you see instead?

The error message I get is Get "https://example.com": proxyconnect tcp: dial tcp: lookup http on 127.0.0.53:53: server misbehaving, which doesn't reveal the root cause and can lead to confusion.

@gopherbot gopherbot added this to the Unreleased milestone Nov 16, 2023
@seankhliao seankhliao changed the title x/net: Misleading error for http requests when proxy URL is misconfigured x/net/http/httpproxy: Misleading error for http requests when proxy URL is misconfigured Nov 16, 2023
@seankhliao
Copy link
Member

cc @neild

@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 16, 2023
@seankhliao seankhliao changed the title x/net/http/httpproxy: Misleading error for http requests when proxy URL is misconfigured x/net/http/httpproxy: misleading error for http requests when proxy URL is misconfigured Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants