From 75559fb21a353e4e97568f6f70c4cf461242b453 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Wed, 1 Mar 2023 11:49:43 +0100 Subject: [PATCH] Ensure the event is decrypted before applying push rules --- .../android/sdk/api/session/pushrules/EventMatchCondition.kt | 5 +---- .../org/matrix/android/sdk/internal/crypto/EventDecryptor.kt | 1 + .../internal/session/pushrules/ProcessEventForPushTask.kt | 5 ++++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushrules/EventMatchCondition.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushrules/EventMatchCondition.kt index d637b4d0bb..c3ddbf14b3 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushrules/EventMatchCondition.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushrules/EventMatchCondition.kt @@ -45,10 +45,7 @@ class EventMatchCondition( if (decryptedRawJson != null) { rawJson .toMutableMap() - .apply { - set("type", decryptedRawJson["type"]) - set("content", decryptedRawJson["content"]) - } + .apply { putAll(decryptedRawJson) } } else { rawJson } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/EventDecryptor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/EventDecryptor.kt index 03672ae81c..ff3ae1890d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/EventDecryptor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/EventDecryptor.kt @@ -94,6 +94,7 @@ internal class EventDecryptor @Inject constructor( * @param timeline the id of the timeline where the event is decrypted. It is used to prevent replay attack. */ suspend fun decryptEventAndSaveResult(event: Event, timeline: String) { + if (event.type == EventType.ENCRYPTED && event.mxDecryptionResult != null) return tryOrNull(message = "Unable to decrypt the event") { decryptEvent(event, timeline) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushrules/ProcessEventForPushTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushrules/ProcessEventForPushTask.kt index 3dfac694ed..7f1acfe0b5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushrules/ProcessEventForPushTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushrules/ProcessEventForPushTask.kt @@ -21,6 +21,7 @@ import org.matrix.android.sdk.api.session.events.model.isInvitation import org.matrix.android.sdk.api.session.pushrules.PushEvents import org.matrix.android.sdk.api.session.pushrules.rest.PushRule import org.matrix.android.sdk.api.session.sync.model.RoomsSyncResponse +import org.matrix.android.sdk.internal.crypto.EventDecryptor import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.task.Task import timber.log.Timber @@ -36,7 +37,8 @@ internal interface ProcessEventForPushTask : Task + eventDecryptor.decryptEventAndSaveResult(event, "") pushRuleFinder.fulfilledBingRule(event, params.rules)?.let { Timber.v("[PushRules] Rule $it match for event ${event.eventId}") event to it