From 2375bf061c250a84ba9a7b4de937ff5b36b6c79c Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 4 Aug 2021 10:26:03 -0700 Subject: [PATCH] Strip relates_to from encrypted events' original contents. --- src/matrix/room/sending/PendingEvent.js | 23 +++++++++++++---------- src/matrix/room/sending/SendQueue.js | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/matrix/room/sending/PendingEvent.js b/src/matrix/room/sending/PendingEvent.js index af295579..a6f53059 100644 --- a/src/matrix/room/sending/PendingEvent.js +++ b/src/matrix/room/sending/PendingEvent.js @@ -28,9 +28,7 @@ export const SendStatus = createEnum( "Error", ); -const preservedContentFields = { - "m.room.message": [ "m.relates_to" ] -}; +const preservedContentFields = [ "m.relates_to" ]; export class PendingEvent { constructor({data, remove, emitUpdate, attachments}) { @@ -100,14 +98,19 @@ export class PendingEvent { this._emitUpdate("status"); } + get cleanedContent() { + const content = Object.assign({}, this._data.content); + for (const field of preservedContentFields) { + delete content[field]; + } + return content; + } + _preserveContentFields(into) { - const preservedFields = preservedContentFields[this.eventType]; - if (preservedFields) { - const content = this._data.content; - for (const field of preservedFields) { - if (content[field] !== undefined) { - into[field] = content[field]; - } + const content = this._data.content; + for (const field of preservedContentFields) { + if (content[field] !== undefined) { + into[field] = content[field]; } } } diff --git a/src/matrix/room/sending/SendQueue.js b/src/matrix/room/sending/SendQueue.js index dd562610..f9cb19f9 100644 --- a/src/matrix/room/sending/SendQueue.js +++ b/src/matrix/room/sending/SendQueue.js @@ -97,8 +97,9 @@ export class SendQueue { } if (pendingEvent.needsEncryption) { pendingEvent.setEncrypting(); + const cleanedContent = pendingEvent.cleanedContent; const {type, content} = await log.wrap("encrypt", log => this._roomEncryption.encrypt( - pendingEvent.eventType, pendingEvent.content, this._hsApi, log)); + pendingEvent.eventType, cleanedContent, this._hsApi, log)); pendingEvent.setEncrypted(type, content); await this._tryUpdateEvent(pendingEvent); }