mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-19 11:45:12 +00:00
fix(login v1): only check password expiry for local users with password (#11344)
# Which Problems Are Solved When setting a password expiry policy, users without password, e.g. federated users, would be prompted to change their password. This was due to two bugs, where the policy would be applied for all users. Additionally, whenever a user was created a `PasswordChanged` timestamp would be set, regardless if the user has a password or not. # How the Problems Are Solved - Only apply the password expiry check on local authentication and users with a password (e.g. passkey only users would not be prompted) - Only set the `PasswordChanged` timestamp for users with password # Additional Changes None # Additional Context - reported through Discord: https://discord.com/channels/927474939156643850/1447235781717397596/1450481990808637470 - requires backport to v4.x
This commit is contained in:
@@ -1146,7 +1146,10 @@ func (repo *AuthRequestRepo) nextSteps(ctx context.Context, request *domain.Auth
|
||||
return append(steps, step), nil
|
||||
}
|
||||
|
||||
expired := passwordAgeChangeRequired(request.PasswordAgePolicy, user.PasswordChanged)
|
||||
var expired bool
|
||||
if isInternalLogin && user.PasswordSet {
|
||||
expired = passwordAgeChangeRequired(request.PasswordAgePolicy, user.PasswordChanged)
|
||||
}
|
||||
if expired || user.PasswordChangeRequired {
|
||||
steps = append(steps, &domain.ChangePasswordStep{Expired: expired})
|
||||
}
|
||||
|
||||
@@ -1916,6 +1916,60 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) {
|
||||
[]domain.NextStep{&domain.ChangePasswordStep{Expired: true}},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"password change expiry for non local user ignored, next possible step",
|
||||
fields{
|
||||
userSessionViewProvider: &mockViewUserSession{
|
||||
ExternalLoginVerification: testNow.Add(-5 * time.Minute),
|
||||
SecondFactorVerification: testNow.Add(-5 * time.Minute),
|
||||
},
|
||||
userViewProvider: &mockViewUser{
|
||||
PasswordSet: false,
|
||||
PasswordChangeRequired: false,
|
||||
IsEmailVerified: false,
|
||||
MFAMaxSetUp: int32(domain.MFALevelSecondFactor),
|
||||
},
|
||||
userEventProvider: &mockEventUser{},
|
||||
orgViewProvider: &mockViewOrg{State: domain.OrgStateActive},
|
||||
lockoutPolicyProvider: &mockLockoutPolicy{
|
||||
policy: &query.LockoutPolicy{
|
||||
ShowFailures: true,
|
||||
},
|
||||
},
|
||||
passwordAgePolicyProvider: &mockPasswordAgePolicy{
|
||||
policy: &query.PasswordAgePolicy{
|
||||
MaxAgeDays: 30,
|
||||
},
|
||||
},
|
||||
idpUserLinksProvider: &mockIDPUserLinks{
|
||||
[]*query.IDPUserLink{
|
||||
{
|
||||
IDPID: "idpID",
|
||||
UserID: "userID",
|
||||
IDPName: "idpName",
|
||||
ProvidedUserID: "providedUserID",
|
||||
ProvidedUsername: "providedUsername",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
args{&domain.AuthRequest{
|
||||
UserID: "UserID",
|
||||
LoginPolicy: &domain.LoginPolicy{
|
||||
AllowUsernamePassword: true,
|
||||
SecondFactors: []domain.SecondFactorType{domain.SecondFactorTypeTOTP},
|
||||
PasswordCheckLifetime: 10 * 24 * time.Hour,
|
||||
ExternalLoginCheckLifetime: 18 * time.Hour,
|
||||
SecondFactorCheckLifetime: 18 * time.Hour,
|
||||
},
|
||||
PasswordAgePolicy: &domain.PasswordAgePolicy{
|
||||
MaxAgeDays: 30,
|
||||
},
|
||||
SelectedIDPConfigID: "idpID",
|
||||
}, false},
|
||||
[]domain.NextStep{&domain.VerifyEMailStep{}},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"email verified and no password change required, redirect to callback step",
|
||||
fields{
|
||||
|
||||
Reference in New Issue
Block a user