Skip to content

Commit f8da206

Browse files
MadLittleModsanoadragon453richvdh
authored
MSC3905: Application services should only be interested in local users (#3905)
* MSC so appservices only interested in local users Fix matrix-org/matrix-spec#1272 * Add MSC number * Fix typo * Fix title * Add example implementation See #3905 (comment) * `rooms` and `aliases` not affected See #3905 (comment) * Add historical context See #3905 (comment) * Document how to do unstable See #3905 (comment) * fix some typos * Add link to spec Co-authored-by: Richard van der Hoff <[email protected]> Co-authored-by: Andrew Morgan <[email protected]> Co-authored-by: Richard van der Hoff <[email protected]>
1 parent 1676be3 commit f8da206

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# MSC3905: Application services should only be interested in local users
2+
3+
Application services receive events that they are "interested" in.
4+
5+
The [current language in the spec](https://spec.matrix.org/v1.4/application-service-api/#registration)
6+
describes it like this:
7+
8+
> An application service is said to be "interested" in a given event if one of the IDs
9+
> in the event match the regular expression provided by the application service
10+
> [registration]. [...] the application service is said to be interested in a given
11+
> event if one of the application service's namespaced users is the target of the event,
12+
> or is a joined member of the room where the event occurred.
13+
14+
This language is ambiguous around which users it should match against though. Should it
15+
be all members of the room including remote users from other homeservers or just the
16+
local users where the application service lives? It could be assumed either way and
17+
naively applied to all members of the room which is still valid with the current
18+
language and even what Synapse does.
19+
20+
But matching against remote users is merely a footgun because an application service may
21+
assume that it'll receive all events sent by that remote user, even though it will only
22+
receive events in rooms that are shared with a local user. This leaves us with a
23+
behavior mismatch between remote and local users.
24+
25+
26+
## Proposal
27+
28+
Therefore the proposal is that the `users` namespace regex should only be applied
29+
against local users of the homeserver.
30+
31+
A basic implementation of this would look like:
32+
33+
```js
34+
const isLocalUser = sender.endsWith(":" + homeserver.domain);
35+
const isInterestingUser = isLocalUser && sender.matches(regex);
36+
```
37+
38+
```js
39+
const localRoomMembers = getLocalRoomMembers(roomId);
40+
const interestingUsers = localRoomMembers.filter((localRoomMember) => localRoomMember.matches(regex));
41+
```
42+
43+
---
44+
45+
To avoid confusion, please note that the `rooms` and `aliases` namespaces are not
46+
affected. You can still match whatever rooms and aliases to listen to all events
47+
that occur in them.
48+
49+
50+
## Potential issues
51+
52+
There are use cases like moderation where an application service wants to hear all
53+
messages from remote users in rooms but these are also covered by the `rooms`
54+
namespace where all events in a matched room are considered "interesting".
55+
56+
57+
58+
## Alternatives
59+
60+
The alternative is to clarify that the `users` namespace should be matched against all
61+
users (local and remote). This still leaves us with the behavior-difference footgun.
62+
63+
64+
65+
## Security considerations
66+
67+
Since we're reducing the surface area, there doesn't seem to be any additional security
68+
considerations introduced.
69+
70+
With this MSC, an application service will be receiving less events than before.
71+
72+
73+
## Historical context
74+
75+
According to @turt2live (SCT member), "the spec intended to [originally] say the
76+
namespace can make an appservice interested in remote users, though there's obviously no
77+
ability for the server to call `/user` on remote users (it's not like the appservice can
78+
create them)." (https://github.com/matrix-org/synapse/pull/13958#discussion_r988369446)
79+
80+
This intention goes back further than `r0` (or `v1.0` in marketing versions speak) but
81+
this history is lost to time since there isn't really anything concrete to point to
82+
beyond the original spec
83+
[issue](https://github.com/matrix-org/matrix-spec-proposals/issues/1307) and
84+
[PR](https://github.com/matrix-org/matrix-spec-proposals/pull/1533) which don't mention
85+
these details.
86+
87+
Since we're unable to come up with any valid use cases nowadays, it's unclear to
88+
outsiders from that time whether the original intention is actually true. In any case,
89+
we're clarifying it here and making an MSC to change it explicitly.
90+
91+
92+
## Unstable prefix
93+
94+
While this MSC is not considered stable, appservices can opt-in to this behaviour in
95+
either of two ways:
96+
97+
1. Specifying a regex which includes the local homeserver's domain in the regex (eg:
98+
`@_irc.*:example.org`)
99+
1. Adding `"org.matrix.msc3905": true` to the root level of their registration file

0 commit comments

Comments
 (0)