Skip to content

net/http: ~~SetBasicAuth got an incorrect type of value~~ #27919

Closed
@dravenk

Description

@dravenk

Please answer these questions before submitting your issue. Thanks!
I wrote a proxy server and my colleagues found that the authentication information being forwarded was wrong. I compared Mozilla's documentation Authorization and found that the SetBasicAuth method was not in the form of an instance.
Example.

Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l

But SetBasicAuth result is the following.

Authorization:[Basic c3NvX2FkbWluOjt4ODg4OA==]

The value of the Authorization in the example is a string, but what SetBasicAuth gets is a []string.

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

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build572473428=/tmp/go-build -gno-record-gcc-switches"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

func (s *Server) ProxyServer(w http.ResponseWriter, r *http.Request) {
	director := func(req *http.Request) {
		req.SetBasicAuth(s.User, s.Pass)
		req.URL.Scheme = target.Scheme
		req.URL.Host = target.Host
		req.Host = target.Host
	}
	proxy := &httputil.ReverseProxy{Director: director}
	proxy.ServeHTTP(w, r)
}

What did you expect to see?

The value of Authorization is a string type.

Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l

What did you see instead?

The value of Authorization is a []string type.

Authorization:[Basic c3NvX2FkbWluOjt4ODg4OA==]

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions