From ac930cf1aa6c39233183bea8d25b84b7df2acdf4 Mon Sep 17 00:00:00 2001 From: septs Date: Sat, 21 Oct 2023 12:00:00 +0800 Subject: [PATCH] Improve naive auth logical --- inbound/naive.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/inbound/naive.go b/inbound/naive.go index 7542ae0c..0ea2bbb5 100644 --- a/inbound/naive.go +++ b/inbound/naive.go @@ -2,7 +2,6 @@ package inbound import ( "context" - "encoding/base64" "encoding/binary" "io" "math/rand" @@ -139,14 +138,9 @@ func (n *Naive) ServeHTTP(writer http.ResponseWriter, request *http.Request) { n.badRequest(ctx, request, E.New("missing naive padding")) return } - var authOk bool - var userName string - authorization := request.Header.Get("Proxy-Authorization") - if strings.HasPrefix(authorization, "BASIC ") || strings.HasPrefix(authorization, "Basic ") { - userPassword, _ := base64.URLEncoding.DecodeString(authorization[6:]) - userPswdArr := strings.SplitN(string(userPassword), ":", 2) - userName = userPswdArr[0] - authOk = n.authenticator.Verify(userPswdArr[0], userPswdArr[1]) + userName, password, authOk := sHttp.ParseBasicAuth(request.Header.Get("Proxy-Authorization")) + if authOk { + authOk = n.authenticator.Verify(userName, password) } if !authOk { rejectHTTP(writer, http.StatusProxyAuthRequired)