From 6121b9af5eca34eef54690842fb73749525347dc Mon Sep 17 00:00:00 2001 From: cnderrauber Date: Tue, 11 Mar 2025 10:07:05 +0800 Subject: [PATCH] Check ForwardParticipant room name (#3514) --- pkg/service/errors.go | 1 + pkg/service/roomservice.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/pkg/service/errors.go b/pkg/service/errors.go index d208e434c..5c7579abb 100644 --- a/pkg/service/errors.go +++ b/pkg/service/errors.go @@ -30,6 +30,7 @@ var ( ErrAttributeExceedsLimits = psrpc.NewErrorf(psrpc.InvalidArgument, "attribute size exceeds limits") ErrRoomNameExceedsLimits = psrpc.NewErrorf(psrpc.InvalidArgument, "room name length exceeds limits") ErrParticipantIdentityExceedsLimits = psrpc.NewErrorf(psrpc.InvalidArgument, "participant identity length exceeds limits") + ErrForwardToSameRoom = psrpc.NewErrorf(psrpc.InvalidArgument, "cannot forward to the same room") ErrOperationFailed = psrpc.NewErrorf(psrpc.Internal, "operation cannot be completed") ErrParticipantNotFound = psrpc.NewErrorf(psrpc.NotFound, "participant does not exist") ErrRoomNotFound = psrpc.NewErrorf(psrpc.NotFound, "requested room does not exist") diff --git a/pkg/service/roomservice.go b/pkg/service/roomservice.go index e88d30321..be0f129f3 100644 --- a/pkg/service/roomservice.go +++ b/pkg/service/roomservice.go @@ -316,6 +316,10 @@ func (s *RoomService) ForwardParticipant(ctx context.Context, req *livekit.Forwa return nil, twirpAuthError(err) } + if req.Room == req.DestinationRoom { + return nil, twirp.InvalidArgumentError(ErrForwardToSameRoom.Error(), "") + } + res, err := s.participantClient.ForwardParticipant(ctx, s.topicFormatter.ParticipantTopic(ctx, livekit.RoomName(req.Room), livekit.ParticipantIdentity(req.Identity)), req) RecordResponse(ctx, res) return res, err