CVE-2025-24806
Description
Authelia is an open-source authentication and authorization server providing two-factor authentication and single sign-on (SSO) for applications via a web portal. If users are allowed to sign in via both username and email the regulation system treats these as separate login events. This leads to the regulation limitations being effectively doubled assuming an attacker using brute-force to find a user password. It's important to note that due to the effective operation of regulation where no user-facing sign of their regulation ban being visible either via timing or via API responses, it's effectively impossible to determine if a failure occurs due to a bad username password combination, or a effective ban blocking the attempt which heavily mitigates any form of brute-force. This occurs because the records and counting process for this system uses the method utilized for sign in rather than the effective username attribute. This has a minimal impact on account security, this impact is increased naturally in scenarios when there is no two-factor authentication required and weak passwords are used. This makes it a bit easier to brute-force a password. A patch for this issue has been applied to versions 4.38.19, and 4.39.0. Users are advised to upgrade. Users unable to upgrade should 1. Not heavily modify the default settings in a way that ends up with shorter or less frequent regulation bans. The default settings effectively mitigate any potential for this issue to be exploited. and 2. Disable the ability for users to login via an email address.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
github.com/authelia/authelia/v4Go | < 4.38.19 | 4.38.19 |
Patches
2321195866cb5d4a54189aa65fix(handlers): regulation flow (#8683)
2 files changed · +87 −36
internal/handlers/handler_firstfactor.go+28 −24 modified@@ -4,6 +4,7 @@ import ( "errors" "time" + "github.com/authelia/authelia/v4/internal/authentication" "github.com/authelia/authelia/v4/internal/middlewares" "github.com/authelia/authelia/v4/internal/regulation" ) @@ -23,48 +24,61 @@ func FirstFactorPOST(delayFunc middlewares.TimingAttackDelayFunc) middlewares.Re bodyJSON := bodyFirstFactorRequest{} - if err := ctx.ParseBody(&bodyJSON); err != nil { + var ( + details *authentication.UserDetails + err error + ) + + if err = ctx.ParseBody(&bodyJSON); err != nil { ctx.Logger.WithError(err).Errorf(logFmtErrParseRequestBody, regulation.AuthType1FA) respondUnauthorized(ctx, messageAuthenticationFailed) return } - if bannedUntil, err := ctx.Providers.Regulator.Regulate(ctx, bodyJSON.Username); err != nil { + if details, err = ctx.Providers.UserProvider.GetDetails(bodyJSON.Username); err != nil || details == nil { + ctx.Logger.WithError(err).Errorf("Error occurred getting details for user with username input '%s' which usually indicates they do not exist", bodyJSON.Username) + + respondUnauthorized(ctx, messageAuthenticationFailed) + + return + } + + if bannedUntil, err := ctx.Providers.Regulator.Regulate(ctx, details.Username); err != nil { if errors.Is(err, regulation.ErrUserIsBanned) { - _ = markAuthenticationAttempt(ctx, false, &bannedUntil, bodyJSON.Username, regulation.AuthType1FA, nil) + _ = markAuthenticationAttempt(ctx, false, &bannedUntil, details.Username, regulation.AuthType1FA, nil) respondUnauthorized(ctx, messageAuthenticationFailed) return } - ctx.Logger.WithError(err).Errorf(logFmtErrRegulationFail, regulation.AuthType1FA, bodyJSON.Username) + ctx.Logger.WithError(err).Errorf(logFmtErrRegulationFail, regulation.AuthType1FA, details.Username) respondUnauthorized(ctx, messageAuthenticationFailed) return } - userPasswordOk, err := ctx.Providers.UserProvider.CheckUserPassword(bodyJSON.Username, bodyJSON.Password) + userPasswordOk, err := ctx.Providers.UserProvider.CheckUserPassword(details.Username, bodyJSON.Password) if err != nil { - _ = markAuthenticationAttempt(ctx, false, nil, bodyJSON.Username, regulation.AuthType1FA, err) + _ = markAuthenticationAttempt(ctx, false, nil, details.Username, regulation.AuthType1FA, err) respondUnauthorized(ctx, messageAuthenticationFailed) return } if !userPasswordOk { - _ = markAuthenticationAttempt(ctx, false, nil, bodyJSON.Username, regulation.AuthType1FA, nil) + _ = markAuthenticationAttempt(ctx, false, nil, details.Username, regulation.AuthType1FA, nil) respondUnauthorized(ctx, messageAuthenticationFailed) return } - if err = markAuthenticationAttempt(ctx, true, nil, bodyJSON.Username, regulation.AuthType1FA, nil); err != nil { + if err = markAuthenticationAttempt(ctx, true, nil, details.Username, regulation.AuthType1FA, nil); err != nil { respondUnauthorized(ctx, messageAuthenticationFailed) return @@ -92,15 +106,15 @@ func FirstFactorPOST(delayFunc middlewares.TimingAttackDelayFunc) middlewares.Re // Reset all values from previous session except OIDC workflow before regenerating the cookie. if err = ctx.SaveSession(newSession); err != nil { - ctx.Logger.WithError(err).Errorf(logFmtErrSessionReset, regulation.AuthType1FA, bodyJSON.Username) + ctx.Logger.WithError(err).Errorf(logFmtErrSessionReset, regulation.AuthType1FA, details.Username) respondUnauthorized(ctx, messageAuthenticationFailed) return } if err = ctx.RegenerateSession(); err != nil { - ctx.Logger.WithError(err).Errorf(logFmtErrSessionRegenerate, regulation.AuthType1FA, bodyJSON.Username) + ctx.Logger.WithError(err).Errorf(logFmtErrSessionRegenerate, regulation.AuthType1FA, details.Username) respondUnauthorized(ctx, messageAuthenticationFailed) @@ -114,34 +128,24 @@ func FirstFactorPOST(delayFunc middlewares.TimingAttackDelayFunc) middlewares.Re if keepMeLoggedIn { err = provider.UpdateExpiration(ctx.RequestCtx, provider.Config.RememberMe) if err != nil { - ctx.Logger.WithError(err).Errorf(logFmtErrSessionSave, "updated expiration", regulation.AuthType1FA, logFmtActionAuthentication, bodyJSON.Username) + ctx.Logger.WithError(err).Errorf(logFmtErrSessionSave, "updated expiration", regulation.AuthType1FA, logFmtActionAuthentication, details.Username) respondUnauthorized(ctx, messageAuthenticationFailed) return } } - // Get the details of the given user from the user provider. - userDetails, err := ctx.Providers.UserProvider.GetDetails(bodyJSON.Username) - if err != nil { - ctx.Logger.WithError(err).Errorf(logFmtErrObtainProfileDetails, regulation.AuthType1FA, bodyJSON.Username) - - respondUnauthorized(ctx, messageAuthenticationFailed) - - return - } - - ctx.Logger.Tracef(logFmtTraceProfileDetails, bodyJSON.Username, userDetails.Groups, userDetails.Emails) + ctx.Logger.Tracef(logFmtTraceProfileDetails, details.Username, details.Groups, details.Emails) - userSession.SetOneFactor(ctx.Clock.Now(), userDetails, keepMeLoggedIn) + userSession.SetOneFactor(ctx.Clock.Now(), details, keepMeLoggedIn) if ctx.Configuration.AuthenticationBackend.RefreshInterval.Update() { userSession.RefreshTTL = ctx.Clock.Now().Add(ctx.Configuration.AuthenticationBackend.RefreshInterval.Value()) } if err = ctx.SaveSession(userSession); err != nil { - ctx.Logger.WithError(err).Errorf(logFmtErrSessionSave, "updated profile", regulation.AuthType1FA, logFmtActionAuthentication, bodyJSON.Username) + ctx.Logger.WithError(err).Errorf(logFmtErrSessionSave, "updated profile", regulation.AuthType1FA, logFmtActionAuthentication, details.Username) respondUnauthorized(ctx, messageAuthenticationFailed)
internal/handlers/handler_firstfactor_test.go+59 −12 modified@@ -52,6 +52,11 @@ func (s *FirstFactorSuite) TestShouldFailIfBodyIsInBadFormat() { } func (s *FirstFactorSuite) TestShouldFailIfUserProviderCheckPasswordFail() { + s.mock.UserProviderMock. + EXPECT(). + GetDetails(gomock.Eq("test")). + Return(&authentication.UserDetails{Username: "test"}, nil) + s.mock.UserProviderMock. EXPECT(). CheckUserPassword(gomock.Eq("test"), gomock.Eq("hello")). @@ -81,6 +86,11 @@ func (s *FirstFactorSuite) TestShouldFailIfUserProviderCheckPasswordFail() { } func (s *FirstFactorSuite) TestShouldCheckAuthenticationIsNotMarkedWhenProviderCheckPasswordError() { + s.mock.UserProviderMock. + EXPECT(). + GetDetails(gomock.Eq("test")). + Return(&authentication.UserDetails{Username: "test"}, nil) + s.mock.UserProviderMock. EXPECT(). CheckUserPassword(gomock.Eq("test"), gomock.Eq("hello")). @@ -107,6 +117,11 @@ func (s *FirstFactorSuite) TestShouldCheckAuthenticationIsNotMarkedWhenProviderC } func (s *FirstFactorSuite) TestShouldCheckAuthenticationIsMarkedWhenInvalidCredentials() { + s.mock.UserProviderMock. + EXPECT(). + GetDetails(gomock.Eq("test")). + Return(&authentication.UserDetails{Username: "test"}, nil) + s.mock.UserProviderMock. EXPECT(). CheckUserPassword(gomock.Eq("test"), gomock.Eq("hello")). @@ -133,16 +148,6 @@ func (s *FirstFactorSuite) TestShouldCheckAuthenticationIsMarkedWhenInvalidCrede } func (s *FirstFactorSuite) TestShouldFailIfUserProviderGetDetailsFail() { - s.mock.UserProviderMock. - EXPECT(). - CheckUserPassword(gomock.Eq("test"), gomock.Eq("hello")). - Return(true, nil) - - s.mock.StorageMock. - EXPECT(). - AppendAuthenticationLog(s.mock.Ctx, gomock.Any()). - Return(nil) - s.mock.UserProviderMock. EXPECT(). GetDetails(gomock.Eq("test")). @@ -155,11 +160,16 @@ func (s *FirstFactorSuite) TestShouldFailIfUserProviderGetDetailsFail() { }`) FirstFactorPOST(nil)(s.mock.Ctx) - AssertLogEntryMessageAndError(s.T(), s.mock.Hook.LastEntry(), "Could not obtain profile details during 1FA authentication for user 'test'", "failed") + AssertLogEntryMessageAndError(s.T(), s.mock.Hook.LastEntry(), "Error occurred getting details for user with username input 'test' which usually indicates they do not exist", "failed") s.mock.Assert401KO(s.T(), "Authentication failed. Check your credentials.") } func (s *FirstFactorSuite) TestShouldFailIfAuthenticationMarkFail() { + s.mock.UserProviderMock. + EXPECT(). + GetDetails(gomock.Eq("test")). + Return(&authentication.UserDetails{Username: "test"}, nil) + s.mock.UserProviderMock. EXPECT(). CheckUserPassword(gomock.Eq("test"), gomock.Eq("hello")). @@ -264,10 +274,47 @@ func (s *FirstFactorSuite) TestShouldAuthenticateUserWithRememberMeUnchecked() { assert.Equal(s.T(), []string{"dev", "admins"}, userSession.Groups) } +func (s *FirstFactorSuite) TestShouldAuthenticateUserWithEmailAsUsernameInput() { + gomock.InOrder( + s.mock.UserProviderMock. + EXPECT(). + GetDetails(gomock.Eq("test@example.com")). + Return(&authentication.UserDetails{ + Username: "test", + Emails: []string{"test@example.com"}, + Groups: []string{"dev", "admins"}, + }, nil), + s.mock.UserProviderMock. + EXPECT(). + CheckUserPassword(gomock.Eq("test"), gomock.Eq("hello")). + Return(true, nil), + s.mock.StorageMock. + EXPECT(). + AppendAuthenticationLog(s.mock.Ctx, gomock.Eq(model.AuthenticationAttempt{Time: s.mock.Clock.Now(), Successful: true, Username: "test", Type: regulation.AuthType1FA, RemoteIP: model.NewNullIP(s.mock.Ctx.RemoteIP())})). + Return(nil), + ) + + s.mock.Ctx.Request.SetBodyString(`{"username":"test@example.com","password":"hello","requestMethod":"GET","keepMeLoggedIn":false}`) + FirstFactorPOST(nil)(s.mock.Ctx) + + // Respond with 200. + s.Equal(fasthttp.StatusOK, s.mock.Ctx.Response.StatusCode()) + s.Equal([]byte("{\"status\":\"OK\"}"), s.mock.Ctx.Response.Body()) + + userSession, err := s.mock.Ctx.GetSession() + s.Assert().NoError(err) + + s.Equal("test", userSession.Username) + s.Equal(false, userSession.KeepMeLoggedIn) + s.Equal(authentication.OneFactor, userSession.AuthenticationLevel) + s.Equal([]string{"test@example.com"}, userSession.Emails) + s.Equal([]string{"dev", "admins"}, userSession.Groups) +} + func (s *FirstFactorSuite) TestShouldSaveUsernameFromAuthenticationBackendInSession() { s.mock.UserProviderMock. EXPECT(). - CheckUserPassword(gomock.Eq("test"), gomock.Eq("hello")). + CheckUserPassword(gomock.Eq("Test"), gomock.Eq("hello")). Return(true, nil) s.mock.UserProviderMock.
Vulnerability mechanics
Synthesis attempt was rejected by the grounding validator. Re-run pending.
References
4News mentions
0No linked articles in our index yet.