From 80d87e1bf1937be3c8cd96a55d532f7d0f8997bc Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 1 Apr 2020 17:13:24 +0200 Subject: [PATCH] prevent the same event being handled twice in the verification request, result in cancellation --- src/crypto/verification/request/InRoomChannel.js | 5 +++++ .../verification/request/VerificationRequest.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/crypto/verification/request/InRoomChannel.js b/src/crypto/verification/request/InRoomChannel.js index 19b49fd75..dfcbfee0e 100644 --- a/src/crypto/verification/request/InRoomChannel.js +++ b/src/crypto/verification/request/InRoomChannel.js @@ -178,6 +178,11 @@ export class InRoomChannel { * @returns {Promise} a promise that resolves when any requests as an anwser to the passed-in event are sent. */ async handleEvent(event, request, isLiveEvent) { + // prevent processing the same event multiple times, as under + // some circumstances Room.timeline can get emitted twice for the same event + if (request.hasEventId(event.getId())) { + return; + } const type = InRoomChannel.getEventType(event); // do validations that need state (roomId, userId), // ignore if invalid diff --git a/src/crypto/verification/request/VerificationRequest.js b/src/crypto/verification/request/VerificationRequest.js index 87442613a..3dcb70290 100644 --- a/src/crypto/verification/request/VerificationRequest.js +++ b/src/crypto/verification/request/VerificationRequest.js @@ -612,6 +612,20 @@ export class VerificationRequest extends EventEmitter { return newRaceIdentifier < oldRaceIdentifier; } + hasEventId(eventId) { + for (const event of this._eventsByUs.values()) { + if (event.getId() === eventId) { + return true; + } + } + for (const event of this._eventsByThem.values()) { + if (event.getId() === eventId) { + return true; + } + } + return false; + } + /** * Changes the state of the request and verifier in response to a key verification event. * @param {string} type the "symbolic" event type, as returned by the `getEventType` function on the channel.