mirror of https://github.com/usememos/memos.git
fix: add nil check for currentUser in DeleteUser
Defense-in-depth fix: Add missing nil check before accessing currentUser.ID and currentUser.Role in DeleteUser function. While the auth interceptor should block unauthenticated requests, this check prevents potential nil pointer panic if fetchCurrentUser returns (nil, nil).
This commit is contained in:
parent
c7b48b800f
commit
1696c6c414
|
|
@ -301,6 +301,9 @@ func (s *APIV1Service) DeleteUser(ctx context.Context, request *v1pb.DeleteUserR
|
|||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to get user: %v", err)
|
||||
}
|
||||
if currentUser == nil {
|
||||
return nil, status.Errorf(codes.Unauthenticated, "user not authenticated")
|
||||
}
|
||||
if currentUser.ID != userID && currentUser.Role != store.RoleAdmin {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue