From db15e5274346e4d3ba343c12a00bc7d1744f1b75 Mon Sep 17 00:00:00 2001 From: greatroar <61184462+greatroar@users.noreply.github.com> Date: Sat, 6 Nov 2021 12:38:08 +0100 Subject: [PATCH] lib/api: http.Request.BasicAuth instead of custom code (#8039) --- lib/api/api_auth.go | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/lib/api/api_auth.go b/lib/api/api_auth.go index 5a009c5db..d7d7d5a25 100644 --- a/lib/api/api_auth.go +++ b/lib/api/api_auth.go @@ -7,9 +7,7 @@ package api import ( - "bytes" "crypto/tls" - "encoding/base64" "fmt" "net" "net/http" @@ -66,28 +64,12 @@ func basicAuthAndSessionMiddleware(cookieName string, guiCfg config.GUIConfigura http.Error(w, "Not Authorized", http.StatusUnauthorized) } - hdr := r.Header.Get("Authorization") - if !strings.HasPrefix(hdr, "Basic ") { + username, password, ok := r.BasicAuth() + if !ok { error() return } - hdr = hdr[6:] - bs, err := base64.StdEncoding.DecodeString(hdr) - if err != nil { - error() - return - } - - fields := bytes.SplitN(bs, []byte(":"), 2) - if len(fields) != 2 { - error() - return - } - - username := string(fields[0]) - password := string(fields[1]) - authOk := auth(username, password, guiCfg, ldapCfg) if !authOk { usernameIso := string(iso88591ToUTF8([]byte(username)))