feat: Add support for MSC4388 #2429
No reviewers
Labels
No labels
Abandoned
Blocked
Bug
Changelog
Added
Changelog
Missing
Changelog
None
Cherry-picking
Compliance
Database
Dependencies
Dependencies/Renovate
Difficulty
Easy
Difficulty
Hard
Difficulty
Medium
Documentation
Enhancement
Good first issue
Help wanted
Inherited
Matrix/Administration
Matrix/Appservices
Matrix/Auth
Matrix/Client
Matrix/Core
Matrix/E2EE
Matrix/Federation
Matrix/Hydra
Matrix/MSC
Matrix/Media
Matrix/T&S
Merge
Merge/Manual
Merge/Squash
Meta
Meta/CI
Meta/Packaging
Priority
Blocking
Priority
High
Priority
Low
Security
Status
Confirmed
Status
Duplicate
Status
Invalid
Status
Needs Investigation
Support
bob the builder
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
continuwuation/continuwuity!2429
Loading…
Reference in a new issue
No description provided.
Delete branch "ginger/msc4388"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This pull request adds support for MSC4388, allowing compatible clients to log in by scanning a QR code.
Pull request checklist:
mainbranch, and the branch is named something other thanmain.myself, if applicable. This includes ensuring code compiles.
@ -917,0 +925,4 @@/// By default this is true, meaning that a user must use their signed-in/// device to generate a QR code when signing in. Setting this to false will/// allow signed-out devices to generate QR codes using this homeserver,/// which may be desirable for public-registration homeservers.Isn't this needed to allow scan-to-login when the logged out device is the desktop?
Yes, but there's abuse potential to leaving it open, so it's off by default as the MSC recommends.
Surprised they didn't find a workaround. Anyway.
@ -0,0 +1 @@Added support for MSC4388, allowing compatible Matrix clients to log in to Continuwuity by scanning a QR code on an already logged-in client. **Sable Next** is known to work; your mileage may vary for other clients. Contributed by @ginger.I don't know if calling out one specific client that works with this feature is fitting for a changelog that becomes mostly static after the release. If you want to convey that support across the ecosystem may be lacking, something like "It may take some time for some clients to implement support for this functionality" may be more fitting
@ -0,0 +9,4 @@use crate::{Ruma, router::ClientIdentity};/// `GET /_matrix/client/unstable/io.element.msc4388/rendezvous`Describing what the endpoint actually does is probably a good idea if you're going to write a docstring at all (same for the rest of the funcs)
The endpoints are pretty self-explanatory, I think. I added doc comments because most other route handlers have them.
@ -0,0 +29,4 @@return Err!(Request(Forbidden("You are not authorized to create a rendezvous session")));}services.rendezvous.create_session(body.data.clone())Is this clone necessary? I'd have assumed you can do a move or partial move at the very least here, although without an IDE im just guessing
It is necessary, unfortunately; we can't move out of
body.@ -910,4 +909,10 @@/// unauthenticated profile retrieval endpoints (GET)/// "/_matrix/client/v3/profile/{userId}"./// Set this to true to require authentication when looking up user profiles/// through this server.////// This can prevent profile scraping./// By default this is false, allowing tools such as matrix.to to access/// profiles of users on this server and on other servers./// Setting this to true will block those tools, and may block automated/// crawlers from scraping users' profiles, although it will not block/// other homeservers from accessing users' profiles.////// default: falseWhy was this change made in this PR?
I adjusted that docstring to more closely match the way the docstring for the new config option was written.
@ -106,12 +106,14 @@ impl Display for RequestedScopes {pub struct RawScopes(String);impl RawScopes {const MIN_DEVICE_ID_LENGTH: usize = 5;I don't see a spec definition of a minimum (or maximum, for that matter) device ID length?
The spec suggests a minimum of 10 characters; I decided to enforce a minimum of 5 characters because anything less runs a serious risk of collisions.
can we make it 6 so it's a nice even number 🥺
@ -131,0 +135,26 @@));}// The Matrix specification has a "suggested" set of// characters to be used in the device// ID scope. In the past we checked against this set, but we// no longer do that; instead we check// against the _required_ set of// characters defined by the OAuth specification.// We do this because we have observed SDKs in the wild// (*cough* matrix-rust-sdk) that will provide device IDs// that are just unpadded base64, which they're allowed to// do, since the spec just says that// clients "SHOULD" only use the suggested character set and// servers "MAY" choose to require that they do.// Of course this actually means that clients will do// whatever the hell they want and// servers can never ever be stricter// than they absolutely have to be. What// a stupid provision.if device_id.chars().any(|char| !matches!(char, '\x21' | '\x23'..'\x5b' | '\x5d'..'\x7e')){return Err("Device ID contains disallowed characters".to_owned());}While this is true, the spec (and OAuth2 RFC) do have a MUST for what chars are allowed, which can be put into a regex:
urn:matrix:(client|org.matrix.msc2967.client):device:([\x21\x23-\x5B\x5D-\x7E]{5,255})instead of whatever you're doing here which smells badOr if you wanted a nicer to read (as far as regex goes) regex range,
urn:matrix:(client|org.matrix.msc2967.client):device:([a-zA-Z0-9!#$%&'()*+,-./:;<=>?@\[\]^_`{|}~]{5,255})I'm intentionally being generous with the regex and then using a
matches!check later because I want to return an error if the device ID is malformed. If the regex doesn't match it will just be skipped instead.@ -0,0 +1,156 @@use std::{I'm not seeing any docstrings or comments in this service
a781a26a4f0827a7acae0827a7acae1d8059a590@ -0,0 +128,4 @@session.last_sequence_token.clone_from(&new_sequence_token);session.transaction_sequences.insert(transaction, sequence_token);This saves the old sequence_token, so a retried txn_id gets a stale token back and the client's next update fails with ConcurrentWrite. Should be .insert(transaction, new_sequence_token.clone()).
@ -131,0 +154,4 @@// a stupid provision.if device_id.chars().any(|char| !matches!(char, '\x21' | '\x23'..'\x5b' | '\x5d'..'\x7e'))i think ~and [ are rejected even though there are OAUTH nqchar
This is going off of what's in the spec.
You're using exclusive ranges (
..instead of..=), so you're rejecting more than RFC6749.Good catch, fixed.
5cf439ffd25c52194f76@ -917,0 +926,4 @@/// device to generate a QR code when signing in. Setting this to false will/// allow signed-out devices to generate QR codes using this homeserver,/// which may be desirable for public-registration homeservers.///a userstray?
@ -0,0 +103,4 @@sequence_token: String,data: String,) -> Result<update_rendezvous_session::unstable::Response> {if data.len() > Self::MAX_DATA_SIZE_BYTES {This should happen after checking for existing sessions per the MSC
Not fixed, you need to move that check further down still:
fixed for real this time
5c52194f76d4341c1941d4341c1941b688838218d0e4ce39d2d312cbd7f9d312cbd7f9221df58f1ac8369c8fa79d2e53af99