Small changes to add/use helper functions for length checks. (#3704)
This commit is contained in:
@@ -246,6 +246,10 @@ func (l LimitConfig) CheckRoomNameLength(name string) bool {
|
|||||||
return l.MaxRoomNameLength == 0 || len(name) <= l.MaxRoomNameLength
|
return l.MaxRoomNameLength == 0 || len(name) <= l.MaxRoomNameLength
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l LimitConfig) CheckParticipantIdentityLength(identity string) bool {
|
||||||
|
return l.MaxParticipantIdentityLength == 0 || len(identity) <= l.MaxParticipantIdentityLength
|
||||||
|
}
|
||||||
|
|
||||||
func (l LimitConfig) CheckParticipantNameLength(name string) bool {
|
func (l LimitConfig) CheckParticipantNameLength(name string) bool {
|
||||||
return l.MaxParticipantNameLength == 0 || len(name) <= l.MaxParticipantNameLength
|
return l.MaxParticipantNameLength == 0 || len(name) <= l.MaxParticipantNameLength
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,15 +135,15 @@ func (s *RTCRestService) validateCreate(r *http.Request) (*createRequest, int, e
|
|||||||
if roomName == "" {
|
if roomName == "" {
|
||||||
return nil, http.StatusUnauthorized, errors.New("room name cannot be empty")
|
return nil, http.StatusUnauthorized, errors.New("room name cannot be empty")
|
||||||
}
|
}
|
||||||
if limit := s.config.Limit.MaxRoomNameLength; limit > 0 && len(roomName) > limit {
|
if !s.config.Limit.CheckRoomNameLength(string(roomName)) {
|
||||||
return nil, http.StatusBadRequest, fmt.Errorf("%w: max length %d", ErrRoomNameExceedsLimits, limit)
|
return nil, http.StatusBadRequest, fmt.Errorf("%w: max length %d", ErrRoomNameExceedsLimits, s.config.Limit.MaxRoomNameLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
if claims.Identity == "" {
|
if claims.Identity == "" {
|
||||||
return nil, http.StatusBadRequest, ErrIdentityEmpty
|
return nil, http.StatusBadRequest, ErrIdentityEmpty
|
||||||
}
|
}
|
||||||
if limit := s.config.Limit.MaxParticipantIdentityLength; limit > 0 && len(claims.Identity) > limit {
|
if !s.config.Limit.CheckParticipantIdentityLength(claims.Identity) {
|
||||||
return nil, http.StatusBadRequest, fmt.Errorf("%w: max length %d", ErrParticipantIdentityExceedsLimits, limit)
|
return nil, http.StatusBadRequest, fmt.Errorf("%w: max length %d", ErrParticipantIdentityExceedsLimits, s.config.Limit.MaxParticipantIdentityLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
var clientInfo struct {
|
var clientInfo struct {
|
||||||
|
|||||||
@@ -132,8 +132,8 @@ func (s *RTCService) validateInternal(log logger.Logger, r *http.Request, strict
|
|||||||
if claims.Identity == "" {
|
if claims.Identity == "" {
|
||||||
return "", pi, http.StatusBadRequest, ErrIdentityEmpty
|
return "", pi, http.StatusBadRequest, ErrIdentityEmpty
|
||||||
}
|
}
|
||||||
if limit := s.config.Limit.MaxParticipantIdentityLength; limit > 0 && len(claims.Identity) > limit {
|
if !s.config.Limit.CheckParticipantIdentityLength(claims.Identity) {
|
||||||
return "", pi, http.StatusBadRequest, fmt.Errorf("%w: max length %d", ErrParticipantIdentityExceedsLimits, limit)
|
return "", pi, http.StatusBadRequest, fmt.Errorf("%w: max length %d", ErrParticipantIdentityExceedsLimits, s.config.Limit.MaxParticipantIdentityLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
roomName := livekit.RoomName(r.FormValue("room"))
|
roomName := livekit.RoomName(r.FormValue("room"))
|
||||||
@@ -150,8 +150,8 @@ func (s *RTCService) validateInternal(log logger.Logger, r *http.Request, strict
|
|||||||
if onlyName != "" {
|
if onlyName != "" {
|
||||||
roomName = onlyName
|
roomName = onlyName
|
||||||
}
|
}
|
||||||
if limit := s.config.Limit.MaxRoomNameLength; limit > 0 && len(roomName) > limit {
|
if !s.config.Limit.CheckRoomNameLength(string(roomName)) {
|
||||||
return "", pi, http.StatusBadRequest, fmt.Errorf("%w: max length %d", ErrRoomNameExceedsLimits, limit)
|
return "", pi, http.StatusBadRequest, fmt.Errorf("%w: max length %d", ErrRoomNameExceedsLimits, s.config.Limit.MaxRoomNameLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is new connection for existing participant - with publish only permissions
|
// this is new connection for existing participant - with publish only permissions
|
||||||
|
|||||||
Reference in New Issue
Block a user