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
@@ -337,6 +337,14 @@ type LimitConfig struct {
|
||||
MaxDataBlobSize uint32 `yaml:"max_data_blobs_size,omitempty"`
|
||||
|
||||
MaxDataTrackCustomEncodingLength int `yaml:"max_data_track_custom_encoding_length,omitempty"`
|
||||
|
||||
// maximum size (in bytes) of a single message read off a client-facing
|
||||
// signalling WebSocket connection. Frames larger than this are rejected by the
|
||||
// transport before being buffered, guarding against single-frame memory
|
||||
// exhaustion. A value of 0 disables the limit (unbounded).
|
||||
SignalMessageSizeLimit int64 `yaml:"signal_message_size_limit,omitempty"`
|
||||
// same as SignalMessageSizeLimit, but for agent worker WebSocket connections.
|
||||
AgentSignalMessageSizeLimit int64 `yaml:"agent_signal_message_size_limit,omitempty"`
|
||||
}
|
||||
|
||||
func (l LimitConfig) CheckRoomNameLength(name string) bool {
|
||||
@@ -543,6 +551,8 @@ var DefaultConfig = Config{
|
||||
MaxDataBlobKeyLength: 256,
|
||||
MaxDataBlobSize: 64000,
|
||||
MaxDataTrackCustomEncodingLength: 32,
|
||||
SignalMessageSizeLimit: 2 << 20, // 2 MiB
|
||||
AgentSignalMessageSizeLimit: 2 << 20, // 2 MiB
|
||||
},
|
||||
Logging: LoggingConfig{
|
||||
PionLevel: "error",
|
||||
|
||||
@@ -42,6 +42,25 @@ func TestConfig_DefaultsKept(t *testing.T) {
|
||||
require.Equal(t, uint32(10), conf.Room.EmptyTimeout)
|
||||
}
|
||||
|
||||
func TestConfig_SignalMessageSizeLimitDefaults(t *testing.T) {
|
||||
conf, err := NewConfig("", true, nil, nil)
|
||||
require.NoError(t, err)
|
||||
// both default to 2 MiB when not specified
|
||||
require.Equal(t, int64(2<<20), conf.Limit.SignalMessageSizeLimit)
|
||||
require.Equal(t, int64(2<<20), conf.Limit.AgentSignalMessageSizeLimit)
|
||||
}
|
||||
|
||||
func TestConfig_SignalMessageSizeLimitOverride(t *testing.T) {
|
||||
const content = `limit:
|
||||
signal_message_size_limit: 1024
|
||||
agent_signal_message_size_limit: 0`
|
||||
conf, err := NewConfig(content, true, nil, nil)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(1024), conf.Limit.SignalMessageSizeLimit)
|
||||
// 0 explicitly disables the limit
|
||||
require.Equal(t, int64(0), conf.Limit.AgentSignalMessageSizeLimit)
|
||||
}
|
||||
|
||||
func TestConfig_UnknownKeys(t *testing.T) {
|
||||
const content = `unknown: 10
|
||||
room:
|
||||
|
||||
Reference in New Issue
Block a user