Add configurable read-message size limit on signalling WebSockets (#4743)
* Add configurable read-message size limit on signalling WebSockets Set a read limit on both the client-facing (/rtc) and agent worker WebSocket connections so an oversized frame is rejected by the transport before being buffered. The limits are operator-tunable via signal_message_size_limit and agent_signal_message_size_limit, both defaulting to 2 MiB (0 disables). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Add tests for signalling WebSocket read-message size limit Cover the configurable signal_message_size_limit added in the prior commit: - config: assert both limits default to 2 MiB and that a YAML override (including 0 to disable) is parsed correctly. - full-path integration: a real client connects to /rtc on a single-node server and an oversized frame is rejected by the transport with a 1009 close; a 0 limit leaves the connection unbounded and signalling proceeds. Adds setupSingleNodeTestWithConfig so a single-node server can be started with config overrides. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Bound decompressed size of signalling WebSocket messages conn.SetReadLimit only accounts for the compressed bytes read off the wire, and the client-facing /rtc upgrader negotiates permessage-deflate, so a small compressed frame could still expand into a much larger buffer once inflated. Enforce the same limit on the decompressed message by reading through NextReader + io.LimitReader in WSSignalConnection instead of the unbounded ReadMessage. The transport-level SetReadLimit is kept as the cheap wire-level guard; the new check is the decompressed-size backstop. Adds NextReader to the WebsocketClient interface (regenerated fake) and a unit test plus permessage-deflate integration tests covering the amplification case. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
fad2cc4afe
commit
3c6e56232e
@@ -131,6 +131,8 @@ func HandshakeAgentWorker(c agent.SignalConn, serverInfo *livekit.ServerInfo, re
|
||||
type AgentService struct {
|
||||
upgrader AgentSocketUpgrader
|
||||
|
||||
signalMessageSizeLimit int64
|
||||
|
||||
*AgentHandler
|
||||
}
|
||||
|
||||
@@ -170,7 +172,9 @@ func NewAgentService(
|
||||
bus psrpc.MessageBus,
|
||||
keyProvider auth.KeyProvider,
|
||||
) (*AgentService, error) {
|
||||
s := &AgentService{}
|
||||
s := &AgentService{
|
||||
signalMessageSizeLimit: conf.Limit.AgentSignalMessageSizeLimit,
|
||||
}
|
||||
|
||||
serverInfo := &livekit.ServerInfo{
|
||||
Edition: livekit.ServerInfo_Standard,
|
||||
@@ -200,7 +204,14 @@ func NewAgentService(
|
||||
|
||||
func (s *AgentService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if conn, registration, ok := s.upgrader.Upgrade(w, r, nil); ok {
|
||||
s.HandleConnection(r.Context(), NewWSSignalConnection(conn), registration)
|
||||
// bound the size of a single signalling frame so an oversized message is
|
||||
// rejected by the transport before being fully buffered in memory. This
|
||||
// limits the compressed bytes read off the wire; the decompressed size is
|
||||
// bounded separately in WSSignalConnection.
|
||||
if s.signalMessageSizeLimit > 0 {
|
||||
conn.SetReadLimit(s.signalMessageSizeLimit)
|
||||
}
|
||||
s.HandleConnection(r.Context(), NewWSSignalConnection(conn, s.signalMessageSizeLimit), registration)
|
||||
conn.Close()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user