matrix-rust-sdk icon indicating copy to clipboard operation
matrix-rust-sdk copied to clipboard

`Room::decrypt_event` does not decrypt event bundled in `m.relations`

Open zecakeh opened this issue 7 months ago • 2 comments

In the case of edits (m.replace relation type), the latest edit is bundled under m.relations on the event. It means that, in encrypted rooms, we have two encrypted events in the raw JSON.

Currently, when we pass the raw JSON to Room::decrypt_event(), only the main event is decrypted, leaving the bundled one encrypted. So when we deserialize the decrypted JSON, the bundled event is mostly lost because the Ruma type expects an edit of the same type as the main event, but the bundled event is still of type m.room.encrypted. It still keeps track that there was an "invalid" replacement, but we lost the content.

That leads to issues like #2848.

My proposal would be to change Room::decrypt_event() to also decrypt the bundled event. That has the benefit of being simpler for the users, but has the downside that it will result in breaking changes to the return type, since it should know reflect that we tried to decrypt several events. It should probably not fail if the bundled event failed to be decrypted though, but keep it around so decrypting only the bundled event can be retried later.

It is still possible to solve this issue without the proposed solution by extracting the bundled event in the raw JSON and sending it to Room::decrypt_event manually. That has the benefit of not changing the API, but that is something that users will need to do manually. Besides some APIs are already broken because of it, and we could solve them globally instead of one by one. For example, Room::messages() will always lose the bundled event in encrypted rooms.

zecakeh avatar Dec 22 '23 11:12 zecakeh