Skip to content

Commit

Permalink
Add authenticated media (MSC3916) (#1858)
Browse files Browse the repository at this point in the history
* C2S: Deprecate now-legacy endpoints

* C2S: Fix MXC URI code block while we're here

* C2S: Describe the authentication and deprecation requirements

* C2S: Intro the upload/download endpoints differently

* C2S: Literally copy/paste the `content-repo.yaml` spec

* C2S: Drop `/upload` and `/create` because we aren't replacing them today

* C2S: Fix notes while we're here

* C2S: Update metadata for new endpoints

* C2S: Add authentication to new endpoints

* C2S: Drop `allow_remote` and `allow_redirect` on new endpoints

* C2S: Append backwards compatibility notes

* C2S: Decorate old media endpoints with pointers to the new ones

The server-server spec might have a harder time linking to these, but that can be fixed with verbiage.

* C2S: Annotate IdP icon spec with media auth implications

* S2S: Modernize section text

* S2S: Create content repository API

This is largely a copy/paste of the new authed content repo API in the Client-Server API, though some keywords (like "client") have been changed. Paths and response formats have also been changed to support the federation-specific requirements.

* C2S & S2S: Add plethora of changelogs

* Reference RFC 1341

* Upgrade keywords in changed text

* Mention caching

* Cross-reference IdP icons

* Update content/client-server-api/modules/content_repo.md
  • Loading branch information
turt2live authored Jun 13, 2024
1 parent 4a280bc commit 7a51ae8
Show file tree
Hide file tree
Showing 19 changed files with 967 additions and 15 deletions.
1 change: 1 addition & 0 deletions changelogs/client_server/newsfragments/1858.deprecation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use of the `/_matrix/media/*` endpoints is now deprecated. New, authenticated, endpoints are available instead.
1 change: 1 addition & 0 deletions changelogs/client_server/newsfragments/1858.feature.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Media downloads and thumbnails are now authenticated, as per [MSC3916](https://github.com/matrix-org/matrix-spec-proposals/pull/3916).
1 change: 1 addition & 0 deletions changelogs/client_server/newsfragments/1858.feature.2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some media endpoints are now consistently under `/_matrix/client/{version}/media/*` instead of `/_matrix/media/*`, as per [MSC3916](https://github.com/matrix-org/matrix-spec-proposals/pull/3916).
1 change: 1 addition & 0 deletions changelogs/client_server/newsfragments/1858.new.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[`GET /_matrix/client/v1/media/config`](/client-server-api/#get_matrixclientv1mediaconfig)
1 change: 1 addition & 0 deletions changelogs/client_server/newsfragments/1858.new.2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[`GET /_matrix/client/v1/media/download/{serverName}/{mediaId}`](/client-server-api/#get_matrixclientv1mediadownloadservernamemediaid)
1 change: 1 addition & 0 deletions changelogs/client_server/newsfragments/1858.new.3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[`GET /_matrix/client/v1/media/download/{serverName}/{mediaId}/{fileName}`](/client-server-api/#get_matrixclientv1mediadownloadservernamemediaidfilename)
1 change: 1 addition & 0 deletions changelogs/client_server/newsfragments/1858.new.4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[`GET /_matrix/client/v1/media/preview_url`](/client-server-api/#get_matrixclientv1mediapreview_url)
1 change: 1 addition & 0 deletions changelogs/client_server/newsfragments/1858.new.5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[`GET /_matrix/client/v1/media/thumbnail/{serverName}/{mediaId}`](/client-server-api/#get_matrixclientv1mediathumbnailservernamemediaid)
1 change: 1 addition & 0 deletions changelogs/server_server/newsfragments/1858.deprecation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use of the Client-Server API `/_matrix/media/*` endpoints is now deprecated. New, authenticated, endpoints are available instead.
1 change: 1 addition & 0 deletions changelogs/server_server/newsfragments/1858.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Media downloads and thumbnails are now authenticated, as per [MSC3916](https://github.com/matrix-org/matrix-spec-proposals/pull/3916).
1 change: 1 addition & 0 deletions changelogs/server_server/newsfragments/1858.new.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[`GET /_matrix/federation/v1/media/download/{mediaId}`](/server-server-api/#get_matrixfederationv1mediadownloadmediaid)
1 change: 1 addition & 0 deletions changelogs/server_server/newsfragments/1858.new.2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[`GET /_matrix/federation/v1/media/thumbnail/{mediaId}`](/server-server-api/#get_matrixfederationv1mediathumbnailmediaid)
5 changes: 2 additions & 3 deletions content/client-server-api/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ The exceptions are:
which take an empty request body.

Similarly, all endpoints require the server to return a JSON object,
with the exception of 200 responses to
[`GET /_matrix/media/v3/download/{serverName}/{mediaId}`](#get_matrixmediav3downloadservernamemediaid)
and [`GET /_matrix/media/v3/thumbnail/{serverName}/{mediaId}`](#get_matrixmediav3thumbnailservernamemediaid).
with the exception of 200 responses to the media download endpoints in the
[Content Repository module](#content-repository).
Servers must include a `Content-Type` header of `application/json` for all JSON responses.

All JSON data, in requests or responses, must be encoded using UTF-8.
Expand Down
58 changes: 53 additions & 5 deletions content/client-server-api/modules/content_repo.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,67 @@ When serving content, the server SHOULD provide a
interacting with the media repository.
{{% /boxes/added-in-paragraph %}}

{{% boxes/added-in-paragraph %}}
{{< changed-in v="1.11" >}} The unauthenticated download endpoints have been
deprecated in favour of newer, authenticated, ones. This change includes updating
the paths of all media endpoints from `/_matrix/media/*` to `/_matrix/client/{version}/media/*`,
with the exception of the `/upload` and `/create` endpoints. The upload/create
endpoints are expected to undergo a similar transition in a later version of the
specification.
{{% /boxes/added-in-paragraph %}}

#### Matrix Content (`mxc://`) URIs

Content locations are represented as Matrix Content (`mxc://`) URIs. They
look like:

mxc://<server-name>/<media-id>
```
mxc://<server-name>/<media-id>
<server-name> : The name of the homeserver where this content originated, e.g. matrix.org
<media-id> : An opaque ID which identifies the content.
```

#### Client behaviour {id="content-repo-client-behaviour"}

Clients can access the content repository using the following endpoints.

{{% boxes/added-in-paragraph %}}
{{< changed-in v="1.11" >}} Clients SHOULD NOT use the deprecated media endpoints
described below. Instead, they SHOULD use the new endpoints which require authentication.
{{% /boxes/added-in-paragraph %}}

{{% boxes/warning %}}
By Matrix 1.12, servers SHOULD "freeze" the deprecated, unauthenticated, endpoints
to prevent newly-uploaded media from being downloaded. This SHOULD mean that any
media uploaded *before* the freeze remains accessible via the deprecated endpoints,
and any media uploaded *after* (or *during*) the freeze SHOULD only be accessible
through the new, authenticated, endpoints. For remote media, "newly-uploaded" is
determined by the date the cache was populated. This may mean the media is older
than the freeze, but because the server had to re-download it, it is now considered
"new".

Clients SHOULD update to support the authenticated endpoints before servers freeze
unauthenticated access.

Servers SHOULD consider their local ecosystem impact before enacting a freeze.
This could mean ensuring their users' typical clients support the new endpoints
when available, or updating bridges to start using media proxies.

In addition to the above, servers SHOULD exclude [IdP icons used in the `m.login.sso` flow](/client-server-api/#definition-mloginsso-flow-schema)
from the freeze. See the `m.login.sso` flow schema for details.

An *example* timeline for a server may be:

<server-name> : The name of the homeserver where this content originated, e.g. matrix.org
<media-id> : An opaque ID which identifies the content.
* Matrix 1.11 release: Clients begin supporting authenticated media.
* Matrix 1.12 release: Servers freeze unauthenticated media access.
* Media uploaded prior to this point still works with the deprecated endpoints.
* Newly uploaded (or cached) media *only* works on the authenticated endpoints.

#### Client behaviour
Matrix 1.12 is expected to be released in the July-September 2024 calendar quarter.
{{% /boxes/warning %}}

Clients can upload and download content using the following HTTP APIs.
{{% http-api spec="client-server" api="authed-content-repo" %}}

{{% http-api spec="client-server" api="content-repo" %}}

Expand Down
23 changes: 17 additions & 6 deletions content/server-server-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1196,15 +1196,26 @@ using the following EDU:

Attachments to events (images, files, etc) are uploaded to a homeserver
via the Content Repository described in the [Client-Server
API](/client-server-api). When a server wishes
API](/client-server-api/#content-repository). When a server wishes
to serve content originating from a remote server, it needs to ask the
remote server for the media.

Servers should use the server described in the Matrix Content URI, which
has the format `mxc://{ServerName}/{MediaID}`. Servers should use the
download endpoint described in the [Client-Server
API](/client-server-api), being sure to use
the `allow_remote` parameter (set to `false`).
Servers MUST use the server described in the [Matrix Content URI](/client-server-api/#matrix-content-mxc-uris).
Formatted as `mxc://{ServerName}/{MediaID}`, servers MUST download the media from
`ServerName` using the below endpoints.

{{% boxes/added-in-paragraph %}}
{{< changed-in v="1.11" >}} Servers were previously advised to use the `/_matrix/media/*`
endpoints described by the [Content Repository module in the Client-Server API](/client-server-api/#content-repository),
however, those endpoints have been deprecated. New endpoints are introduced which
require authentication. Naturally, as a server is not a user, they cannot provide
the required access token to those endpoints. Instead, servers MUST try the endpoints
described below before falling back to the deprecated `/_matrix/media/*` endpoints
when they receive a `404 M_UNRECOGNIZED` error. When falling back, servers MUST
be sure to set `allow_remote` to `false`.
{{% /boxes/added-in-paragraph %}}

{{% http-api spec="server-server" api="content_repository" %}}

## Server Access Control Lists (ACLs)

Expand Down
Loading

0 comments on commit 7a51ae8

Please sign in to comment.