@@ -17,6 +17,11 @@ Currently, access to media in Matrix has the following problems:
17
17
* If a user requests GDPR erasure, their media remains visible to all.
18
18
* When all users leave a room, their media is not deleted from the server.
19
19
20
+ This proposal builds on
21
+ [ MSC3916] ( https://github.com/matrix-org/matrix-spec-proposals/pull/3916 ) (which
22
+ adds authentication to media download), to require that the authenticated
23
+ user is * authorised* to access the requested media.
24
+
20
25
## Proposal
21
26
22
27
### Overview
@@ -72,81 +77,49 @@ to a user if the user can see the corresponding event.
72
77
(say, ten minutes), then the server is free to assume that the user has changed their
73
78
mind (or the client has gone offline), and may clean up the uploaded media.
74
79
75
- 4 . New download endpoints
76
-
77
- The existing download endpoints are to be deprecated, and replaced with new
78
- endpoints specific to client-server or federation requests:
79
-
80
- | Old | Client-Server | Federation |
81
- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------- |
82
- | [ ` GET /_matrix/media/v3/download/{serverName}/{mediaId} ` ] ( https://spec.matrix.org/v1.4/client-server-api/#get_matrixmediav3downloadservernamemediaid ) | ` GET /_matrix/client/v1/media/download/{serverName}/{mediaId} ` | ` GET /_matrix/federation/v1/media/download/{serverName}/{mediaId} ` |
83
- | [ ` GET /_matrix/media/v3/download/{serverName}/{mediaId}/{fileName} ` ] ( https://spec.matrix.org/v1.4/client-server-api/#get_matrixmediav3downloadservernamemediaid ) | ` GET /_matrix/client/v1/media/download/{serverName}/{mediaId}/{fileName} ` | N/A |
84
- | [ ` GET /_matrix/media/v3/thumbnail/{serverName}/{mediaId} ` ] ( https://spec.matrix.org/v1.4/client-server-api/#get_matrixmediav3thumbnailservernamemediaid ) | ` GET /_matrix/client/v1/media/thumbnail/{serverName}/{mediaId} ` | ` GET /_matrix/federation/v1/media/thumbnail/{serverName}/{mediaId} ` |
85
-
86
- [ TODO: we should probably move ` /config ` , and ` /preview_url ` while
87
- we're at it]
88
-
89
- None of the new endpoints take an ` allow_remote ` query parameter. (For
90
- ` /_matrix/client ` , servers should always attempt to request remote
91
- media. For ` /_matrix/federation ` , servers should never attempt to request
92
- remote media they do not already have cached.)
93
-
94
- All of the new endpoints require an ` Authorization ` header, which must be
95
- set in the same way as for any other CSAPI or federation request (ie,
96
- ` Bearer {accessToken} ` for ` /_matrix/client ` , or the signature for
97
- ` /_matrix/federation ` ).
80
+ 3 . Federation API returns a ` restrictions ` property
98
81
99
- When handling a request to the new endpoints, the server must check if the
100
- requesting user or server has permission to see the corresponding event.
101
- If not, the server responds with a 403 error and ` M_UNAUTHORIZED ` .
82
+ The ` /_matrix/federation/v1/media/download ` and ` /_matrix/federation/v1/media/thumbnail `
83
+ endpoints specified by [ MSC3916 ] ( https://github.com/matrix-org/matrix-spec-proposals/pull/3916 )
84
+ are extended: the returned json object may have a property ` restrictions ` .
102
85
103
- * For the new ` /_matrix/client ` endpoints, the response format is the same as
104
- the corresponding original endpoints.
86
+ If there is no ` restrictions ` property, the media is a legacy "unrestricted"
87
+ media. Otherwise, ` restrictions ` should be a JSON object with one
88
+ of the following properties:
105
89
106
- * For the new ` /_matrix/federation ` endpoints, the response is
107
- [ ` multipart/mixed ` ] ( https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html )
108
- content with two parts: the first must be a JSON object
109
- (and should have a ` Content-type: application/json ` header), and the second
110
- is the media item as per the original endpoints. The json object may have
111
- a property ` restrictions ` .
90
+ * ` event_id ` : the event id of the event to which the media is attached.
91
+ * ` profile_user_id ` : the user id of the user to whose profile the media is attached.
112
92
113
- If there is no ` restrictions ` property, the media is a legacy "unrestricted"
114
- media. Otherwise, ` restrictions ` should be a JSON object with one
115
- of the following properties:
93
+ It is invalid for both ` event_id ` and ` profile_user_id ` to be set.
116
94
117
- * ` event_id ` : the event id of the event to which the media is attached.
118
- * ` profile_user_id ` : the user id of the user to whose profile the media is attached.
95
+ The requesting server must check the restrictions list, and only return
96
+ the requested media to users who have permission to view the relevant
97
+ event or profile. If the requesting server caches the media, it must also
98
+ cache the restrictions list.
119
99
120
- It is invalid for both ` event_id ` and ` profile_user_id ` to be set.
100
+ If neither ` event_id ` nor ` profile_user_id ` are present, the requesting
101
+ user should assume that an unknown restriction is present, and not allow access
102
+ to any user.
121
103
122
- The requesting server must check the restrictions list, and only return
123
- the requested media to users who have permission to view the relevant
124
- event or profile. If the requesting server caches the media, it must also
125
- cache the restrictions list.
104
+ An example response:
126
105
127
- If neither ` event_id ` nor ` profile_user_id ` are present, the requesting
128
- user should assume that an unknown restriction is present, and not allow access
129
- to any user.
106
+ ```
107
+ Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08jU534c0p
130
108
131
- An example response:
109
+ --gc0p4Jq0M2Yt08jU534c0p
110
+ Content-Type: application/json
132
111
133
- ```
134
- Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08jU534c0p
112
+ { "restrictions": {
113
+ "event_id": "$Rqnc-F-dvnEYJTyHq_iKxU2bZ1CI92-kuZq3a5lr5Zg"
114
+ }}
135
115
136
- --gc0p4Jq0M2Yt08jU534c0p
137
- Content-Type: application/json
116
+ --gc0p4Jq0M2Yt08jU534c0p
117
+ Content-Type: text/plain
138
118
139
- { "restrictions": {
140
- "event_id": "$Rqnc-F-dvnEYJTyHq_iKxU2bZ1CI92-kuZq3a5lr5Zg"
141
- }}
119
+ This media is plain text. Maybe somebody used it as a paste bin.
142
120
143
- --gc0p4Jq0M2Yt08jU534c0p
144
- Content-Type: text/plain
145
-
146
- This media is plain text. Maybe somebody used it as a paste bin.
147
-
148
- --gc0p4Jq0M2Yt08jU534c0p
149
- ```
121
+ --gc0p4Jq0M2Yt08jU534c0p
122
+ ```
150
123
151
124
4 . New "media copy" API
152
125
@@ -177,14 +150,9 @@ to a user if the user can see the corresponding event.
177
150
178
151
5 . Backwards compatibility mechanisms
179
152
180
- a. Backwards compatibility with older servers: if a client or requesting
181
- server receives a 404 error with a non-JSON response, or a 400 error with
182
- `{"errcode": "M_UNRECOGNIZED"}`, in response to a request to one of the new
183
- endpoints, they may retry the request using the original endpoint.
184
-
185
- b. Backwards compatibility with older clients and federating servers:
153
+ For backwards compatibility with older clients and requesting servers:
186
154
servers may for a short time choose to allow unauthenticated access via the
187
- deprecated endpoints, even for restricted media.
155
+ deprecated ` /_matrix/media/v3 ` endpoints, even for restricted media.
188
156
189
157
6 . URL preview
190
158
@@ -206,41 +174,28 @@ implementations, and how the proposal will facilitate future extensions.
206
174
207
175
#### IRC/XMPP bridges
208
176
209
- Possibly the largest impact will be on IRC and XMPP bridges. Since IRC and
210
- XMPP have no media repository of their own, these bridges currently transform
211
- `mxc:` URIs into `https://<server>/_matrix/media/v3/download/` URIs and forward
212
- those links to the remote platform. This will no longer be a viable option.
213
-
214
- This is largely a problem to be solved by the bridge implementations, but one
215
- potential solution is for the bridges to provide a proxy.
177
+ These bridges have previously been discussed in [ MSC3916] ( https://github.com/matrix-org/matrix-spec-proposals/pull/3916 ) , however this proposal adds a new problem.
216
178
217
- In this scenario, the bridge would have a secret HMAC key. When it
218
- receives a matrix event referencing a piece of media, it should create a new URI
219
- referencing the media, include an HMAC to prevent tampering. For example:
179
+ These bridges currently use the content repository as a paste-bin: large text
180
+ messages are uploaded as plain-text media, and a link is then sent to the
181
+ remote network. This will become problematic, because servers are entitled
182
+ to remove any media that does not get linked to an event.
220
183
221
- ```
222
- https://<bridge_server>/media/{originServerName}/{mediaId}?mac={hmac}
223
- ```
184
+ Solutions might include:
185
+ * the bridge hosting its own content repository for this usecase
186
+ * using an external service
187
+ * special-casing the bridge AS user to permit it to upload media without
188
+ expiry.
224
189
225
- When the bridge later receives a request to that URI, it checks the hmac,
226
- and proxies the request to the homeserver, using its AS access
227
- token in the `Authorization` header.
228
-
229
- This mechanism also works for a secondary use of the content repository in
230
- bridges: as a paste-bin. In this case, the bridge simply generates a link
231
- referencing its own media.
232
-
233
- The bridge might also choose to embed information such as the room that
234
- referenced the media, and the time that the link was generated, in the URL.
235
- This could be used to help control access to the media.
236
-
237
- Such mechanisms would allow the bridge to impose controls such as:
190
+ #### Icons for "social login" flows
238
191
239
- * Limiting the time a media link is valid for. Doing so would help prevent
240
- visibility to users who weren't participating in the chat .
192
+ These likewise were previously discussed in
193
+ [ MSC3916 ] ( https://github.com/matrix-org/matrix-spec-proposals/pull/3916 ) .
241
194
242
- * Rate-limiting the amount of media being shared in a particular room (in other
243
- words, avoiding the use of Matrix as a Warez distribution system).
195
+ We need to ensure that the icons are not deleted from the content
196
+ repository even though they have not been attached to any event or profile. It
197
+ would be wise for servers to provide administrators with a mechanism to upload
198
+ media without attaching it to anything.
244
199
245
200
#### Redacting events
246
201
@@ -257,60 +212,18 @@ extend to deleting the media.
257
212
258
213
Fixes [ synapse #1263 ] ( https://github.com/matrix-org/synapse/issues/1263 ) .
259
214
260
- #### Icons for "social login" flows
261
-
262
- When a server supports multiple login providers, it provides the client with
263
- icons for the login providers as `mxc:` media URIs. These must be accessible
264
- without authentication (because the client has no access token at the time the
265
- icons are displayed).
266
-
267
- This remains a somewhat unsolved problem. Possibly the clients can continue
268
- to call the legacy `/_matrix/media/v3/download` URI for now: ultimately this
269
- problem will be solved by the transition to OIDC. Alternatively, we may need
270
- to provide an alternative `/_matrix/client/v3/login/sso/icon/{idpId}` API
271
- specifically for access to these icon.
272
-
273
- We also need to ensure that the icons are not deleted from the content
274
- repository even though they have not been attached to any event or profile. It
275
- would be wise for servers to provide administrators with a mechanism to upload
276
- media without attaching it to anything.
277
-
278
- (This was previously discussed in
279
- [MSC2858](https://github.com/matrix-org/matrix-spec-proposals/pull/2858#discussion_r543513811).)
280
-
281
215
## Potential issues
282
216
283
- * Setting the `Authorization` header is going to be annoying for web clients. Service workers
284
- might be needed.
285
-
286
- * Users will be unable to copy links to media from web clients to share out of
287
- band. This is considered a feature, not a bug.
288
-
289
217
* Since each ` m.room.member ` references the avatar separately, changing your
290
218
avatar will cause an even bigger traffic storm if you're in a lot of rooms.
291
219
292
220
## Alternatives
293
221
294
- * Allow clients to upload media which does not require authentication (for
295
- example via a `public=true` query parameter). This might be particularly
296
- useful for IRC/XMPP bridges, which could upload any media they encounter to
297
- the homeserver's repository.
298
-
299
- The danger with this is that is that there's little stopping clients
300
- continuing to upload media as "public", negating all of the benefits in this
301
- MSC. It might be ok if media upload it was restricted to certain privileged
302
- users.
303
-
304
222
* Have the "upload" endpoint return a nonce, which can then be used in the
305
223
"send" endpoint in place of the ` mxc ` uri. It's hard to see what advantage
306
224
this gives, beyond the fact a nonce could be smaller so marginally fewer
307
225
bytes to send.
308
226
309
- * Rather than messing with multiplart content, have a separate endpoint for
310
- servers to get the access controls for a media item. That would mean two
311
- requests, but might make more sense than both `/thumbnail` and `/download`
312
- providing the info.
313
-
314
227
* Use some sort of "content token" for each piece of media, and require clients to
315
228
provide it, per [ MSC3910] ( https://github.com/matrix-org/matrix-spec-proposals/pull/3910 ) .
316
229
@@ -325,11 +238,11 @@ TODO
325
238
326
239
## Dependencies
327
240
328
- None at present .
241
+ [ MSC3916 ] ( https://github.com/matrix-org/matrix-spec-proposals/issues/3916 ) "Authentication for media access, and new endpoint names" .
329
242
330
243
## Prior art
331
244
332
- * Credit: this is based on ideas from @jcgruenhage and @anoadragon453 at
245
+ * Credit: this proposal is based on ideas from @jcgruenhage and @anoadragon453 at
333
246
https://cryptpad.fr/code/#/2/code/view/oWjZciD9N1aWTr1IL6GRZ0k1i+dm7wJQ7juLf4tJRoo/
334
247
335
248
* [ MSC~~ 701~~ 3796] ( https://github.com/matrix-org/matrix-spec-proposals/issues/3796 ) :
0 commit comments