The vulnerability lies in the incomplete validation of message edits across the Matrix Rust SDK. Specifically, the SDK did not enforce a critical rule from the Matrix specification: if an original event (message) is encrypted, any replacement event (edit) must also be encrypted. This oversight allowed a malicious homeserver administrator to replace a user's encrypted message with a cleartext message of their choosing, effectively spoofing messages from that user.
The fix involved creating a new, centralized function, check_validity_of_replacement_events, which correctly implements all the specified validation rules for edits. This function was then integrated into all the code paths that process message edits.
I have identified three key areas where this vulnerability was present:
-
Timeline Aggregation (matrix-sdk-ui): The edit_item function, which is responsible for applying edits to messages in the user's timeline, lacked the necessary validation. This is the most direct manifestation of the vulnerability for an end-user viewing a timeline.
-
Latest Event Logic (matrix-sdk): The Builder::new_remote function, used to determine the most recent event in a room (often for previews), would incorrectly select an invalid edit as the latest event.
-
Thread Summaries (matrix-sdk): The logic for updating thread summaries also failed to validate edits on thread replies, allowing an invalid edit to be reflected as the latest message in a thread.
By patching these functions to use the new validation logic, the vulnerability was remediated throughout the SDK.