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

Add authenticated media (MSC3916) #1858

Merged
merged 22 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f155fdc
C2S: Deprecate now-legacy endpoints
turt2live Jun 10, 2024
bd03530
C2S: Fix MXC URI code block while we're here
turt2live Jun 10, 2024
214e38a
C2S: Describe the authentication and deprecation requirements
turt2live Jun 10, 2024
b19e73a
C2S: Intro the upload/download endpoints differently
turt2live Jun 10, 2024
f10abb3
C2S: Literally copy/paste the `content-repo.yaml` spec
turt2live Jun 10, 2024
c998b8a
C2S: Drop `/upload` and `/create` because we aren't replacing them today
turt2live Jun 10, 2024
a1e558b
C2S: Fix notes while we're here
turt2live Jun 10, 2024
ce861df
C2S: Update metadata for new endpoints
turt2live Jun 10, 2024
e7442b6
C2S: Add authentication to new endpoints
turt2live Jun 10, 2024
3e6ba86
C2S: Drop `allow_remote` and `allow_redirect` on new endpoints
turt2live Jun 10, 2024
c33390f
C2S: Append backwards compatibility notes
turt2live Jun 10, 2024
3cef6f0
C2S: Decorate old media endpoints with pointers to the new ones
turt2live Jun 10, 2024
0617ace
C2S: Annotate IdP icon spec with media auth implications
turt2live Jun 10, 2024
1621ecc
S2S: Modernize section text
turt2live Jun 10, 2024
72c0944
S2S: Create content repository API
turt2live Jun 10, 2024
70e70cb
C2S & S2S: Add plethora of changelogs
turt2live Jun 11, 2024
c7522a6
Reference RFC 1341
turt2live Jun 11, 2024
290e6a2
Upgrade keywords in changed text
turt2live Jun 11, 2024
bc93c9a
Mention caching
turt2live Jun 11, 2024
add03fe
Merge remote-tracking branch 'origin/main' into travis/media-auth
turt2live Jun 11, 2024
aa54db1
Cross-reference IdP icons
turt2live Jun 11, 2024
b73ef14
Update content/client-server-api/modules/content_repo.md
turt2live Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 included updating
turt2live marked this conversation as resolved.
Show resolved Hide resolved
the pathing of all media endpoints from `/_matrix/media/*` to `/_matrix/client/{version}/media/*`,
turt2live marked this conversation as resolved.
Show resolved Hide resolved
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 %}}
turt2live marked this conversation as resolved.
Show resolved Hide resolved
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