@@ -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
@@ -40,7 +45,7 @@ to a user if the user can see the corresponding event.
40
45
41
46
* The methods for sending events
42
47
([ ` PUT /_matrix/client/v3/rooms/{roomId}/state/{eventType}/{stateKey} ` ] ( https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3roomsroomidstateeventtypestatekey )
43
- and [ ` PUT /_matrix/client/v3/rooms/{roomId}/state /{eventType}/{stateKey } ` ] ( https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3roomsroomidsendeventtypetxnid ) )
48
+ and [ ` PUT /_matrix/client/v3/rooms/{roomId}/send /{eventType}/{txnId } ` ] ( https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3roomsroomidsendeventtypetxnid ) )
44
49
are extended to take a query parameter ` attach_media ` , whose value must be a complete ` mxc: ` URI.
45
50
46
51
The ` attach_media ` parameter may be used several times to attach several
@@ -72,83 +77,59 @@ 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 . Additional checks on ` /download ` and ` /thumbnail ` endpoints
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 new ` /download ` and ` /thumbnail ` endpoints added in
83
+ [ MSC3916] ( https://github.com/matrix-org/matrix-spec-proposals/pull/3916 ) are
84
+ updated the server must check if the requesting user or server has
85
+ permission to see the corresponding event. If not, the server responds with
86
+ a 403 error and ` M_UNAUTHORIZED ` .
102
87
103
- * For the new ` /_matrix/client ` endpoints, the response format is the same as
104
- the corresponding original endpoints.
88
+ 4 . Federation API returns a ` restrictions ` property
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
+ The ` /_matrix/federation/v1/media/download ` and ` /_matrix/federation/v1/media/thumbnail `
91
+ endpoints specified by [ MSC3916] ( https://github.com/matrix-org/matrix-spec-proposals/pull/3916 )
92
+ are extended: the returned json object may have a property ` restrictions ` .
112
93
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:
94
+ If there is no ` restrictions ` property, the media is a legacy "unrestricted"
95
+ media. Otherwise, ` restrictions ` should be a JSON object with one
96
+ of the following properties:
116
97
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.
98
+ * ` event_id ` : the event id of the event to which the media is attached.
99
+ * ` profile_user_id ` : the user id of the user to whose profile the media is attached.
119
100
120
- It is invalid for both ` event_id ` and ` profile_user_id ` to be set.
101
+ It is invalid for both ` event_id ` and ` profile_user_id ` to be set.
121
102
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.
103
+ The requesting server must check the restrictions list, and only return
104
+ the requested media to users who have permission to view the relevant
105
+ event or profile. If the requesting server caches the media, it must also
106
+ cache the restrictions list.
126
107
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.
108
+ If neither ` event_id ` nor ` profile_user_id ` are present, the requesting
109
+ user should assume that an unknown restriction is present, and not allow access
110
+ to any user.
130
111
131
- An example response:
112
+ An example response:
132
113
133
- ```
134
- Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08jU534c0p
114
+ ```
115
+ Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08jU534c0p
135
116
136
- --gc0p4Jq0M2Yt08jU534c0p
137
- Content-Type: application/json
117
+ --gc0p4Jq0M2Yt08jU534c0p
118
+ Content-Type: application/json
138
119
139
- { "restrictions": {
140
- "event_id": "$Rqnc-F-dvnEYJTyHq_iKxU2bZ1CI92-kuZq3a5lr5Zg"
141
- }}
120
+ { "restrictions": {
121
+ "event_id": "$Rqnc-F-dvnEYJTyHq_iKxU2bZ1CI92-kuZq3a5lr5Zg"
122
+ }}
142
123
143
- --gc0p4Jq0M2Yt08jU534c0p
144
- Content-Type: text/plain
124
+ --gc0p4Jq0M2Yt08jU534c0p
125
+ Content-Type: text/plain
145
126
146
- This media is plain text. Maybe somebody used it as a paste bin.
127
+ This media is plain text. Maybe somebody used it as a paste bin.
147
128
148
- --gc0p4Jq0M2Yt08jU534c0p
149
- ```
129
+ --gc0p4Jq0M2Yt08jU534c0p
130
+ ```
150
131
151
- 4 . New "media copy" API
132
+ 5 . New "media copy" API
152
133
153
134
A new endpoint is defined: `POST
154
135
/_ matrix/client/v1/media/copy/{serverName}/{mediaId}`. The body of the
@@ -175,18 +156,13 @@ to a user if the user can see the corresponding event.
175
156
Such events must each use a different copy of the media item, in the same
176
157
way as the "media copy" API described above.
177
158
178
- 5 . Backwards compatibility mechanisms
159
+ 6 . Backwards compatibility mechanisms
179
160
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:
161
+ For backwards compatibility with older clients and requesting servers:
186
162
servers may for a short time choose to allow unauthenticated access via the
187
- deprecated endpoints, even for restricted media.
163
+ deprecated ` /_matrix/media/v3 ` endpoints, even for restricted media.
188
164
189
- 6 . URL preview
165
+ 7 . URL preview
190
166
191
167
The
192
168
[ ` /preview_url ` ] ( https://spec.matrix.org/v1.4/client-server-api/#get_matrixmediav3preview_url )
@@ -206,41 +182,28 @@ implementations, and how the proposal will facilitate future extensions.
206
182
207
183
#### IRC/XMPP bridges
208
184
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.
216
-
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:
185
+ 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.
220
186
221
- ```
222
- https://<bridge_server>/media/{originServerName}/{mediaId}?mac={hmac}
223
- ```
187
+ These bridges currently use the content repository as a paste-bin: large text
188
+ messages are uploaded as plain-text media, and a link is then sent to the
189
+ remote network. This will become problematic, because servers are entitled
190
+ to remove any media that does not get linked to an event.
224
191
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.
192
+ Solutions might include:
193
+ * the bridge hosting its own content repository for this usecase
194
+ * using an external service
195
+ * special-casing the bridge AS user to permit it to upload media without
196
+ expiry.
228
197
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:
198
+ #### Icons for "social login" flows
238
199
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 .
200
+ These likewise were previously discussed in
201
+ [ MSC3916 ] ( https://github.com/matrix-org/matrix-spec-proposals/pull/3916 ) .
241
202
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).
203
+ We need to ensure that the icons are not deleted from the content
204
+ repository even though they have not been attached to any event or profile. It
205
+ would be wise for servers to provide administrators with a mechanism to upload
206
+ media without attaching it to anything.
244
207
245
208
#### Redacting events
246
209
@@ -257,60 +220,18 @@ extend to deleting the media.
257
220
258
221
Fixes [ synapse #1263 ] ( https://github.com/matrix-org/synapse/issues/1263 ) .
259
222
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
223
## Potential issues
282
224
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
225
* Since each ` m.room.member ` references the avatar separately, changing your
290
226
avatar will cause an even bigger traffic storm if you're in a lot of rooms.
291
227
292
228
## Alternatives
293
229
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
230
* Have the "upload" endpoint return a nonce, which can then be used in the
305
231
"send" endpoint in place of the ` mxc ` uri. It's hard to see what advantage
306
232
this gives, beyond the fact a nonce could be smaller so marginally fewer
307
233
bytes to send.
308
234
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
235
* Use some sort of "content token" for each piece of media, and require clients to
315
236
provide it, per [ MSC3910] ( https://github.com/matrix-org/matrix-spec-proposals/pull/3910 ) .
316
237
@@ -325,11 +246,11 @@ TODO
325
246
326
247
## Dependencies
327
248
328
- None at present .
249
+ [ MSC3916 ] ( https://github.com/matrix-org/matrix-spec-proposals/issues/3916 ) "Authentication for media access, and new endpoint names" .
329
250
330
251
## Prior art
331
252
332
- * Credit: this is based on ideas from @jcgruenhage and @anoadragon453 at
253
+ * Credit: this proposal is based on ideas from @jcgruenhage and @anoadragon453 at
333
254
https://cryptpad.fr/code/#/2/code/view/oWjZciD9N1aWTr1IL6GRZ0k1i+dm7wJQ7juLf4tJRoo/
334
255
335
256
* [ MSC~~ 701~~ 3796] ( https://github.com/matrix-org/matrix-spec-proposals/issues/3796 ) :
0 commit comments