From 668edbc67917bdcb50061e4b628bf3aa67c744a3 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 18 May 2026 09:50:54 +0100 Subject: [PATCH 1/4] Fix scanning code from signed out device when using "Sign in with QR code" --- .../impl/auth/RustMatrixAuthenticationService.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt index 6cd30d4f70..837dcee5d9 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt @@ -434,13 +434,23 @@ class RustMatrixAuthenticationService( qrCodeData: QrCodeData, ): Client { Timber.d("Creating client for QR Code login with simplified sliding sync") + // The 2025 versions of MSC4108 should always give us the baseUrl + 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() + } + return rustMatrixClientFactory .getBaseClientBuilder( sessionPaths = sessionPaths, passphrase = pendingPassphrase, slidingSyncType = ClientBuilderSlidingSync.Discovered, ) - .serverNameOrHomeserverUrl(qrCodeData.serverName()!!) + .serverNameOrHomeserverUrl(baseUrlOrServerName) .build() } From 458405b29f7a7ee36009957967b4f1f421292e76 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 18 May 2026 11:44:47 +0100 Subject: [PATCH 2/4] Iterate --- .../matrix/impl/auth/RustMatrixAuthenticationService.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt index 837dcee5d9..336aa4d054 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt @@ -434,7 +434,8 @@ class RustMatrixAuthenticationService( qrCodeData: QrCodeData, ): Client { Timber.d("Creating client for QR Code login with simplified sliding sync") - // The 2025 versions of MSC4108 should always give us the baseUrl + // The 2025 version of MSC4108 will always give us the baseUrl and guarantees it to be a well-formed URL + // The 2024 version always has null baseUrl and uses the serverName instead, which can be null or malformed val baseUrlOrServerName = qrCodeData.baseUrl() ?: qrCodeData.serverName() if (baseUrlOrServerName == null) { @@ -444,6 +445,10 @@ class RustMatrixAuthenticationService( throw HumanQrLoginException.OtherDeviceNotSignedIn() } + if (baseUrlOrServerName.isBlank()) { + error("The QR code contains an empty base URL or server name, which is invalid") + } + return rustMatrixClientFactory .getBaseClientBuilder( sessionPaths = sessionPaths, From efa61f1d249261ea5d3c4fc39acf8a9e5169003e Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 18 May 2026 11:51:23 +0100 Subject: [PATCH 3/4] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../matrix/impl/auth/RustMatrixAuthenticationService.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt index 336aa4d054..40f4b90072 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt @@ -434,8 +434,9 @@ class RustMatrixAuthenticationService( qrCodeData: QrCodeData, ): Client { Timber.d("Creating client for QR Code login with simplified sliding sync") - // The 2025 version of MSC4108 will always give us the baseUrl and guarantees it to be a well-formed URL - // The 2024 version always has null baseUrl and uses the serverName instead, which can be null or malformed + // 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) { From fb17fc7e8afb326647990c9a178b494cc0c63034 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 18 May 2026 11:52:51 +0100 Subject: [PATCH 4/4] Iterate --- .../matrix/impl/auth/RustMatrixAuthenticationService.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt index 336aa4d054..dfc29ee6fe 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt @@ -446,7 +446,8 @@ class RustMatrixAuthenticationService( } if (baseUrlOrServerName.isBlank()) { - error("The QR code contains an empty base URL or server name, which is invalid") + Timber.e("The QR code contains an empty base URL or server name, which is invalid") + throw HumanQrLoginException.Unknown() } return rustMatrixClientFactory