From bb715e1f3ea37de0473804a444bdbacd3622d02a Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Sun, 31 Aug 2025 08:50:48 +0000 Subject: [PATCH] fix: add missing base64 import for password change handler --- internal/api/router.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/internal/api/router.go b/internal/api/router.go index 289668ffa..ad7030663 100644 --- a/internal/api/router.go +++ b/internal/api/router.go @@ -2,6 +2,7 @@ package api import ( "bufio" + "encoding/base64" "encoding/json" "fmt" "net/http" @@ -1040,14 +1041,31 @@ func (r *Router) handleChangePassword(w http.ResponseWriter, req *http.Request) return } - // Verify the current password is correct - username, password, ok := parseBasicAuth(authHeader) - if !ok { + // Parse Basic auth header + const basicPrefix = "Basic " + if !strings.HasPrefix(authHeader, basicPrefix) { writeErrorResponse(w, http.StatusUnauthorized, "unauthorized", "Invalid authorization format", nil) return } + decoded, err := base64.StdEncoding.DecodeString(authHeader[len(basicPrefix):]) + if err != nil { + writeErrorResponse(w, http.StatusUnauthorized, "unauthorized", + "Invalid authorization encoding", nil) + return + } + + parts := strings.SplitN(string(decoded), ":", 2) + if len(parts) != 2 { + writeErrorResponse(w, http.StatusUnauthorized, "unauthorized", + "Invalid authorization format", nil) + return + } + + username := parts[0] + password := parts[1] + // Check if username matches configured user if username != r.config.AuthUser { writeErrorResponse(w, http.StatusUnauthorized, "unauthorized",