|
| 1 | +# MSC3700: Deprecate plaintext sender_key |
| 2 | + |
| 3 | +This MSC proposes to deprecate superfluous fields from the plaintext event |
| 4 | +content of encrypted events, increasing privacy and enhancing security. |
| 5 | + |
| 6 | +An encrypted message that uses an algorithm of |
| 7 | +[`m.megolm.v1.aes-sha2`](https://spec.matrix.org/v1.2/client-server-api/#mmegolmv1aes-sha2) |
| 8 | +(such as an `m.room.encrypted` event) contains the following plain text keys in |
| 9 | +its contents: `algorithm`, `session_id`, `sender_key` and `device_id`. Both the |
| 10 | +`algorithm` and `session_id` are required for clients to be able to decrypt the |
| 11 | +ciphertext: the algorithm explains how to decrypt and the session ID says which |
| 12 | +session to use to decrypt the ciphertext. |
| 13 | + |
| 14 | +The `sender_key` and `device_id` are currently used by clients to store and |
| 15 | +lookup sessions in addition to the `session_id`, however the `session_id` is |
| 16 | +globally unique and so no disambiguation using `sender_key` or `device_id` is |
| 17 | +needed. |
| 18 | + |
| 19 | +Session IDs are encoded ed25519 public keys. In particular, the session ID is |
| 20 | +the public part of the key used to sign the session when it is shared. |
| 21 | + |
| 22 | +## Proposal |
| 23 | + |
| 24 | +The `sender_key` and `device_id` in `m.megolm.v1.aes-sha2` message contents are |
| 25 | +deprecated. Clients must ignore those fields when processing events, but should |
| 26 | +still include the fields when generating events to maintain backwards |
| 27 | +compatibility. At a future time the fields will stop being included. |
| 28 | + |
| 29 | +Similarly, the `sender_key` field in `m.room_key_request` to-device messages is |
| 30 | +deprecated. Clients must ignore the field when processing the request, but |
| 31 | +should still include it when generating *if* there is a `sender_key` field in |
| 32 | +the event we're requesting keys for. |
| 33 | + |
| 34 | +Clients must not store or lookup sessions using the sender key or device ID. |
| 35 | + |
| 36 | +Client must continue to ensure that the event's sender and room ID fields match |
| 37 | +those of the looked up session, e.g. by storing and looking up session using the |
| 38 | +room ID and sender as well as the session ID. |
| 39 | + |
| 40 | +When updating an existing session key, clients must ensure: |
| 41 | +1. that the updated session data comes from a trusted source, e.g. either the |
| 42 | + session data has a) a valid signature, or b) comes from the user’s session |
| 43 | + key backup; and |
| 44 | +2. that the new session key has a lower message index than the existing session |
| 45 | + key. |
| 46 | + |
| 47 | +When clients receive an encrypted event with an unknown session they will need |
| 48 | +to send a key request to all clients, rather than the device specified by |
| 49 | +`sender_key` and `device_id`. This is the current behaviour used by Element |
| 50 | +clients. |
| 51 | + |
| 52 | +### Benefits |
| 53 | + |
| 54 | +There are two main benefits of removing the `sender_key` and `device_id`: |
| 55 | +enhanced privacy and better security. |
| 56 | + |
| 57 | +Including these extra fields leaks which device was used to send the message, |
| 58 | +and so removing them has an obvious privacy benefit. |
| 59 | + |
| 60 | +On the security side, these fields are untrusted as: a malicious server (or |
| 61 | +other man-in-the-middle (MITM) attacker) can change these values; and other |
| 62 | +devices/users can simply lie about these values. |
| 63 | + |
| 64 | +Currently, clients therefore need to take care to only use these values to look |
| 65 | +up the session. If the client needs to know the associated `sender_key` they |
| 66 | +must use the identity key of the Olm session that was used to send them the |
| 67 | +Megolm session data, and not the `sender_key` in the event contents. |
| 68 | + |
| 69 | +This is an obvious footgun, and therefore removing/ignoring these untrusted |
| 70 | +fields reduces the risk of security bugs being introduced. |
| 71 | + |
| 72 | +## Potential issues |
| 73 | +Removing the `sender_key` and `device_id` means that clients don’t know which |
| 74 | +remote device to ask for the session key if they don’t already have it. Instead, |
| 75 | +clients will need to send a key request to all devices of the event sender. This |
| 76 | +will also reduce the information available when debugging encryption issues. |
0 commit comments