|
1 |
| -# MSC0000: Template for new MSCs |
| 1 | +# MSC4268: Sharing room keys for past messages |
2 | 2 |
|
3 |
| -*Note: Text written in italics represents notes about the section or proposal process. This document |
4 |
| -serves as an example of what a proposal could look like (in this case, a proposal to have a template) |
5 |
| -and should be used where possible.* |
| 3 | +In Matrix, rooms can be configured via the |
| 4 | +[`m.room.history_visibility`](https://spec.matrix.org/v1.14/client-server-api/#room-history-visibility) |
| 5 | +state event such that previously-sent messages can be visible to users that |
| 6 | +join the room. However, this is ineffective in encrypted rooms, where new |
| 7 | +joiners will lack the keys necessary to decrypt historical messages. |
6 | 8 |
|
7 |
| -*In this first section, be sure to cover your problem and a broad overview of the solution. Covering |
8 |
| -related details, such as the expected impact, can also be a good idea. The example in this document |
9 |
| -says that we're missing a template and that things are confusing and goes on to say the solution is |
10 |
| -a template. There's no major expected impact in this proposal, so it doesn't list one. If your proposal |
11 |
| -was more invasive (such as proposing a change to how servers discover each other) then that would be |
12 |
| -a good thing to list here.* |
13 |
| - |
14 |
| -*If you're having troubles coming up with a description, a good question to ask is "how |
15 |
| -does this proposal improve Matrix?" - the answer could reveal a small impact, and that is okay.* |
16 |
| - |
17 |
| -There can never be enough templates in the world, and MSCs shouldn't be any different. The level |
18 |
| -of detail expected of proposals can be unclear - this is what this example proposal (which doubles |
19 |
| -as a template itself) aims to resolve. |
| 9 | +This proposal defines a mechanism by which existing room members can share the |
| 10 | +decryption keys with new members, for example when inviting them, thus giving |
| 11 | +the new members access to historical messages. |
20 | 12 |
|
| 13 | +A previous propsal, |
| 14 | +[MSC3061](https://github.com/matrix-org/matrix-spec-proposals/pull/3061) aimed |
| 15 | +to solve a similar problem; however, the mechanism used did not scale well. In |
| 16 | +addition, the implementation in `matrix-js-sdk` was subject to a [security |
| 17 | +vulnerability](https://matrix.org/blog/2024/10/security-disclosure-matrix-js-sdk-and-matrix-react-sdk/) |
| 18 | +which this proposal addresses. |
21 | 19 |
|
22 | 20 | ## Proposal
|
23 | 21 |
|
24 |
| -*Here is where you'll reinforce your position from the introduction in more detail, as well as cover |
25 |
| -the technical points of your proposal. Including rationale for your proposed solution and detailing |
26 |
| -why parts are important helps reviewers understand the problem at hand. Not including enough detail |
27 |
| -can result in people guessing, leading to confusing arguments in the comments section. The example |
28 |
| -here covers why templates are important again, giving a stronger argument as to why we should have |
29 |
| -a template. Afterwards, it goes on to cover the specifics of what the template could look like.* |
30 |
| - |
31 |
| -Having a default template that everyone can use is important. Without a template, proposals would be |
32 |
| -all over the place and the minimum amount of detail may be left out. Introducing a template to the |
33 |
| -proposal process helps ensure that some amount of consistency is present across multiple proposals, |
34 |
| -even if each author decides to abandon the template. |
35 |
| - |
36 |
| -The default template should be a markdown document because the MSC process requires authors to write |
37 |
| -a proposal in markdown. Using other formats wouldn't make much sense because that would prevent authors |
38 |
| -from copy/pasting the template. |
39 |
| - |
40 |
| -The template should have the following sections: |
41 |
| - |
42 |
| -* **Introduction** - This should cover the primary problem and broad description of the solution. |
43 |
| -* **Proposal** - The gory details of the proposal. |
44 |
| -* **Potential issues** - This is where problems with the proposal would be listed, such as changes |
45 |
| - that are not backwards compatible. |
46 |
| -* **Alternatives** - This section lists alternative solutions to the same |
47 |
| - problem which have been considered and dismsissed. |
48 |
| -* **Security considerations** - Discussion of what steps were taken to avoid security issues in the |
49 |
| - future and any potential risks in the proposal. |
50 |
| - |
51 |
| -Furthermore, the template should not be required to be followed. However it is strongly recommended to |
52 |
| -maintain some sense of consistency between proposals. |
53 |
| - |
| 22 | +### `shared_history` property in `m.room_key` events |
| 23 | + |
| 24 | +Suppose Alice and Bob are participating in an encrypted room, and Bob now |
| 25 | +wishes to invite Charlie to join the chat. If the [history |
| 26 | +visibility](https://spec.matrix.org/v1.14/client-server-api/#room-history-visibility) |
| 27 | +settings allow, Bob can share the message decryption keys for previously sent |
| 28 | +messages with Charlie. However, it is dangerous for Bob to take the server's |
| 29 | +word for the history visibility setting: a malicious server admin collaborating |
| 30 | +with Charlie could tell Bob that the history visibility was open when in fact |
| 31 | +it was restricted. In addition, the history visibility in a given room may have |
| 32 | +been changed over time and it can be difficult for clients to estalish which |
| 33 | +setting was in force for a particular Megolm session. |
| 34 | + |
| 35 | +To counter this, we add a `shared_history` property to `m.room_key` messages, |
| 36 | +indicating that the creator of that Megolm session understands and agrees that |
| 37 | +the session keys may be shared with newly-invited users in future. For example: |
| 38 | + |
| 39 | +```json |
| 40 | +{ |
| 41 | + "type": "m.room_key", |
| 42 | + "content": { |
| 43 | + "algorithm": "m.megolm.v1.aes-sha2", |
| 44 | + "room_id": "!room_id", |
| 45 | + "session_id": "session_id", |
| 46 | + "session_key": "session_key", |
| 47 | + "shared_history": true |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +In other words: when Alice wants to send a message in the room she shares with |
| 53 | +Bob, she first checks the `history_visibility`. If it is `shared` or |
| 54 | +`world_readable`, then when she sends the Megolm keys to Bob, she sets |
| 55 | +`shared_history` to `true`. |
| 56 | + |
| 57 | +Clients SHOULD show a visual indication to users that their encrypted messages |
| 58 | +may be shared with future room members in this way. |
| 59 | + |
| 60 | +If the history visibility changes in a way that would affect the |
| 61 | +`shared_history` flag (i.e., it changes from `joined` or `invited` to `shared` |
| 62 | +or `world_readable`, or vice versa), then clients MUST rotate their outbound |
| 63 | +megolm session before sending more messages. |
| 64 | + |
| 65 | +In addition, a `shared_history` property is added to the [`BackedUpSessionData` |
| 66 | +type](https://spec.matrix.org/v1.14/client-server-api/#definition-backedupsessiondata) |
| 67 | +in key backups (that is, the plaintext object that gets encrypted into the |
| 68 | +`session_data` field) and the [`ExportedSessionData` |
| 69 | +type](https://spec.matrix.org/v1.14/client-server-api/#definition-exportedsessiondata). In |
| 70 | +both cases, the new property is set to `true` if the session was shared with us |
| 71 | +with `shared_history: true`, and `false` otherwise. |
| 72 | + |
| 73 | +For example: |
| 74 | + |
| 75 | +```json |
| 76 | +{ |
| 77 | + "algorithm": "m.megolm.v1.aes-sha2", |
| 78 | + "forwarding_curve25519_key_chain": [ |
| 79 | + "hPQNcabIABgGnx3/ACv/jmMmiQHoeFfuLB17tzWp6Hw" |
| 80 | + ], |
| 81 | + "sender_claimed_keys": { |
| 82 | + "ed25519": "aj40p+aw64yPIdsxoog8jhPu9i7l7NcFRecuOQblE3Y" |
| 83 | + }, |
| 84 | + "sender_key": "RF3s+E7RkTQTGF2d8Deol0FkQvgII2aJDf3/Jp5mxVU", |
| 85 | + "session_key": "AgAAAADxKHa9uFxcXzwYoNueL5Xqi69IkD4sni8Llf...", |
| 86 | + "shared_history": true |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +In all cases, an absent or non-boolean `shared_history` property is treated the same as |
| 91 | +`shared_history: false`. |
| 92 | + |
| 93 | + |
| 94 | +### Key bundle format |
| 95 | + |
| 96 | +TODO |
| 97 | + |
| 98 | +### To-device message format |
54 | 99 |
|
55 | 100 | ## Potential issues
|
56 | 101 |
|
|
0 commit comments