mirror of
https://github.com/livekit/livekit.git
synced 2026-05-24 08:05:33 +00:00
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:
@@ -332,6 +332,31 @@ type LimitConfig struct {
|
||||
MaxAttributesSize uint32 `yaml:"max_attributes_size,omitempty"`
|
||||
MaxRoomNameLength int `yaml:"max_room_name_length,omitempty"`
|
||||
MaxParticipantIdentityLength int `yaml:"max_participant_identity_length,omitempty"`
|
||||
MaxParticipantNameLength int `yaml:"max_participant_name_length,omitempty"`
|
||||
}
|
||||
|
||||
func (l LimitConfig) CheckRoomNameLength(name string) bool {
|
||||
return l.MaxRoomNameLength == 0 || len(name) <= l.MaxRoomNameLength
|
||||
}
|
||||
|
||||
func (l LimitConfig) CheckParticipantNameLength(name string) bool {
|
||||
return l.MaxParticipantNameLength == 0 || len(name) <= l.MaxParticipantNameLength
|
||||
}
|
||||
|
||||
func (l LimitConfig) CheckMetadataSize(metadata string) bool {
|
||||
return l.MaxMetadataSize == 0 || uint32(len(metadata)) <= l.MaxMetadataSize
|
||||
}
|
||||
|
||||
func (l LimitConfig) CheckAttributesSize(attributes map[string]string) bool {
|
||||
if l.MaxAttributesSize == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
total := 0
|
||||
for k, v := range attributes {
|
||||
total += len(k) + len(v)
|
||||
}
|
||||
return uint32(total) <= l.MaxAttributesSize
|
||||
}
|
||||
|
||||
type IngressConfig struct {
|
||||
@@ -540,6 +565,7 @@ var DefaultConfig = Config{
|
||||
MaxAttributesSize: 64000,
|
||||
MaxRoomNameLength: 256,
|
||||
MaxParticipantIdentityLength: 256,
|
||||
MaxParticipantNameLength: 256,
|
||||
},
|
||||
Logging: LoggingConfig{
|
||||
PionLevel: "error",
|
||||
|
||||
Reference in New Issue
Block a user