From deea9ff038b59c5f12a53588cf4b8fb7d649372d Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Sat, 28 Dec 2024 18:47:04 +0100 Subject: [PATCH] do not return if client IP is not allowed in login API response Signed-off-by: Nicola Murino --- internal/httpd/internal_test.go | 2 +- internal/httpd/server.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/httpd/internal_test.go b/internal/httpd/internal_test.go index 78d98f18f..35a3ad85c 100644 --- a/internal/httpd/internal_test.go +++ b/internal/httpd/internal_test.go @@ -2463,7 +2463,7 @@ func TestProxyHeaders(t *testing.T) { rr := httptest.NewRecorder() testServer.Config.Handler.ServeHTTP(rr, req) assert.Equal(t, http.StatusUnauthorized, rr.Code) - assert.Contains(t, rr.Body.String(), "login from IP 127.0.0.1 not allowed") + assert.NotContains(t, rr.Body.String(), "login from IP 127.0.0.1 not allowed") req.RemoteAddr = testIP rr = httptest.NewRecorder() diff --git a/internal/httpd/server.go b/internal/httpd/server.go index fc030355e..669f644f3 100644 --- a/internal/httpd/server.go +++ b/internal/httpd/server.go @@ -530,7 +530,7 @@ func (s *httpdServer) handleWebAdminTwoFactorPost(w http.ResponseWriter, r *http return } if err := verifyCSRFToken(r, s.csrfTokenAuth); err != nil { - err = handleDefenderEventLoginFailed(ipAddr, err) + handleDefenderEventLoginFailed(ipAddr, err) //nolint:errcheck s.renderTwoFactorPage(w, r, util.NewI18nError(err, util.I18nErrorInvalidCSRF)) return } @@ -941,9 +941,10 @@ func (s *httpdServer) getToken(w http.ResponseWriter, r *http.Request) { ipAddr := util.GetIPFromRemoteAddress(r.RemoteAddr) admin, err := dataprovider.CheckAdminAndPass(username, password, ipAddr) if err != nil { - err = handleDefenderEventLoginFailed(ipAddr, err) + handleDefenderEventLoginFailed(ipAddr, err) //nolint:errcheck w.Header().Set(common.HTTPAuthenticationHeader, basicRealm) - sendAPIResponse(w, r, err, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) + sendAPIResponse(w, r, dataprovider.ErrInvalidCredentials, http.StatusText(http.StatusUnauthorized), + http.StatusUnauthorized) return } if admin.Filters.TOTPConfig.Enabled {