Skip to content

Commit

Permalink
Bugfix: Return AuthenticationFailedError when password is not OK (#3182)
Browse files Browse the repository at this point in the history
This fixes a panic in Basic Auth mode.
  • Loading branch information
scudette committed Dec 23, 2023
1 parent ef430fa commit 5dfbb65
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions services/users/set_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
)

var (
NameReservedError = errors.New("Username is reserved")
NameReservedError = errors.New("Username is reserved")
AuthenticationFailedError = errors.New("Authentication Failed")
)

// Update the user's password.
Expand Down Expand Up @@ -143,6 +144,8 @@ func verifyPassword(self *api_proto.VelociraptorUser, password string) bool {
return subtle.ConstantTimeCompare(hash[:], self.PasswordHash) == 1
}

// Verifies the username's password is ok. If the password is not OK
// returns an AuthenticationFailedError too.
func (self *UserManager) VerifyPassword(
ctx context.Context,
principal, username string,
Expand All @@ -153,5 +156,10 @@ func (self *UserManager) VerifyPassword(
return false, err
}

return verifyPassword(user_record, password), nil
ok := verifyPassword(user_record, password)
if !ok {
return ok, AuthenticationFailedError
}

return true, nil
}

0 comments on commit 5dfbb65

Please sign in to comment.