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

MSC2461: Proposal for Authenticated Content Repository API #2461

Closed
Changes from 1 commit
Commits
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
79 changes: 79 additions & 0 deletions proposals/2461-authenticated-content-repository-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Authenticated Content Repository API
Currently anyone can fetch resources from content repositories.
This can be undesired behaviour for several reasons as discussed
in [synapse#2150](https://github.com/matrix-org/synapse/issues/2150) and [synapse#2133](https://github.com/matrix-org/synapse/issues/2133).
Homeservers might want to be able to restrict access to the content they serve.

## Proposal
Homeservers may reject unauthenticated access to media endpoints.

When an unauthenticated client accesses an endpoint, the homeserver
may reject the request like it would with an authenticated endpoint.

Thus it returns status code 401 and an error
with an errcode of M_MISSING_TOKEN or M_UNKNOWN_TOKEN as apropriate.

Example response:
```json
{
"errcode": "M_MISSING_TOKEN",
"error": "Media access is restricted to authenticated clients"
}
```

### Configuration
To allow clients to predetermine whether authentication is required,
the configuration field m.media.unauthenticated is added.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added where? To which endpoint? Down there you have that as a reply and not as sending, so something is off

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added endpoint in new revision

It specifies what content can be accessed unauthenticated.

The following behaviours are defined:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Threaded discussions are preferred @helaan

  • m.local Correct, it also allows compliance with local regulations regarding the possession and distribution of illegal content.
  • m.cached Not quite, if the server already fetched the content (or it originated on this server), unauthenticated users can access it. Maybe m.stored is less confusing?
  • m.none and null / missing Exactly.
  • m.unspecified The server could use different criteria to allow access to content, that are not covered by this document.
    This is basically the fallback case of "you need to check to know whether you can access something".
    One might also call it arbitrary, but I didn't want the connotation of
    it never being consistent.

An unpublished version contained "Each entry in the following table is a subset of the preceding ones, with m.unspecified not fitting into this hierarchy".

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I'll switch to threaded replies then.

An unpublished version contained "Each entry in the following table is a subset of the preceding ones, with m.unspecified not fitting into this hierarchy".
That makes it a lot clearer, I did not pick up on m.cached being comparable to m.local.

About m.none: Maybe state more clearly that this is only possible on unfederated servers?

What do you think will be the mode that servers in the public federation will use when this MSC is implemented and it is worth it to have it flexible? Personally, I think federated servers will switch to m.local and unfederated servers will just use m.none. Wouldn't this be simpler and as effective to have this setting depend on whether or not you have federation enabled or am I underestimating the importance of old client support?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion m.none is not just possible on unfederated servers. Having m.none as the default for unfederated servers seems sensible, but concluding that when a server federates it will always have an accessible content repo is wrong. An admin might just not want to distribute through the media endpoints regardless.

I agree m.local would be the most common case for federated servers.

Especially m.cached gives nice properties like explained in the MSC. Although that could be cut and signaled through m.unspecified, loosing the benefit of clients knowing they can link to the content directly.

Having m.unspecified forces client and server authors to think about the possibility of rejection, something that some current clients don't do. It empowers admins to have a different rule set without clients failing when they make assumptions for the other cases.
Maybe this should be replaced or amended with "When an unknown value is encountered a client should account for the possibility of rejection".

Preserving compatibility with older clients is also a choice admins should make.
Explicitly supporting the old behavior allows this.

If I were to create the simplest form of this proposal it would just state.

All unauthenticated accesses to media endpoints may be rejected for any reason

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd generally just recommend we have it turned on for the client-server API regardless. There's nothing stopping a server from accepting lack of auth, and realistically the spec should fix the general case of media being locked down.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such a change should only happen after some server-server API is in place though, right?
Otherwise media couldn't be fetched from a strictly conforming server.


| Enum value | Description |
| ---------- | ----------- |
| null / missing | All content can be accessed unauthenticated |
| m.cached | Only cached content can be accessed unauthenticated |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this even needed? It sounds odd - someone in the room accesses the content and then suddenly everyone can as it is cached

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replying to the first part of the question, as the latter is unrelated as clarified elsewhere.
This is based on Mathew's comment in synapse#2133.
One possible use case for m.cached is that a server admin knows that all users are responsible and allows content that they accessed (and then for exampled didn't report) to be accessed by older clients and to be directly linked to for bridges or download links.

| m.local | Only content with an authority the server is responsible for can be accessed unauthenticated |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean? Basically all users in the room can see it, but noone else?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment.
Does the new context clarify the meaning of this?
Because to me it is phrased very clearly.

| m.unspecified | Unauthenticated access is possible but not specified |
| m.none | No content can be accessed unauthenticated |

Example response:
```json
{
"m.media.unauthenticated": "m.local"
}
```

Clients can decide based on this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not add the authentification type to m.file etc.? So like

{
  "url": "blah",
  "info": { ... },
  "authenticated": "m.local"
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have miscommunicated the intent of this proposal by adding synapse#2150 considering it is only tagentally related. I've read the conversation some time ago and added it from memory. Only checking whether I cought the issues I was thinking of.

I have clarified the intent in a new revision.

if sharing a download link to a non Matrix user is possible.

### Server to server
To reduce the amount of server to server communication,
when one homeserver tries to fetch content from another homeserver,
the configuration should first be retrieved and cached.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no federation API for this.

Copy link
Author

@SyrupThinker SyrupThinker Mar 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured that because servers use the client API for media downloads they could also use it for the media config endpoint

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They cannot. Also they aren't supposed to be using the client endpoints, they just haven't been defined correctly in the server-side endpoints.

Copy link
Author

@SyrupThinker SyrupThinker Mar 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then this proposal is the time to specify that I'd say. Sharing media will be hard.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the "federation api" could be an extra query parameter on existing download/thumbnail endpoints, which can be as simple as authed=yes/no? Of course, servers would need to also authenticate that it is another server that is requesting such media, and not someone else.

When the value is m.none the server should not attempt to fetch the
Copy link
Contributor

@ShadowJonathan ShadowJonathan Apr 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does m.none effectively mean "All content uploaded on here is non-accessible to other servers"? that breaks quite a lot of (core) assumptions in matrix, where f.e. someone setting a room avatar in a federated room can suddenly "not display" that avatar simply because the server does not allow federated propagation of that file, per server-wide rules.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume my other comment clears the first part up, but m.none actually means no restrictions, as in the current behaviour. m.all would actually be the behaviour you describe, as in everything is restricted.

For the latter, yes, that is an expected consequence of this proposal.
I'd expect a user to be made aware by server owners if such media restrictions are in place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"restricted" as in "can only be accessed once authenticated"? And that any server over federation can request such media in an authenticated user's stead?

content from the remote server
and return status code 404 and an error with an errcode of M_NOT_FOUND.

Example response:
```json
{
"errcode": "M_NOT_FOUND",
"error": "Remote homeserver rejected access"
}
```

## Potential issues
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also mentioned in MSC701 (I think, I'm going off memory) is a way to solve the authentication issue without potentially leaking your access token. Clients which have 'download this file' or 'open in new tab' buttons will need to pass along the access token via the query string. In doing so, when someone copies the link and pastes it to someone else they've exposed their account.

Copy link
Author

@SyrupThinker SyrupThinker Mar 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really try to stay away from crypto, so this is just a naive simplification of MSC701:

The authentication token is created through HMAC(access_token, media_id).
This way only the media download can be replayed.
I'm not sure how the HMAC would be verified, but that'd need to be solved for MSC701 as well.

Once homeservers enable this behaviour with a m.media.unauthenticated
value other than null, older clients will not be able to access some content.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not only older clients, but many desktop clients will have a hard time accessing images now. Some of the toolkits people use don't allow them to add headers before the request, so they'd need to add special code for this to buffer the media ahead of time.

This isn't a problem we need to fix in the MSC though, just something to be aware of.

This is desired for the server operator and undesired for the user.

Additionally older clients and servers might encounter an unexpected error code
which may lead to unknown behaviour.

## Alternatives
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need a section comparing it to MSC701

All media endpoints could always require authentication,
but then the server to server exchange would still need
to be extended to allow access for remote homeservers.

## Security considerations
None