Merge pull request #6802 from hughns/qr-other-device-not-signed-in

Show error message when using "Sign in with QR code" with a QR from a device that is also not signed in
This commit is contained in:
Benoit Marty 2026-05-18 14:33:17 +02:00 committed by GitHub
commit 1111315c6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -434,13 +434,30 @@ class RustMatrixAuthenticationService(
qrCodeData: QrCodeData,
): Client {
Timber.d("Creating client for QR Code login with simplified sliding sync")
// The 2025 version of MSC4108 provides baseUrl; the 2024 version has null baseUrl and uses
// serverName instead, which can be null or malformed. We only enforce presence/non-blankness
// here and rely on serverNameOrHomeserverUrl()/the Rust builder layer to validate structure.
val baseUrlOrServerName = qrCodeData.baseUrl() ?: qrCodeData.serverName()
if (baseUrlOrServerName == null) {
// With the 2024 version of MSC4108 we treat the absence of serverName as meaning that
// the other device is not signed in.
Timber.e("The QR code is from a device that is not yet signed in")
throw HumanQrLoginException.OtherDeviceNotSignedIn()
}
if (baseUrlOrServerName.isBlank()) {
Timber.e("The QR code contains an empty base URL or server name, which is invalid")
throw HumanQrLoginException.Unknown()
}
return rustMatrixClientFactory
.getBaseClientBuilder(
sessionPaths = sessionPaths,
passphrase = pendingPassphrase,
slidingSyncType = ClientBuilderSlidingSync.Discovered,
)
.serverNameOrHomeserverUrl(qrCodeData.serverName()!!)
.serverNameOrHomeserverUrl(baseUrlOrServerName)
.build()
}