Skip to content

Lesson 1 of 9 · 24m

Signaling Is Your Security Boundary

Model the signaling channel WebRTC refuses to define, including authentication, room membership, message ordering, and abuse controls.

The first thing I tell new WebRTC engineers surprises them: WebRTC does not know how a call starts. The browser knows how to describe media, punch NAT holes, encrypt packets, and render audio. It deliberately does not know how two users find each other. That missing piece — signaling — is yours, and it is where identity, authorization, abuse control, and most production incidents live.

WebRTC gives you media plumbing, not a meeting product

The browser API produces and consumes SDP blobs. Your application carries them:

caller browser   --offer SDP-->    your signaling service   --> callee browser
caller browser   <--answer SDP--   your signaling service   <-- callee browser
both browsers    <--ICE candidates------------------------------->

Nothing in WebRTC says this must be WebSocket, HTTP POST, Matrix, SIP, XMPP, or carrier pigeons. In practice it is usually an authenticated WebSocket because you need low latency and server-initiated delivery.

The minimum message contract

A useful signaling envelope carries routing, ordering, and correlation metadata:

{
  "type": "offer",
  "room_id": "rm_01J9W8",
  "from": "usr_ada",
  "to": "usr_lin",
  "session_id": "call_7f42",
  "seq": 18,
  "sdp": "v=0
o=- 829...",
  "sent_at": "2026-11-30T18:04:11Z"
}

Do not let clients write arbitrary from fields. The server must bind the sender identity from the authenticated connection, reject targets outside the room, and enforce monotonically increasing sequence numbers per session.

Signaling is a trust boundary

The server should treat every field as hostile until validated:

async def handle_signal(ws, msg):
    user = ws.state.user
    if msg.room_id not in await memberships.for_user(user.id):
        raise CloseForbidden()
    if msg.type not in {"offer", "answer", "ice", "leave", "mute"}:
        raise CloseProtocolError()
    if len(msg.sdp or "") > 64_000:
        raise CloseMessageTooBig()

This is not pedantry. Signaling servers are exposed to browsers and mobile apps, which means hostile input is normal input. A room invitation is a capability. A malformed SDP can crash older parsers. Unbounded candidate relay can become a reflection or cost problem.

Presence is not authorization

A user being "online" does not mean they may join a room. Model room state explicitly: invited, joined, admitted, removed, locked. If you support waiting rooms, the signaling channel needs distinct events for request, admit, deny, and timeout. The media layer cannot repair a bad admission decision afterward.

Design for reconnects from day one

Mobile browsers suspend sockets. Wi-Fi changes to LTE. VPN clients flap. Use durable session IDs and idempotency keys so a reconnect can resume rather than create a ghost participant. A participant list derived only from live sockets will eventually show two copies of the same person and zero copies of the person actually speaking.

Field notes

  • SDP is opaque to WebRTC but not secret; it contains codecs, fingerprints, network details, and sometimes media capabilities you did not intend to expose broadly.
  • Never use unauthenticated WebSocket rooms with numeric IDs. They are invitation links whether you call them that or not.
  • Store enough signaling history to debug ordering bugs, but redact or expire it; call setup metadata is sensitive behavioral data.
  • Rate-limit joins, renegotiations, and candidate messages. A browser tab loop can spend real money on TURN in minutes.

Was this lesson helpful?

Sign in to rate