Skip to content

Add WebSocket message body size limit to prevent memory exhaustion via large payloads #881

Description

@RUKAYAT-CODER

Overview

src/collaboration/collaboration.gateway.ts accepts WebSocket messages from clients with no size validation. A malicious client can send megabyte-scale operation payloads, exhausting server-side memory during JSON parsing or OT transformation.

Specifications

Features:

  • Reject WebSocket messages exceeding a configurable size limit (default 64KB for collaboration operations).

Tasks:

  • In each @SubscribeMessage handler, measure JSON.stringify(payload).length and throw WsException if over the limit.
  • Read the limit from ConfigService (WS_MAX_PAYLOAD_BYTES).
  • Alternatively, configure maxHttpBufferSize on the Socket.IO server in main.ts.
  • Add unit tests that emit oversized payloads and verify rejection.

Impacted Files:

  • src/collaboration/collaboration.gateway.ts
  • src/main.ts

Acceptance Criteria

  • Messages exceeding the limit result in a WsException with code PAYLOAD_TOO_LARGE.
  • Legitimate messages under the limit are processed normally.
  • Limit is configurable without code changes.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions