matrix-org / sydent

Sydent: Reference Matrix Identity Server
http://matrix.org
Apache License 2.0
292 stars 82 forks source link

Remove the v1 API #338

Open richvdh opened 3 years ago

richvdh commented 3 years ago

Blocked by matrix-org/synapse#9677

The deprecated v1 identity service API is a source of security issues and poor UX. We should set a date to remove it, and follow through with that.

richvdh commented 3 years ago

Some notable places this is still used:

turt2live commented 3 years ago

mxisd is more likely to be ma1sd: https://github.com/ma1uta/ma1sd

callahad commented 3 years ago

Would be good to set a public deprecation timeline for this

turt2live commented 3 years ago

related: https://github.com/matrix-org/matrix-doc/pull/2713

erikjohnston commented 3 years ago

@turt2live suggests that there is other work that might need to be done before we can remove the v1 APIs, but he'd need to go and spend some time figuring out what that is. (I hope that is a fair representation)

BillCarsonFr commented 3 years ago

Notice that email invites are still using V1 api in order to sign the invitation. Also we cannot just change the email template to use the v2 API, because v2 API requires consent for the sign-ed25519 endpoint, this will lead to a pretty bad invite flow.

This API is defined as helper for client that cannot do crypto, but still element clients are using it. I tried to get more info on what clients are supposed to do but failed to find more info.

I guess that before removing this API we should:

richvdh commented 2 years ago

I decided to try and pull some figures on where the v1 API is being used. Over the 7 days to 24 June:

t3chguy commented 1 year ago

/_matrix/identity/api/v1/sign-ed25519 is a strange one.

3PID (email) invites include a link like https://app.element.io/#/room/%21cCpRBTFuXwPmOCUFRL%3Amatrix.org?email=michaelt%40element.io&signurl=https%3A%2F%2Fvector.im%2F_matrix%2Fidentity%2Fapi%2Fv1%2Fsign-ed25519%3Ftoken%3DcBeQOefWJXQrcgHavWuqjMtiazBrYMCvLbpGvOSWFLkitbMbuFGyEmgBbcPtfHhHxiKKsdEbEXSJezCbTXowCuFaQIKV%26private_key%3DRkzs-2BDCjkOOnS74LwLRO_Uw&room_name=&room_avatar_url=&inviter_name=Michael%20Telatynski&guest_access_token=&guest_user_id=&room_type=

Which passes a signurl using the aforementioned API, but encodes the params in query params rather than a POST body which the v2 API docs state the API demands. This means a simple v1->v2 port isn't so simple as now clients would need to receive the parameters outside of the URL and include them in a POST body themselves, with no backwards compatibility.

The API description being

To aid clients who may not be able to perform crypto themselves, the identity server offers some crypto functionality to help in accepting invitations. This is less secure than the client doing it itself, but may be useful where this isn’t possible.

when in reality clients can't really do the signing themselves without parsing the signurl in brittle ways given the URL params don't match any known documentation means that clients are forced to blindly just call a given URL in undocumented ways.

richvdh commented 1 year ago

For links, the endpoint in question used to be specced at https://matrix.org/docs/spec/identity_service/r0.3.0.html#deprecated-post-matrix-identity-api-v1-sign-ed25519; note that a GET variant was never part of the spec.

@t3chguy (and @BillCarsonFr, since I think you said the same thing): I'm failing to grok how this "signurl" is used in the 3pid flow. How is the URL generated? How is it used? I can't find it mentioned at https://spec.matrix.org/v1.5/client-server-api/#server-behaviour-7.

t3chguy commented 1 year ago

It is being used as POST but with no body and all params being query params, so still doesn't match that spec

The link comes from the email templates https://github.com/search?q=repo%3Amatrix-org%2Fsydent+sign-ed25519&type=code The client includes a third_party_signed in the /join/ request which is the object it got back from the sign-ed25519 API, the path & params to which it got via signurl in the link in the email template above

richvdh commented 1 year ago

It is being used as POST but with no body and all params being query params, so still doesn't match that spec

Right. Yes.

The link comes from the email templates https://github.com/search?q=repo%3Amatrix-org%2Fsydent+sign-ed25519&type=code

Is that the link you meant? It doesn't seem to give anything useful here.

t3chguy commented 1 year ago

Yup - all the templates have v1 references to the API.

image

richvdh commented 1 year ago

that link definitely doesn't show me those results, but thanks

t3chguy commented 1 year ago

Ah, might be because I'm on the Github Search Beta which makes the search quite usable

turt2live commented 1 year ago

I'm failing to grok how this "signurl" is used in the 3pid flow. How is the URL generated? How is it used? I can't find it mentioned at https://spec.matrix.org/v1.5/client-server-api/#server-behaviour-7.

@richvdh worth noting that there's two flows an email invite can take, and only one of those flows is documented in the spec. The other is completely missing (I couldn't find an issue at first glance, but know this to be true)

richvdh commented 1 year ago

@richvdh worth noting that there's two flows an email invite can take, and only one of those flows is documented in the spec. The other is completely missing (I couldn't find an issue at first glance, but know this to be true)

Opened https://github.com/matrix-org/matrix-spec/issues/1359 to track this, then.

Re the signurl parameter: based on the evidence of https://github.com/matrix-org/sydent/blob/main/res/matrix-org/invite_template.eml and friends, it looks like:

t3chguy commented 1 year ago

and as such we can consider it to be an implementation detail of sydent, and there is no need for it to be part of the spec.

Yes, and no. Element Web code has to append a &mxid=<my_mxid> to the URL, presumably removing it would make it stop working, this behaviour means we'd need to spec that you need to do such for signurl somewhere.

richvdh commented 1 year ago

Element Web code has to append a &mxid=<my_mxid> to the URL, presumably removing it would make it stop working

Ugh. But also, surely that would work just as well if the root of signurl was https://matrix.org/_sydent/get_stored_invite?... instead of https://matrix.org/_matrix/identity/api/v1/sign-ed25519?... ? In other words, the location of the endpoint is entirely internal to sydent, rather than being a matter for the spec, even if the parameters that should be passed to the endpoint have to be specced (which would be part of matrix-org/matrix-spec#1360).

t3chguy commented 1 year ago

Quite right - especially the ugh

H-Shay commented 1 year ago

Note that there is a config option to disable V1 bindings: https://github.com/matrix-org/sydent/pull/267 - although currently this is only applied to the bind endpoint: https://github.com/matrix-org/sydent/blob/c9980a9fb89d7fa00ef45601294312110f47c565/sydent/http/httpserver.py#L129-L130