name length config

This commit is contained in:
boks1971
2026-05-27 11:20:43 +05:30
parent 42c8463238
commit 5ed3a5ae95
3 changed files with 25 additions and 18 deletions
+7 -1
View File
@@ -281,7 +281,8 @@ type LimitConfig struct {
MaxParticipantIdentityLength int `yaml:"max_participant_identity_length,omitempty"`
MaxParticipantNameLength int `yaml:"max_participant_name_length,omitempty"`
MaxAsyncAttributesSize uint32 `yaml:"max_async_attributes_size,omitempty"`
MaxAsyncAttributeNameLength int `yaml:"max_async_attributes_name_length,omitempty"`
MaxAsyncAttributesSize uint32 `yaml:"max_async_attributes_size,omitempty"`
}
func (l LimitConfig) CheckRoomNameLength(name string) bool {
@@ -312,6 +313,10 @@ func (l LimitConfig) CheckAttributesSize(attributes map[string]string) bool {
return uint32(total) <= l.MaxAttributesSize
}
func (l LimitConfig) CheckAsyncAttributeNameLength(name string) bool {
return l.MaxAsyncAttributeNameLength == 0 || len(name) <= l.MaxAsyncAttributeNameLength
}
func (l LimitConfig) CheckAsyncAttributesSize(asyncAttributes []*livekit.DataTrackSchemaDefinition) bool {
if l.MaxAsyncAttributesSize == 0 {
return true
@@ -457,6 +462,7 @@ var DefaultConfig = Config{
MaxRoomNameLength: 256,
MaxParticipantIdentityLength: 256,
MaxParticipantNameLength: 256,
MaxAsyncAttributeNameLength: 256,
MaxAsyncAttributesSize: 256000,
},
Logging: LoggingConfig{
@@ -34,7 +34,7 @@ func (p *ParticipantImpl) HandleDefineDataTrackSchemaRequest(req *livekit.Define
return
}
if req.SchemaDefinition == nil || req.SchemaDefinition.Id == nil || len(req.SchemaDefinition.Id.Name) == 0 || len(req.SchemaDefinition.Id.Name) > 256 {
if req.SchemaDefinition == nil || req.SchemaDefinition.Id == nil || len(req.SchemaDefinition.Id.Name) == 0 || !p.params.LimitConfig.CheckAsyncAttributeNameLength(req.SchemaDefinition.Id.Name) {
p.pubLogger.Warnw("aync attribute definition is invalid", nil, "req", logger.Proto(req))
p.sendRequestResponse(&livekit.RequestResponse{
Reason: livekit.RequestResponse_INVALID_REQUEST,
@@ -27,12 +27,13 @@ import (
"github.com/livekit/livekit-server/pkg/rtc/types/typesfakes"
)
func newParticipantWithAsyncAttributes(t *testing.T, enabled bool, maxSize uint32) *ParticipantImpl {
func newParticipantWithAsyncAttributes(t *testing.T, enabled bool, maxNameLength int, maxSize uint32) *ParticipantImpl {
t.Helper()
p := newParticipantForTest("test")
p.params.EnableParticipantAsyncAttributes = enabled
p.params.LimitConfig = config.LimitConfig{
MaxAsyncAttributesSize: maxSize,
MaxAsyncAttributeNameLength: maxNameLength,
MaxAsyncAttributesSize: maxSize,
}
return p
}
@@ -47,7 +48,7 @@ func lastRequestResponse(t *testing.T, sink *routingfakes.FakeMessageSink, idx i
func TestHandleDefineDataTrackSchemaRequest(t *testing.T) {
t.Run("returns NOT_ALLOWED when feature not enabled", func(t *testing.T) {
p := newParticipantWithAsyncAttributes(t, false, 0)
p := newParticipantWithAsyncAttributes(t, false, 0, 0)
sink := p.params.Sink.(*routingfakes.FakeMessageSink)
req := &livekit.DefineDataTrackSchemaRequest{
@@ -69,7 +70,7 @@ func TestHandleDefineDataTrackSchemaRequest(t *testing.T) {
})
t.Run("returns INVALID_REQUEST when schema definition is nil", func(t *testing.T) {
p := newParticipantWithAsyncAttributes(t, true, 0)
p := newParticipantWithAsyncAttributes(t, true, 0, 0)
sink := p.params.Sink.(*routingfakes.FakeMessageSink)
p.HandleDefineDataTrackSchemaRequest(&livekit.DefineDataTrackSchemaRequest{})
@@ -81,7 +82,7 @@ func TestHandleDefineDataTrackSchemaRequest(t *testing.T) {
})
t.Run("returns INVALID_REQUEST when id is nil", func(t *testing.T) {
p := newParticipantWithAsyncAttributes(t, true, 0)
p := newParticipantWithAsyncAttributes(t, true, 0, 0)
sink := p.params.Sink.(*routingfakes.FakeMessageSink)
p.HandleDefineDataTrackSchemaRequest(&livekit.DefineDataTrackSchemaRequest{
@@ -96,7 +97,7 @@ func TestHandleDefineDataTrackSchemaRequest(t *testing.T) {
})
t.Run("returns INVALID_REQUEST when name is empty", func(t *testing.T) {
p := newParticipantWithAsyncAttributes(t, true, 0)
p := newParticipantWithAsyncAttributes(t, true, 0, 0)
sink := p.params.Sink.(*routingfakes.FakeMessageSink)
p.HandleDefineDataTrackSchemaRequest(&livekit.DefineDataTrackSchemaRequest{
@@ -115,7 +116,7 @@ func TestHandleDefineDataTrackSchemaRequest(t *testing.T) {
})
t.Run("returns INVALID_REQUEST when name exceeds 256 chars", func(t *testing.T) {
p := newParticipantWithAsyncAttributes(t, true, 0)
p := newParticipantWithAsyncAttributes(t, true, 256, 0)
sink := p.params.Sink.(*routingfakes.FakeMessageSink)
p.HandleDefineDataTrackSchemaRequest(&livekit.DefineDataTrackSchemaRequest{
@@ -134,7 +135,7 @@ func TestHandleDefineDataTrackSchemaRequest(t *testing.T) {
})
t.Run("returns INVALID_REQUEST when definition is empty", func(t *testing.T) {
p := newParticipantWithAsyncAttributes(t, true, 0)
p := newParticipantWithAsyncAttributes(t, true, 0, 0)
sink := p.params.Sink.(*routingfakes.FakeMessageSink)
p.HandleDefineDataTrackSchemaRequest(&livekit.DefineDataTrackSchemaRequest{
@@ -154,7 +155,7 @@ func TestHandleDefineDataTrackSchemaRequest(t *testing.T) {
})
t.Run("returns LIMIT_EXCEEDED when adding would breach the limit", func(t *testing.T) {
p := newParticipantWithAsyncAttributes(t, true, 16)
p := newParticipantWithAsyncAttributes(t, true, 0, 16)
sink := p.params.Sink.(*routingfakes.FakeMessageSink)
p.HandleDefineDataTrackSchemaRequest(&livekit.DefineDataTrackSchemaRequest{
@@ -174,7 +175,7 @@ func TestHandleDefineDataTrackSchemaRequest(t *testing.T) {
})
t.Run("stores a valid definition and sends no response", func(t *testing.T) {
p := newParticipantWithAsyncAttributes(t, true, 0)
p := newParticipantWithAsyncAttributes(t, true, 0, 0)
sink := p.params.Sink.(*routingfakes.FakeMessageSink)
id := &livekit.DataTrackSchemaId{
@@ -201,7 +202,7 @@ func TestHandleDefineDataTrackSchemaRequest(t *testing.T) {
func TestHandleGetDataTrackSchemaRequest(t *testing.T) {
t.Run("returns INVALID_REQUEST when schema id is missing", func(t *testing.T) {
p := newParticipantWithAsyncAttributes(t, true, 0)
p := newParticipantWithAsyncAttributes(t, true, 0, 0)
sink := p.params.Sink.(*routingfakes.FakeMessageSink)
p.HandleGetDataTrackSchemaRequest(&livekit.GetDataTrackSchemaRequest{
@@ -214,7 +215,7 @@ func TestHandleGetDataTrackSchemaRequest(t *testing.T) {
})
t.Run("forwards request to listener when schema id is provided", func(t *testing.T) {
p := newParticipantWithAsyncAttributes(t, true, 0)
p := newParticipantWithAsyncAttributes(t, true, 0, 0)
listener := p.params.ParticipantListener.(*typesfakes.FakeLocalParticipantListener)
req := &livekit.GetDataTrackSchemaRequest{
@@ -234,7 +235,7 @@ func TestHandleGetDataTrackSchemaRequest(t *testing.T) {
}
func TestGetDataTrackSchema(t *testing.T) {
p := newParticipantWithAsyncAttributes(t, true, 0)
p := newParticipantWithAsyncAttributes(t, true, 0, 0)
id := &livekit.DataTrackSchemaId{
Name: "schema-1",
@@ -255,7 +256,7 @@ func TestGetDataTrackSchema(t *testing.T) {
func TestProcessGetDataTrackSchemaRequest(t *testing.T) {
t.Run("returns NOT_FOUND when publisher is nil", func(t *testing.T) {
p := newParticipantWithAsyncAttributes(t, true, 0)
p := newParticipantWithAsyncAttributes(t, true, 0, 0)
sink := p.params.Sink.(*routingfakes.FakeMessageSink)
p.ProcessGetDataTrackSchemaRequest(&livekit.GetDataTrackSchemaRequest{
@@ -272,7 +273,7 @@ func TestProcessGetDataTrackSchemaRequest(t *testing.T) {
})
t.Run("returns NOT_FOUND when publisher has no matching schema", func(t *testing.T) {
p := newParticipantWithAsyncAttributes(t, true, 0)
p := newParticipantWithAsyncAttributes(t, true, 0, 0)
sink := p.params.Sink.(*routingfakes.FakeMessageSink)
publisher := &typesfakes.FakeParticipant{}
@@ -295,7 +296,7 @@ func TestProcessGetDataTrackSchemaRequest(t *testing.T) {
})
t.Run("sends schema response when publisher has a matching schema", func(t *testing.T) {
p := newParticipantWithAsyncAttributes(t, true, 0)
p := newParticipantWithAsyncAttributes(t, true, 0, 0)
sink := p.params.Sink.(*routingfakes.FakeMessageSink)
id := &livekit.DataTrackSchemaId{