From 9fe05e7d40c3151a04af9c7f80c6c1fa15d6b0f5 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Mon, 9 Aug 2021 12:43:00 +0200 Subject: [PATCH 1/5] Fix temporary call messages being handled without call In cases where a rogue client, or just a simple bug, sends a temporary call message, like CallNegotiate the messages should just be discarded if there's no actual p2p connection created. --- src/webrtc/call.ts | 6 +++++- src/webrtc/callEventHandler.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index f757168febb..f1456e26ce7 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -1286,7 +1286,7 @@ export class MatrixCall extends EventEmitter { // https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Perfect_negotiation const offerCollision = ( (description.type === 'offer') && - (this.makingOffer || this.peerConn.signalingState != 'stable') + (this.makingOffer || this.peerConn.signalingState !== 'stable') ); this.ignoreOffer = !polite && offerCollision; @@ -1935,6 +1935,10 @@ export class MatrixCall extends EventEmitter { } } } + + get hasPeerConnection() { + return Boolean(this.peerConn); + } } async function getScreensharingStream( diff --git a/src/webrtc/callEventHandler.ts b/src/webrtc/callEventHandler.ts index 3e080c0eb55..8251cdf0422 100644 --- a/src/webrtc/callEventHandler.ts +++ b/src/webrtc/callEventHandler.ts @@ -220,6 +220,7 @@ export class CallEventHandler { } else { this.client.emit("Call.incoming", call); } + return; } else if (type === EventType.CallCandidates) { if (weSentTheEvent) return; @@ -232,6 +233,7 @@ export class CallEventHandler { } else { call.onRemoteIceCandidatesReceived(event); } + return; } else if ([EventType.CallHangup, EventType.CallReject].includes(type)) { // Note that we also observe our own hangups here so we can see // if we've already rejected a call that would otherwise be valid @@ -255,10 +257,14 @@ export class CallEventHandler { this.calls.delete(content.call_id); } } + return; } - // The following events need a call - if (!call) return; + // The following events need a call and a peer connection + if (!call && !call.hasPeerConnection) { + logger.warn('Discarding an event', type); + return; + } // Ignore remote echo if (event.getContent().party_id === call.ourPartyId) return; From 4fd77c2f0528aa90f56076d7e35898ef2a05c9a0 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk <3636685+Palid@users.noreply.github.com> Date: Wed, 11 Aug 2021 14:38:08 +0200 Subject: [PATCH 2/5] Update src/webrtc/callEventHandler.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Šimon Brandner --- src/webrtc/callEventHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webrtc/callEventHandler.ts b/src/webrtc/callEventHandler.ts index 8251cdf0422..8ffe3efff21 100644 --- a/src/webrtc/callEventHandler.ts +++ b/src/webrtc/callEventHandler.ts @@ -262,7 +262,7 @@ export class CallEventHandler { // The following events need a call and a peer connection if (!call && !call.hasPeerConnection) { - logger.warn('Discarding an event', type); + logger.warn('Discarding an event, we don't have a call/peerConn', type); return; } // Ignore remote echo From 3e94db1837ecead43f5bc85c9e697ae8e3fffac5 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk <3636685+Palid@users.noreply.github.com> Date: Wed, 11 Aug 2021 14:38:13 +0200 Subject: [PATCH 3/5] Update src/webrtc/call.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Šimon Brandner --- src/webrtc/call.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index f1456e26ce7..72b927bd9c7 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -1936,7 +1936,7 @@ export class MatrixCall extends EventEmitter { } } - get hasPeerConnection() { + public get hasPeerConnection() { return Boolean(this.peerConn); } } From d7dbaeba46f5a17335fe60a227d40dc41a586f12 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk <3636685+Palid@users.noreply.github.com> Date: Wed, 11 Aug 2021 14:38:20 +0200 Subject: [PATCH 4/5] Update src/webrtc/callEventHandler.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Šimon Brandner --- src/webrtc/callEventHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webrtc/callEventHandler.ts b/src/webrtc/callEventHandler.ts index 8ffe3efff21..4067c58d145 100644 --- a/src/webrtc/callEventHandler.ts +++ b/src/webrtc/callEventHandler.ts @@ -261,7 +261,7 @@ export class CallEventHandler { } // The following events need a call and a peer connection - if (!call && !call.hasPeerConnection) { + if (!call || !call.hasPeerConnection) { logger.warn('Discarding an event, we don't have a call/peerConn', type); return; } From 4607f0177cf7d95bb48df1372dbcfb5d5fee8767 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Wed, 11 Aug 2021 14:39:00 +0200 Subject: [PATCH 5/5] Fix invalid string quotes --- src/webrtc/callEventHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webrtc/callEventHandler.ts b/src/webrtc/callEventHandler.ts index 4067c58d145..2ad4bcc7132 100644 --- a/src/webrtc/callEventHandler.ts +++ b/src/webrtc/callEventHandler.ts @@ -262,7 +262,7 @@ export class CallEventHandler { // The following events need a call and a peer connection if (!call || !call.hasPeerConnection) { - logger.warn('Discarding an event, we don't have a call/peerConn', type); + logger.warn("Discarding an event, we don't have a call/peerConn", type); return; } // Ignore remote echo