mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
Fix authorization check in reset password (#1182)
Improper authorization checks made it so that users could not reset their password with a reset token.
This commit is contained in:
parent
7af97579fe
commit
675e551484
1 changed files with 6 additions and 5 deletions
|
|
@ -299,19 +299,20 @@ func (svc *Service) ChangePassword(ctx context.Context, oldPass, newPass string)
|
|||
}
|
||||
|
||||
func (svc *Service) ResetPassword(ctx context.Context, token, password string) error {
|
||||
// skipauth: No viewer context available. The user is locked out of their
|
||||
// account and authNZ is performed entirely by providing a valid password
|
||||
// reset token.
|
||||
svc.authz.SkipAuthorization(ctx)
|
||||
|
||||
reset, err := svc.ds.FindPassswordResetByToken(token)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "looking up reset by token")
|
||||
}
|
||||
user, err := svc.User(ctx, reset.UserID)
|
||||
user, err := svc.ds.UserByID(reset.UserID)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "retrieving user")
|
||||
}
|
||||
|
||||
if err := svc.authz.Authorize(ctx, user, fleet.ActionWrite); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if user.SSOEnabled {
|
||||
return errors.New("password reset for single sign on user not allowed")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue