Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSC2676: Message editing #2676

Merged
merged 28 commits into from
Jul 18, 2022
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8b95ffc
initial version of message editing proposal
uhoreg Jul 7, 2020
7f42c8b
fix MSC numbers
uhoreg Jul 7, 2020
5473009
Fix JSON in example
uhoreg Nov 24, 2020
e44f566
clarifications
uhoreg Jun 2, 2021
634dc2e
remove obsolete "XXX:", and fix a typo
uhoreg Oct 28, 2021
f9768e7
Initial cleanup and restructuring
richvdh Apr 12, 2022
1de6c11
Clarify algorithm for replacing content
richvdh Apr 12, 2022
adcdddc
background
richvdh Apr 12, 2022
fc2a690
More clarifications on applying edits
richvdh Apr 12, 2022
80c467b
Clarify behaviour of redactions
richvdh Apr 12, 2022
6cea76a
Minor grammar fixes
richvdh May 17, 2022
dac2399
Move the section on `msgtype` down
richvdh May 17, 2022
b8a7745
Clarify how edits are ordered
richvdh May 17, 2022
79a362e
Spec the behaviour for encrypted events
richvdh May 17, 2022
bb96694
Requirements for an edit event to be considered valid
richvdh May 17, 2022
dd1ca71
Collect "client behaviour" and "sever behaviour" together
richvdh May 17, 2022
eba4753
Clarify permalinks section
richvdh May 17, 2022
78550a2
Notes on edits of replies
richvdh May 17, 2022
e58715c
Clarify that `m.relates_to` within `m.new_content` is ignored
richvdh May 19, 2022
4c77c01
Clarifications from review
richvdh Jun 28, 2022
1850fb5
event ids are sorted lexicographically
richvdh Jun 28, 2022
c9e6652
Clarify aggregation section
richvdh Jun 28, 2022
1e63094
minor clarifications
richvdh Jul 12, 2022
2373873
Clarify which endpoints support edits
richvdh Jul 12, 2022
8ec4cf3
move definition of latest edit
richvdh Jul 12, 2022
08489e8
Apply suggestions from code review
richvdh Jul 13, 2022
f3d328d
fix typo
richvdh Jul 13, 2022
b245761
Attempt to clarify encrypted events
richvdh Jul 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Spec the behaviour for encrypted events
  • Loading branch information
richvdh committed May 17, 2022
commit 79a362e47f2d88339371d2c7df73a6c6ed7a909c
61 changes: 56 additions & 5 deletions proposals/2676-message-editing.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ field as defined in
intended primarily for handling edits, and lets you define an event which
replaces an existing event.

The replacement event must contain a `m.new_content` property which defines the
replacement content. (This allows the normal `body` fields to be used for a
fallback for clients who do not understand replacement events.)
Such an event, with `rel_type: m.replace`, is referred to as a "message edit event".

### `m.new_content` property

The `content` of a message edit event must contain a `m.new_content` property
which defines the replacement content. (This allows the normal `body` fields to
be used for a fallback for clients who do not understand replacement events.)

For instance, an `m.room.message` which replaces an existing event might look like:

Expand All @@ -78,11 +82,56 @@ For instance, an `m.room.message` which replaces an existing event might look li
}
```

Such an event, with `rel_type: m.replace`, is referred to as a "message edit".

The `m.new_content` can include any properties that would normally be found in
an event's `content` property, such as `formatted_body`.

#### Encrypted events

If the original event was encrypted, the replacement should be too. In that
case, `m.new_content` is placed in the `content` of the encrypted payload. For
example, an encrypted replacement event might look like this:

```json
{
"type": "m.room.encrypted",
"content": {
"m.relates_to": {
"rel_type": "m.replace",
"event_id": "$some_event_id"
},
"algorithm": "m.megolm.v1.aes-sha2",
"sender_key": "<sender_curve25519_key>",
"device_id": "<sender_device_id>",
"session_id": "<outbound_group_session_id>",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth noting that what we should encrypt with? I.e. think we encrypt with the "next" key as if it was a normal message, rather than reusing the same key as for the edit event? Not 100% sure though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You always need to use a new key. Not only for security, but if you didn't the fallback would be useless since clients relying on the fallback would mark the event as a key reuse attack.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hopefully clarified in uhoreg@1e63094.

"ciphertext": "<encrypted_payload_base_64>"
}
}
```

... and, once decrypted, the payload might look like this:


```json
{
"type": "m.room.<event_type>",
"room_id": "!some_room_id",
"content": {
"body": "* Hello! My name is bar",
"msgtype": "m.text",
"m.new_content": {
"body": "Hello! My name is bar",
"msgtype": "m.text"
},
"m.relates_to": {
"rel_type": "m.replace",
"event_id": "$some_event_id"
}
}
}
```

#### Server behaviour

Whenever a homeserver would return an event via the Client-Server API, it
should check for any applicable `m.replace` event, and if one is found, it
should first modify the `content` of the original event according to the
Expand All @@ -92,6 +141,8 @@ should first modify the `content` of the original event according to the
which should return the *unmodified* event (though the relationship should still be
"bundled", as described [below](#server-side-aggregation-of-mreplace-relationships).

#### Client behaviour

Clients are generally expected to ignore message edit events, since the server
implementation takes care of updating the content of the original
event. However, if the client has already received the original event, it must
Expand Down