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

Clarify that arbitrary unicode is allowed in user/room IDs and room aliases #1506

Merged
merged 9 commits into from
Jan 22, 2025
1 change: 1 addition & 0 deletions changelogs/appendices/newsfragments/1506.clarification
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clarify that arbitrary unicode is allowed in user/room IDs and room aliases.
Copy link
Member

Choose a reason for hiding this comment

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

Strongly disagree on this.

The original vintage 2014 Synapse implementation only allowed non URL quotable characters in user localparts when registering for an account. Unfortunately, federation did not apply the same check, alluded to by other comments here:

Arbitrary unicode ids exist in the wild too, but it has never been possible to create them without modifying the server.

If you are playing silly games (removing validation checks on your server) we should NOT set the precedent that we are just going to accept your games imo, otherwise where do you draw the line? Some comments in this proposal mention about excluding the null byte, but why? Sure, postgres cannot represent it when used with TEXT columns, but hey I am using a modified Synapse which doesn't have this problem, so why are we allowing some silly games but not others?

The result is an inconsistent mess, and it was never designed to be that way. This isn't like other cases where "hey this is what synapse does, in the spec it goes" because in order to get the failure mode of unicode characters you need a malicious and/or buggy actor.

The consequences of making this the rule in the specification, and hence removing these checks in Dendrite, Conduit, et al is an increased risk of homograph attacks. I cannot and will not support increasing the attack surface of Matrix just because a few people back in 2014 removed validation and sent unicode user IDs into a room, which synapse accepted.

It is worth emphasising that room versions ARE NOT a get-out-of-jail-free card here, as user IDs are outside the scope of rooms. For example, the sliding sync proxy recently had an issue with unicode user IDs in device list changes. It's not hard to see how this can also be an issue with the user directory and to-device msgs, both of which sit outside of rooms.

Counter proposal: sorry folks with smiley poos as user localparts, you're going to be broken in the next release of Synapse, and we remove / subsequently ignore events with malformed user IDs aka what we should have done in 2014.

Copy link
Contributor

Choose a reason for hiding this comment

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

While I agree that this only really happens because of people modifying their servers, the result of enforcing those checks in one implementation and not in another can end up being outright disastrous for innocent users.

For example, if Dendrite enforces these checks but Synapse doesn't, then all it takes is for a Synapse user with an emoji localpart to make a power level change or perform any kind of power action to break the room for Dendrite users probably irreversibly.

Hell, they might not even have to perform a power action, because we might drop auth events (such as the user joining to begin with) or refuse to pull in prev events (from normal timeline events), which in turn causes us to run state resolution with a different set of input events (which can result in a different output state set or a complete state reset) or to accidentally propagate broken state to other servers when they ask us for /state_ids or /state.

This situation 100% sucks but Matrix only functions if implementations agree to handle these things in the same way, otherwise different implementations will never arrive at a consistent state. We already see this happen due to other corner cases and it just ends up feeling terrible for all users involved.

As for room versions, it is true that it's not a great solution to the problem due to the fact that it still leaks into device updates or other areas, but at least it's possible in a future room version to make sure that users with invalid localparts can't join the rooms to begin with. That is a huge step towards stamping out invalid localparts.

18 changes: 16 additions & 2 deletions content/appendices.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,13 @@ character set:

extended_user_id_char = %x21-39 / %x3B-7E ; all ASCII printing chars except :

##### User IDs over federation

Due to a lack of validation in original Matrix homeserver implementations,
the localpart of user IDs over federation may contain any valid unicode
codepoints except `:`. A future spec change may create a new room version
to disallow such user IDs.
richvdh marked this conversation as resolved.
Show resolved Hide resolved

##### Mapping from other character sets

In certain circumstances it will be desirable to map from a wider
Expand Down Expand Up @@ -645,6 +652,10 @@ Room IDs are case-sensitive. They are not meant to be
human-readable. They are intended to be treated as fully opaque strings
by clients.

The localpart of a room ID (`opaque_id` above) may contain any valid
unicode codepoints except `:`, but it is recommended to only include
tulir marked this conversation as resolved.
Show resolved Hide resolved
ASCII letters and digits when generating them.
tulir marked this conversation as resolved.
Show resolved Hide resolved

#### Room Aliases

A room may have zero or more aliases. A room alias has the format:
Expand All @@ -655,8 +666,11 @@ The `domain` of a room alias is the [server name](#server-name) of the
homeserver which created the alias. Other servers may contact this
homeserver to look up the alias.

Room aliases MUST NOT exceed 255 bytes (including the `#` sigil and the
domain).
The localpart of a room alias may contain any valid unicode codepoints
except `:`.
tulir marked this conversation as resolved.
Show resolved Hide resolved

Room aliases MUST NOT exceed 255 bytes as UTF-8 (including the `#` sigil
and the domain).
richvdh marked this conversation as resolved.
Show resolved Hide resolved

#### Event IDs

Expand Down