From 7e2e8c703e53406405a9205348ed399dd7702446 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Fri, 12 Dec 2025 22:52:46 +0100 Subject: [PATCH] Add SDP validation to publishService() Validation: Add comprehensive offer validation - Validate each offer is an object - Validate each offer has sdp property - Validate sdp is a string - Validate sdp is not empty/whitespace Impact: Prevents runtime errors from malformed offers Improves error messages with specific index information --- src/rpc.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/rpc.ts b/src/rpc.ts index 7c91710..5f0e2cd 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -336,6 +336,19 @@ const handlers: Record = { ); } + // Validate each offer has valid SDP + offers.forEach((offer, index) => { + if (!offer || typeof offer !== 'object') { + throw new Error(`Invalid offer at index ${index}: must be an object`); + } + if (!offer.sdp || typeof offer.sdp !== 'string') { + throw new Error(`Invalid offer at index ${index}: missing or invalid SDP`); + } + if (!offer.sdp.trim()) { + throw new Error(`Invalid offer at index ${index}: SDP cannot be empty`); + } + }); + // Create service with offers const now = Date.now(); const offerTtl =