Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a2e9656
API Scopes MSC
sandhose Jan 14, 2021
544d75b
Proposed insufficient privilege response format
hughns May 16, 2022
d49f2d8
Remove realm as not required
hughns May 18, 2022
23c7638
Clarifications + update on latest device management proposal
hughns Jul 31, 2022
b609c2b
Revised namespace structure + unstable prefixes
hughns Aug 3, 2022
f07b466
Revise prefix for device ID
hughns Aug 3, 2022
1ce049e
Reference to MSC3861 + cleanup
hughns Aug 5, 2022
5c57507
Add scope for guest access and tidy up
hughns Nov 17, 2022
5afb697
No need for UIA scope
hughns Feb 16, 2023
8ec2d7c
Update proposals/2967-api-scopes.md
hughns Jul 28, 2023
8539ab2
Clarification about encoding of device ID within URN scope
hughns May 10, 2024
0666b24
Merge branch 'matrix-org:main' into msc/sandhose/api-scopes
sandhose Sep 3, 2024
f65aef3
Rework MSC
sandhose Sep 4, 2024
660946a
Update proposals/2967-api-scopes.md
sandhose Mar 5, 2025
4dd433f
Reword as dbkr suggested
sandhose Mar 13, 2025
79845f5
Reword how unstable subdivisions are used
sandhose Mar 13, 2025
49550fe
Remove confusing sentence
sandhose Mar 13, 2025
14b962c
Gather all the links at the bottom of the document
sandhose Mar 13, 2025
58f2398
Tyding up, define exactly how device IDs are handled
sandhose Mar 14, 2025
e7531fa
Don't use a table for a single row
sandhose Mar 14, 2025
acc8e91
Typo
sandhose Mar 14, 2025
1304203
Fix math rendering
sandhose Mar 14, 2025
6623b96
Fix the math
sandhose Mar 18, 2025
1ddd733
Minor rewording on device uniqueness
sandhose Mar 18, 2025
a33d1e3
Simplify wording around the ASCII range
sandhose Mar 18, 2025
0800ea6
Typo
sandhose Mar 18, 2025
a7bb99c
Scope vs scope token is confusing
sandhose Mar 18, 2025
abbae1e
Reword how the device ID is requested
sandhose Mar 18, 2025
082625d
Explain why we keep the device ID generation on the client
sandhose Mar 25, 2025
089a789
MSCXXXX is a better placeholder
sandhose Mar 26, 2025
858b7be
The scope MUST have a device ID
sandhose Mar 26, 2025
c9f8690
Clarify that device IDs are still unique per user
sandhose Mar 26, 2025
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
74 changes: 74 additions & 0 deletions proposals/2967-api-scopes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# MSC2967: API scope restriction

When a user logs in with a Matrix client, it gives this client full access to their Matrix account.

This introduces scopes to allow restricting client access to only part of the Matrix client API.

## Proposal

The [MSC2964](https://github.com/matrix-org/matrix-doc/pull/2964) introduces the usage of OAuth 2.0 to authenticate against a Matrix server.
OAuth 2.0 grants have scopes associated to them and encourage to ask for user consent when a client asks for a new scope that was not granted before.

This MSC does not attempt to define all the scopes necessary to cover the whole API, but lays out a base for that.

### Format

URN are widely used formats for OAuth 2.0 scopes.
All scopes related to Matrix must therefore start with `urn:matrix:`.

Calls to the Matrix client API, excluding calls that need UIA, must be restricted by scopes prefixed by `urn:matrix:api:`.
Calls to endpoints that currently need User-Interactive Authentication (UIA) must be restricted by scopes prefixed by `urn:matrix:sudo:`.

Protected resource can have both `read` and `write` operations.
`write` access to a resource implies `read` access to it.
Access to those operations are specified as the scope suffix, e.g. `urn:matrix:api:[resource]:read`.

### Globs

Scopes used by the Matrix client API support wildcard globs.
`urn:matrix:api:*` gives full access to the API (excluding UIA).
`urn:matrix:api:*:read` gives read-only access to the API.
Access to the `urn:matrix:sudo:*` can be time-restricted and require user re-authentication for sensitive operations.

Top-level wildcards (`urn:matrix:*` or `*`) are not valid and must be rejected by the authentication server.
Wildcards can only replace URN segments, e.g. `urn:matrix:a*` is invalid.

### Exact scopes

The exact scopes are intentionally not specified in this MSC.
The glob mechanism allows to the existing behaviour during a transition period while allowing further MSCs that introduces those exact scopes.

### Device handling

With the pre-MSC2964 authentication mechanism, a `device_id` was associated with the access token.
Since there are no such thing as a session in OAuth 2.0, this can be hardly mapped like this.

`device_id` can be bound to a client session via a scope with this format: `urn:matrix:device:[device_id]`.
If the client does not ask such a scope during the initial login, the authentication server must generate a new `device_id` and give it as a granted scope to the client.
A client can adopt and rehydrate an existing client by asking for its scope on login.
This also has a nice side-effect: if the device asked was never used by the client making the request, the authorization server will ask for explicit consent from the user.

The authentication server must only grant exactly one device scope for a token.
Wildcards are not allowed under the `urn:matrix:device:` prefix.

## Potential issues

The Device ID handling involves some custom logic on the authorization server side.
This means the Matrix server must be involved at some point in the authorization logic, which also involves implementation-specific code for each Matrix server implementation and OAuth 2.0 authentication server implementation.
This is not a problem when the Matrix server acts as the authorization server.

## Alternatives

Scope format could also have an URL format, e.g. `https://matrix.org/api/*/read`.
The URL prefix could either be static (`https://matrix.org`) or dependant on the homeserver (`https://matrix.example.com`).
In both cases, the URL could be confused with API endpoints and in the second case it would require discovery to know what scopes to ask.

The actual prefix as well as the `:api:`, `:sudo:` and `:device:` URN parts are open to debate.

## Security considerations

TBD

## Unstable prefix

None relevant.