Skip to content

Commit

Permalink
do not return if client IP is not allowed in login API response
Browse files Browse the repository at this point in the history
Signed-off-by: Nicola Murino <[email protected]>
  • Loading branch information
drakkan committed Dec 28, 2024
1 parent 91340bb commit deea9ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/httpd/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions internal/httpd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit deea9ff

Please sign in to comment.