Check size limits on metadata and name set from client. (#2850)

* Send error response when update metadata fails.

Keeping it simple for the first implementation.
- Send error response only if request_id != 0
- Two kinds of errors notified
  o does not have permissions - NOT_ALLOWED
  o attributes exceeds size limits -  INVALID_ARGUMENT

* Check size limits on metadata and name set from client.

Added a name length limit also.

* check name length in service update participant path also

* limit check in limit config

* update protocol

* longer keys
This commit is contained in:
Raja Subramanian
2024-07-12 09:57:17 +05:30
committed by GitHub
parent ff66b545b4
commit 09e3aef859
15 changed files with 208 additions and 206 deletions
+14 -4
View File
@@ -417,6 +417,7 @@ func (r *RoomManager) StartSession(
Sink: responseSink,
AudioConfig: r.config.Audio,
VideoConfig: r.config.Video,
LimitConfig: r.config.Limit,
ProtocolVersion: pv,
SessionStartTime: sessionStartTime,
Telemetry: r.telemetry,
@@ -433,7 +434,6 @@ func (r *RoomManager) StartSession(
AdaptiveStream: pi.AdaptiveStream,
AllowTCPFallback: allowFallback,
TURNSEnabled: r.config.IsTURNSEnabled(),
MaxAttributesSize: r.config.Limit.MaxAttributesSize,
GetParticipantInfo: func(pID livekit.ParticipantID) *livekit.ParticipantInfo {
if p := room.GetParticipantByID(pID); p != nil {
return p.ToProto()
@@ -703,7 +703,7 @@ func (r *RoomManager) MutePublishedTrack(ctx context.Context, req *livekit.MuteR
}
func (r *RoomManager) UpdateParticipant(ctx context.Context, req *livekit.UpdateParticipantRequest) (*livekit.ParticipantInfo, error) {
room, participant, err := r.roomAndParticipantForReq(ctx, req)
_, participant, err := r.roomAndParticipantForReq(ctx, req)
if err != nil {
return nil, err
}
@@ -713,10 +713,20 @@ func (r *RoomManager) UpdateParticipant(ctx context.Context, req *livekit.Update
"permission", req.Permission,
"attributes", req.Attributes,
)
err = room.UpdateParticipantMetadata(participant, req.Name, req.Metadata, req.Attributes)
if err != nil {
if err = participant.CheckMetadataLimits(req.Name, req.Metadata, req.Attributes); err != nil {
return nil, err
}
if req.Name != "" {
participant.SetName(req.Name)
}
if req.Metadata != "" {
participant.SetMetadata(req.Metadata)
}
if req.Attributes != nil {
participant.SetAttributes(req.Attributes)
}
if req.Permission != nil {
participant.SetPermission(req.Permission)
}