From: David Howden Date: Fri, 7 Feb 2020 21:59:45 +0000 (+1100) Subject: cmd/go/internal/auth: fix .netrc lookup for URLs with specified port X-Git-Tag: go1.15beta1~884 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=139a79dc37cd9c6d2b397ebf12da6b7df4e65bb8;p=gostls13.git cmd/go/internal/auth: fix .netrc lookup for URLs with specified port The .netrc spec [1] defines credentials based on "machine name", so remove specified ports from URL before looking for a match. [1] https://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-file.html Fixes #37130 Change-Id: Iab993afba26c927454d6166111ad1e1a53dbce43 Reviewed-on: https://go-review.googlesource.com/c/go/+/218418 Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- diff --git a/src/cmd/go/internal/auth/auth.go b/src/cmd/go/internal/auth/auth.go index 12e3c74dcc..fe5a89d727 100644 --- a/src/cmd/go/internal/auth/auth.go +++ b/src/cmd/go/internal/auth/auth.go @@ -10,10 +10,12 @@ import "net/http" // AddCredentials fills in the user's credentials for req, if any. // The return value reports whether any matching credentials were found. func AddCredentials(req *http.Request) (added bool) { + host := req.URL.Hostname() + // TODO(golang.org/issue/26232): Support arbitrary user-provided credentials. netrcOnce.Do(readNetrc) for _, l := range netrc { - if l.machine == req.URL.Host { + if l.machine == host { req.SetBasicAuth(l.login, l.password) return true }