From a32969e1802669d668758d26b51f8de956d33e8d Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Thu, 26 Nov 2026 10:42:22 -0300 Subject: [PATCH 1/6] fix: match figma relay section on pubky auth Co-Authored-By: Claude Fable 5.2 --- Bitkit/Models/PubkyAuthRequest.swift | 8 +++--- .../Localization/ar.lproj/Localizable.strings | 2 +- .../Localization/ca.lproj/Localizable.strings | 2 +- .../Localization/cs.lproj/Localizable.strings | 2 +- .../Localization/de.lproj/Localizable.strings | 2 +- .../Localization/el.lproj/Localizable.strings | 2 +- .../Localization/en.lproj/Localizable.strings | 2 +- .../es-419.lproj/Localizable.strings | 2 +- .../Localization/es.lproj/Localizable.strings | 2 +- .../Localization/fr.lproj/Localizable.strings | 2 +- .../Localization/it.lproj/Localizable.strings | 2 +- .../Localization/nl.lproj/Localizable.strings | 2 +- .../Localization/pl.lproj/Localizable.strings | 2 +- .../pt-BR.lproj/Localizable.strings | 2 +- .../Localization/pt.lproj/Localizable.strings | 2 +- .../Localization/ru.lproj/Localizable.strings | 2 +- .../PubkyAuthApprovalSheet.swift | 26 ++++++++++++++----- BitkitTests/PubkyAuthRequestTests.swift | 25 ++++++++++++++++-- journeys/pubky-auth/open-signin-link.xml | 2 +- 19 files changed, 64 insertions(+), 27 deletions(-) diff --git a/Bitkit/Models/PubkyAuthRequest.swift b/Bitkit/Models/PubkyAuthRequest.swift index 9645c1fcb3..83b5a7a0dc 100644 --- a/Bitkit/Models/PubkyAuthRequest.swift +++ b/Bitkit/Models/PubkyAuthRequest.swift @@ -186,8 +186,9 @@ struct PubkyAuthRequest { isSignup && (!isGrantSignup || !hasIdentity) } - /// The network origin that receives the authorization. This is a delivery destination, not a service identity. - var relayOrigin: String? { + /// The relay URL that receives the authorization, without user info or fragment so the host cannot be disguised. + /// This is a delivery destination, not a service identity. + var relayDisplayUrl: String? { guard let components = URLComponents(string: relay), let scheme = components.scheme?.lowercased(), ["http", "https"].contains(scheme), @@ -198,7 +199,8 @@ struct PubkyAuthRequest { } let port = components.port.map { ":\($0)" } ?? "" - return "\(scheme)://\(host)\(port)" + let query = components.percentEncodedQuery.map { "?\($0)" } ?? "" + return "\(scheme)://\(host)\(port)\(components.percentEncodedPath)\(query)" } static func isProtocolURL(_ value: String) -> Bool { diff --git a/Bitkit/Resources/Localization/ar.lproj/Localizable.strings b/Bitkit/Resources/Localization/ar.lproj/Localizable.strings index 8843b0b0ed..7f24ba82d8 100644 --- a/Bitkit/Resources/Localization/ar.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/ar.lproj/Localizable.strings @@ -754,7 +754,7 @@ "pubky_auth__watch_only_intro_title" = "اربح BITCOIN\nمن\nمحتواك"; "pubky_auth__watch_only_account_xpub_error" = "تعذر على Bitkit إنشاء xpub صالح للحساب."; "pubky_auth__trust_warning" = "تأكد من أنك تثق بالخدمة والمتصفح والجهاز قبل التفويض باستخدام pubky الخاص بك."; -"pubky_auth__authorization_relay" = "مُرحّل التفويض"; +"pubky_auth__authorization_relay" = "المُرحّل"; "pubky_auth__authorizing" = "جارٍ التفويض..."; "pubky_auth__success_title" = "تم التفويض بنجاح"; "pubky_auth__success_prefix" = "لقد فوّضت باستخدام pubky "; diff --git a/Bitkit/Resources/Localization/ca.lproj/Localizable.strings b/Bitkit/Resources/Localization/ca.lproj/Localizable.strings index b57827a2bb..b564e24fec 100644 --- a/Bitkit/Resources/Localization/ca.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/ca.lproj/Localizable.strings @@ -838,7 +838,7 @@ "pubky_auth__watch_only_intro_title" = "GUANYA BITCOIN\nAMB EL TEU\nCONTINGUT"; "pubky_auth__watch_only_account_xpub_error" = "Bitkit no ha pogut crear un xpub de compte vàlid."; "pubky_auth__trust_warning" = "Assegura't que confies en el servei, el navegador i el dispositiu abans d'autoritzar amb el teu pubky."; -"pubky_auth__authorization_relay" = "RELÉ D'AUTORITZACIÓ"; +"pubky_auth__authorization_relay" = "RELÉ"; "pubky_auth__authorizing" = "Autoritzant..."; "pubky_auth__success_title" = "Autorització correcta"; "pubky_auth__success_prefix" = "T'has autoritzat amb el pubky "; diff --git a/Bitkit/Resources/Localization/cs.lproj/Localizable.strings b/Bitkit/Resources/Localization/cs.lproj/Localizable.strings index a1d8df37d6..c0ae17fbc8 100644 --- a/Bitkit/Resources/Localization/cs.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/cs.lproj/Localizable.strings @@ -897,7 +897,7 @@ "pubky_auth__watch_only_intro_title" = "VYDĚLÁVEJTE BITCOIN\nZE SVÉHO\nOBSAHU"; "pubky_auth__watch_only_account_xpub_error" = "Bitkit nemohl vytvořit platný xpub účtu."; "pubky_auth__trust_warning" = "Než se autorizujete pomocí svého pubky, ujistěte se, že službě, prohlížeči a zařízení důvěřujete."; -"pubky_auth__authorization_relay" = "AUTORIZAČNÍ RELAY"; +"pubky_auth__authorization_relay" = "RELAY"; "pubky_auth__authorizing" = "Autorizování..."; "pubky_auth__success_title" = "Autorizace proběhla úspěšně"; "pubky_auth__success_prefix" = "Autorizovali jste se pomocí pubky "; diff --git a/Bitkit/Resources/Localization/de.lproj/Localizable.strings b/Bitkit/Resources/Localization/de.lproj/Localizable.strings index 53e150e755..cb4a292b52 100644 --- a/Bitkit/Resources/Localization/de.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/de.lproj/Localizable.strings @@ -895,7 +895,7 @@ "pubky_auth__watch_only_intro_title" = "VERDIENE BITCOIN\nMIT DEINEN\nINHALTEN"; "pubky_auth__watch_only_account_xpub_error" = "Bitkit konnte keinen gültigen Konto-xpub erstellen."; "pubky_auth__trust_warning" = "Stelle sicher, dass du dem Dienst, dem Browser und dem Gerät vertraust, bevor du dich mit deinem pubky autorisierst."; -"pubky_auth__authorization_relay" = "AUTORISIERUNGS-RELAY"; +"pubky_auth__authorization_relay" = "RELAY"; "pubky_auth__authorizing" = "Autorisiere..."; "pubky_auth__success_title" = "Autorisierung erfolgreich"; "pubky_auth__success_prefix" = "Du hast dich mit dem pubky "; diff --git a/Bitkit/Resources/Localization/el.lproj/Localizable.strings b/Bitkit/Resources/Localization/el.lproj/Localizable.strings index 9e30774ded..bad6bf4934 100644 --- a/Bitkit/Resources/Localization/el.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/el.lproj/Localizable.strings @@ -785,7 +785,7 @@ "pubky_auth__watch_only_intro_title" = "ΚΕΡΔΙΣΤΕ BITCOIN\nΑΠΟ ΤΟ\nΠΕΡΙΕΧΟΜΕΝΟ ΣΑΣ"; "pubky_auth__watch_only_account_xpub_error" = "Το Bitkit δεν μπόρεσε να δημιουργήσει έγκυρο xpub λογαριασμού."; "pubky_auth__trust_warning" = "Βεβαιωθείτε ότι εμπιστεύεστε την υπηρεσία, τον browser και τη συσκευή πριν εξουσιοδοτήσετε με το pubky σας."; -"pubky_auth__authorization_relay" = "ΑΝΑΜΕΤΑΔΟΤΗΣ ΕΞΟΥΣΙΟΔΟΤΗΣΗΣ"; +"pubky_auth__authorization_relay" = "ΑΝΑΜΕΤΑΔΟΤΗΣ"; "pubky_auth__authorizing" = "Εξουσιοδότηση..."; "pubky_auth__success_title" = "Επιτυχής Εξουσιοδότηση"; "pubky_auth__success_prefix" = "Εξουσιοδοτήσατε με το pubky "; diff --git a/Bitkit/Resources/Localization/en.lproj/Localizable.strings b/Bitkit/Resources/Localization/en.lproj/Localizable.strings index 9c1eb9e59c..ceb24bdd68 100644 --- a/Bitkit/Resources/Localization/en.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/en.lproj/Localizable.strings @@ -885,7 +885,7 @@ "pubky_auth__watch_only_intro_title" = "EARN MONEY\nFROM YOUR\nCONTENT"; "pubky_auth__watch_only_account_xpub_error" = "Bitkit could not create a valid account xpub."; "pubky_auth__trust_warning" = "Make sure you trust the service, browser, and device before authorizing with your pubky."; -"pubky_auth__authorization_relay" = "AUTHORIZATION RELAY"; +"pubky_auth__authorization_relay" = "RELAY"; "pubky_auth__authorizing" = "Authorizing..."; "pubky_auth__success_title" = "Authorization Successful"; "pubky_auth__success_prefix" = "You authorized with pubky "; diff --git a/Bitkit/Resources/Localization/es-419.lproj/Localizable.strings b/Bitkit/Resources/Localization/es-419.lproj/Localizable.strings index 7fd85218d8..f57b10d69a 100644 --- a/Bitkit/Resources/Localization/es-419.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/es-419.lproj/Localizable.strings @@ -898,7 +898,7 @@ "pubky_auth__watch_only_intro_title" = "GANE BITCOIN\nCON SU\nCONTENIDO"; "pubky_auth__watch_only_account_xpub_error" = "Bitkit no pudo crear un xpub de cuenta válido."; "pubky_auth__trust_warning" = "Asegúrese de confiar en el servicio, el navegador y el dispositivo antes de autorizar con su pubky."; -"pubky_auth__authorization_relay" = "RELAY DE AUTORIZACIÓN"; +"pubky_auth__authorization_relay" = "RELAY"; "pubky_auth__authorizing" = "Autorizando..."; "pubky_auth__success_title" = "Autorización exitosa"; "pubky_auth__success_prefix" = "Autorizó con el pubky "; diff --git a/Bitkit/Resources/Localization/es.lproj/Localizable.strings b/Bitkit/Resources/Localization/es.lproj/Localizable.strings index b9f3a5c6b9..09f4b229a0 100644 --- a/Bitkit/Resources/Localization/es.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/es.lproj/Localizable.strings @@ -846,7 +846,7 @@ "pubky_auth__watch_only_intro_title" = "GANE BITCOIN\nCON SU\nCONTENIDO"; "pubky_auth__watch_only_account_xpub_error" = "Bitkit no pudo crear un xpub de cuenta válido."; "pubky_auth__trust_warning" = "Asegúrese de que confía en el servicio, el navegador y el dispositivo antes de autorizar con su pubky."; -"pubky_auth__authorization_relay" = "RELÉ DE AUTORIZACIÓN"; +"pubky_auth__authorization_relay" = "RELÉ"; "pubky_auth__authorizing" = "Autorizando..."; "pubky_auth__success_title" = "Autorización correcta"; "pubky_auth__success_prefix" = "Ha autorizado con el pubky "; diff --git a/Bitkit/Resources/Localization/fr.lproj/Localizable.strings b/Bitkit/Resources/Localization/fr.lproj/Localizable.strings index cd930e6217..edc4fd31ad 100644 --- a/Bitkit/Resources/Localization/fr.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/fr.lproj/Localizable.strings @@ -898,7 +898,7 @@ "pubky_auth__watch_only_intro_title" = "GAGNEZ DES BITCOINS\nGRÂCE À VOTRE\nCONTENU"; "pubky_auth__watch_only_account_xpub_error" = "Bitkit n'a pas pu créer de xpub de compte valide."; "pubky_auth__trust_warning" = "Assurez-vous de faire confiance au service, au navigateur et à l'appareil avant de vous authentifier avec votre pubky."; -"pubky_auth__authorization_relay" = "RELAIS D'AUTORISATION"; +"pubky_auth__authorization_relay" = "RELAIS"; "pubky_auth__authorizing" = "Autorisation…"; "pubky_auth__success_title" = "Autorisation réussie"; "pubky_auth__success_prefix" = "Vous vous êtes authentifié avec le pubky "; diff --git a/Bitkit/Resources/Localization/it.lproj/Localizable.strings b/Bitkit/Resources/Localization/it.lproj/Localizable.strings index 6cff1d76e3..0a3e50edd5 100644 --- a/Bitkit/Resources/Localization/it.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/it.lproj/Localizable.strings @@ -879,7 +879,7 @@ "pubky_auth__watch_only_intro_title" = "GUADAGNA BITCOIN\nCON I TUOI\nCONTENUTI"; "pubky_auth__watch_only_account_xpub_error" = "Bitkit non è riuscito a creare un xpub valido per l'account."; "pubky_auth__trust_warning" = "Assicurati di fidarti del servizio, del browser e del dispositivo prima di autorizzare con il tuo pubky."; -"pubky_auth__authorization_relay" = "RELAY DI AUTORIZZAZIONE"; +"pubky_auth__authorization_relay" = "RELAY"; "pubky_auth__authorizing" = "Autorizzazione..."; "pubky_auth__success_title" = "Autorizzazione Riuscita"; "pubky_auth__success_prefix" = "Hai autorizzato con il pubky "; diff --git a/Bitkit/Resources/Localization/nl.lproj/Localizable.strings b/Bitkit/Resources/Localization/nl.lproj/Localizable.strings index 0389e30ef3..3e9e680d40 100644 --- a/Bitkit/Resources/Localization/nl.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/nl.lproj/Localizable.strings @@ -895,7 +895,7 @@ "pubky_auth__watch_only_intro_title" = "VERDIEN BITCOIN\nMET UW\nCONTENT"; "pubky_auth__watch_only_account_xpub_error" = "Bitkit kon geen geldige account-xpub aanmaken."; "pubky_auth__trust_warning" = "Zorg dat u de service, browser en het apparaat vertrouwt voordat u met uw pubky autoriseert."; -"pubky_auth__authorization_relay" = "AUTORISATIERELAY"; +"pubky_auth__authorization_relay" = "RELAY"; "pubky_auth__authorizing" = "Autoriseren..."; "pubky_auth__success_title" = "Autorisatie geslaagd"; "pubky_auth__success_prefix" = "U hebt geautoriseerd met pubky "; diff --git a/Bitkit/Resources/Localization/pl.lproj/Localizable.strings b/Bitkit/Resources/Localization/pl.lproj/Localizable.strings index 89dbd098e0..a3facdae14 100644 --- a/Bitkit/Resources/Localization/pl.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/pl.lproj/Localizable.strings @@ -897,7 +897,7 @@ "pubky_auth__watch_only_intro_title" = "ZARABIAJ BITCOINY\nNA SWOICH\nTREŚCIACH"; "pubky_auth__watch_only_account_xpub_error" = "Bitkit nie mógł utworzyć prawidłowego xpub konta."; "pubky_auth__trust_warning" = "Upewnij się, że ufasz usłudze, przeglądarce i urządzeniu, zanim autoryzujesz za pomocą swojego pubky."; -"pubky_auth__authorization_relay" = "PRZEKAŹNIK AUTORYZACJI"; +"pubky_auth__authorization_relay" = "PRZEKAŹNIK"; "pubky_auth__authorizing" = "Autoryzowanie..."; "pubky_auth__success_title" = "Autoryzacja zakończona"; "pubky_auth__success_prefix" = "Autoryzowano za pomocą pubky "; diff --git a/Bitkit/Resources/Localization/pt-BR.lproj/Localizable.strings b/Bitkit/Resources/Localization/pt-BR.lproj/Localizable.strings index 62f17f3d7e..77bf48c2df 100644 --- a/Bitkit/Resources/Localization/pt-BR.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/pt-BR.lproj/Localizable.strings @@ -897,7 +897,7 @@ "pubky_auth__watch_only_intro_title" = "GANHE BITCOIN\nCOM O SEU\nCONTEÚDO"; "pubky_auth__watch_only_account_xpub_error" = "A Bitkit não conseguiu criar um xpub de conta válido."; "pubky_auth__trust_warning" = "Certifique-se de que confia no serviço, no navegador e no dispositivo antes de autorizar com sua pubky."; -"pubky_auth__authorization_relay" = "RELAY DE AUTORIZAÇÃO"; +"pubky_auth__authorization_relay" = "RELAY"; "pubky_auth__authorizing" = "Autorizando..."; "pubky_auth__success_title" = "Autorização Concluída"; "pubky_auth__success_prefix" = "Você autorizou com a pubky "; diff --git a/Bitkit/Resources/Localization/pt.lproj/Localizable.strings b/Bitkit/Resources/Localization/pt.lproj/Localizable.strings index 561a186f10..d165959530 100644 --- a/Bitkit/Resources/Localization/pt.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/pt.lproj/Localizable.strings @@ -803,7 +803,7 @@ "pubky_auth__watch_only_intro_title" = "GANHE BITCOIN\nCOM O SEU\nCONTEÚDO"; "pubky_auth__watch_only_account_xpub_error" = "A Bitkit não conseguiu criar uma xpub de conta válida."; "pubky_auth__trust_warning" = "Confirme que confia no serviço, no navegador e no dispositivo antes de autorizar com o seu pubky."; -"pubky_auth__authorization_relay" = "RELAY DE AUTORIZAÇÃO"; +"pubky_auth__authorization_relay" = "RELAY"; "pubky_auth__authorizing" = "A autorizar..."; "pubky_auth__success_title" = "Autorização concluída"; "pubky_auth__success_prefix" = "Autorizou com o pubky "; diff --git a/Bitkit/Resources/Localization/ru.lproj/Localizable.strings b/Bitkit/Resources/Localization/ru.lproj/Localizable.strings index a19e3a9759..ce8b42e6b9 100644 --- a/Bitkit/Resources/Localization/ru.lproj/Localizable.strings +++ b/Bitkit/Resources/Localization/ru.lproj/Localizable.strings @@ -893,7 +893,7 @@ "pubky_auth__watch_only_intro_title" = "ЗАРАБАТЫВАЙТЕ БИТКОИН\nНА СВОЁМ\nКОНТЕНТЕ"; "pubky_auth__watch_only_account_xpub_error" = "Bitkit не смог создать действительный xpub аккаунта."; "pubky_auth__trust_warning" = "Убедитесь, что вы доверяете сервису, браузеру и устройству, прежде чем авторизоваться с вашим pubky."; -"pubky_auth__authorization_relay" = "РЕТРАНСЛЯТОР АВТОРИЗАЦИИ"; +"pubky_auth__authorization_relay" = "РЕТРАНСЛЯТОР"; "pubky_auth__authorizing" = "Авторизация..."; "pubky_auth__success_title" = "Авторизация Выполнена"; "pubky_auth__success_prefix" = "Вы авторизовались с pubky "; diff --git a/Bitkit/Views/Sheets/PubkyAuthApproval/PubkyAuthApprovalSheet.swift b/Bitkit/Views/Sheets/PubkyAuthApproval/PubkyAuthApprovalSheet.swift index 5de86a6689..f5d3bf3b65 100644 --- a/Bitkit/Views/Sheets/PubkyAuthApproval/PubkyAuthApprovalSheet.swift +++ b/Bitkit/Views/Sheets/PubkyAuthApproval/PubkyAuthApprovalSheet.swift @@ -431,8 +431,8 @@ struct PubkyAuthApprovalSheet: View { .padding(.bottom, 32) } - if let relayOrigin = config.request.relayOrigin { - relayOriginSection(relayOrigin) + if let relayUrl = config.request.relayDisplayUrl { + relaySection(relayUrl) .padding(.bottom, 32) } @@ -532,11 +532,25 @@ struct PubkyAuthApprovalSheet: View { } } - private func relayOriginSection(_ relayOrigin: String) -> some View { + private func relaySection(_ relayUrl: String) -> some View { VStack(alignment: .leading, spacing: 8) { - CaptionMText(t("pubky_auth__authorization_relay"), textColor: .white64) - BodySSBText(relayOrigin) - .accessibilityIdentifier("PubkyAuthRelayOrigin") + CaptionMText(t("pubky_auth__authorization_relay"), textColor: .white64).frame(minHeight: 18) + HStack(alignment: .top, spacing: 4) { + Image("globe") + .resizable() + .scaledToFit() + .foregroundColor(.white) + .frame(width: 16, height: 16) + .padding(.top, 2) + .accessibilityHidden(true) + + BodySSBText(pubkyAuthLiteralText(relayUrl)) + .fixedSize(horizontal: false, vertical: true) + .textSelection(.enabled) + .accessibilityIdentifier("PubkyAuthRelayOrigin") + + Spacer(minLength: 0) + } CustomDivider(color: .white10) } } diff --git a/BitkitTests/PubkyAuthRequestTests.swift b/BitkitTests/PubkyAuthRequestTests.swift index 5082c0a4cf..1ccf3511c2 100644 --- a/BitkitTests/PubkyAuthRequestTests.swift +++ b/BitkitTests/PubkyAuthRequestTests.swift @@ -1,4 +1,5 @@ @testable import Bitkit +import Paykit import XCTest /// Tests for PubkyAuthRequest capability parsing and permission display. @@ -76,14 +77,34 @@ final class PubkyAuthRequestTests: XCTestCase { } } - func testRelayOriginShowsOnlyTheAuthorizationDestination() throws { + func testRelayDisplayUrlKeepsThePathAndDropsUserInfoAndFragment() throws { let url = "bitkit://pubky-auth/setup?caps=\(PubkyAuthClaim.requiredCapabilities)" + "&relay=https%3A%2F%2FRelay.Example%3A8443%2Finbox%2F&secret=\(secret)" + "&cid=paykit.test&cpk=\(publicKey)&x-bitkit-claim=watch-only-account-v1" let request = try PubkyAuthRequest.parse(url: url) - XCTAssertEqual(request.relayOrigin, "https://relay.example:8443") + XCTAssertEqual(request.relayDisplayUrl, "https://relay.example:8443/inbox/") + + let displayUrls: [(relay: String, expected: String?)] = [ + ("https://httprelay.pubky.app/link", "https://httprelay.pubky.app/link"), + ("https://httprelay.pubky.app", "https://httprelay.pubky.app"), + ("http://user@10.0.2.2:15412/link?x=1#y", "http://10.0.2.2:15412/link?x=1"), + ("https://trusted.example@relay.example/in%20box/", "https://relay.example/in%20box/"), + ("ftp://relay.example/inbox/", nil), + ("relay.example/inbox/", nil), + ("https:///inbox/", nil), + ("", nil), + ] + for (relay, expected) in displayUrls { + let request = PubkyAuthRequest( + rawUrl: url, kind: .signIn, clientID: "paykit.test", relay: relay, capabilities: "/pub/example/:rw", + permissions: [], serviceNames: [], bitkitClaim: nil, homeserverPublicKey: nil, signupToken: nil, + authorizationUrl: url + ) + + XCTAssertEqual(request.relayDisplayUrl, expected, relay) + } } func testProtocolUrlRejectsBitkitSpecificSetupHandoffWithoutClaimMarker() { diff --git a/journeys/pubky-auth/open-signin-link.xml b/journeys/pubky-auth/open-signin-link.xml index af87c764a9..7b6df6bf51 100644 --- a/journeys/pubky-auth/open-signin-link.xml +++ b/journeys/pubky-auth/open-signin-link.xml @@ -6,7 +6,7 @@ If the simulator asks to open the link in Bitkit, tap Open Verify the authorize button (id "PubkyAuthAuthorize") is visible Wait 5 seconds, then verify the authorize button (id "PubkyAuthAuthorize") is still visible - Verify the relay origin (id "PubkyAuthRelayOrigin") shows "https://httprelay.pubky.app" + Verify the relay (id "PubkyAuthRelayOrigin") shows "https://httprelay.pubky.app/inbox/" next to a globe icon under the RELAY label Verify the Paykit access row (id "PubkyAuthPaykitAccess") is not visible Tap Cancel (id "PubkyAuthCancel") Verify the authorize button (id "PubkyAuthAuthorize") is no longer visible From da8f258e221a46945d2ab55d52db11b849b431fd Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Thu, 26 Nov 2026 10:42:43 -0300 Subject: [PATCH 2/6] chore: add changelog fragment Co-Authored-By: Claude Fable 5.2 --- changelog.d/next/1502.changed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/next/1502.changed.md diff --git a/changelog.d/next/1502.changed.md b/changelog.d/next/1502.changed.md new file mode 100644 index 0000000000..f64d4e8bb4 --- /dev/null +++ b/changelog.d/next/1502.changed.md @@ -0,0 +1 @@ +Changed the Pubky authorization screen to show the relay's full address next to a globe icon. From d7042c1bf1f2eb5275c264254a3e8fc24854597b Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Thu, 26 Nov 2026 11:42:28 -0300 Subject: [PATCH 3/6] fix: fail closed on unreadable pubky auth relays Co-Authored-By: Claude Fable 5.2 --- Bitkit/Models/PubkyAuthRequest.swift | 48 ++++++++--- .../PubkyAuthApprovalSheet.swift | 25 ++++-- BitkitTests/PubkyAuthRequestTests.swift | 79 +++++++++++++++---- journeys/pubky-auth/open-signin-link.xml | 2 +- 4 files changed, 117 insertions(+), 37 deletions(-) diff --git a/Bitkit/Models/PubkyAuthRequest.swift b/Bitkit/Models/PubkyAuthRequest.swift index 83b5a7a0dc..706222aedf 100644 --- a/Bitkit/Models/PubkyAuthRequest.swift +++ b/Bitkit/Models/PubkyAuthRequest.swift @@ -187,20 +187,41 @@ struct PubkyAuthRequest { } /// The relay URL that receives the authorization, without user info or fragment so the host cannot be disguised. - /// This is a delivery destination, not a service identity. + /// This is a delivery destination, not a service identity. Nil only when the request has no relay. var relayDisplayUrl: String? { - guard let components = URLComponents(string: relay), - let scheme = components.scheme?.lowercased(), - ["http", "https"].contains(scheme), - let host = components.host?.lowercased(), - !host.isEmpty - else { - return nil + Self.displayRelay(relay) + } + + /// The relay as shown on the approval sheet: scheme, host, port, path and query. Nil when the destination the Pubky + /// SDK would send to cannot be read from `relay` with certainty: a backslash, a space, control or non-ASCII + /// characters, a missing or percent-encoded host, or a numeric host that is not a plain IPv4 address. + static func displayRelay(_ relay: String) -> String? { + guard relay.unicodeScalars.allSatisfy({ $0.value > 0x20 && $0.value < 0x7F && $0 != "\\" }), + let schemeEnd = relay.range(of: "://"), schemeEnd.lowerBound > relay.startIndex + else { return nil } + let scheme = relay[.. Bool { @@ -343,6 +364,9 @@ struct PubkyAuthRequest { .compactMap { extractServiceName($0.path) } .filter { seenServiceNames.insert($0).inserted } let bitkitClaim = try parseBitkitClaim(url: url, capabilities: capabilities, requiresBitkitClaim: requiresBitkitClaim) + guard relay.isEmpty || displayRelay(relay) != nil else { + throw PubkyAuthRequestError.invalidUrl + } return PubkyAuthRequest( rawUrl: url, kind: kind, diff --git a/Bitkit/Views/Sheets/PubkyAuthApproval/PubkyAuthApprovalSheet.swift b/Bitkit/Views/Sheets/PubkyAuthApproval/PubkyAuthApprovalSheet.swift index f5d3bf3b65..57be2aa6f5 100644 --- a/Bitkit/Views/Sheets/PubkyAuthApproval/PubkyAuthApprovalSheet.swift +++ b/Bitkit/Views/Sheets/PubkyAuthApproval/PubkyAuthApprovalSheet.swift @@ -431,22 +431,29 @@ struct PubkyAuthApprovalSheet: View { .padding(.bottom, 32) } - if let relayUrl = config.request.relayDisplayUrl { - relaySection(relayUrl) - .padding(.bottom, 32) - } + let relayUrl = config.request.relayDisplayUrl + let showsPaykitAccess = config.request.bitkitClaim?.includesPaykitAccess == true if !config.request.permissions.isEmpty { permissionsSection + if relayUrl != nil || showsPaykitAccess { + sectionDivider + } + } + + if let relayUrl { + relaySection(relayUrl) + if showsPaykitAccess { + sectionDivider + } } - if config.request.bitkitClaim?.includesPaykitAccess == true { + if showsPaykitAccess { VStack(alignment: .leading, spacing: 8) { CaptionMText(t("pubky_auth__details"), textColor: .white64).frame(minHeight: 18) BodySText(t("pubky_auth__paykit_access_description"), textColor: .textPrimary, kerning: 0, lineHeight: 20) .fixedSize(horizontal: false, vertical: true) } - .padding(.top, 32) .accessibilityElement(children: .contain) .accessibilityIdentifier("PubkyAuthPaykitAccess") } @@ -551,10 +558,14 @@ struct PubkyAuthApprovalSheet: View { Spacer(minLength: 0) } - CustomDivider(color: .white10) } } + private var sectionDivider: some View { + CustomDivider(color: .white10) + .padding(.vertical, 12) + } + private var successDescriptionText: some View { let authorization = requesterText.isEmpty ? t("pubky_auth__success_prefix") + "" + truncatedPublicKey + "" diff --git a/BitkitTests/PubkyAuthRequestTests.swift b/BitkitTests/PubkyAuthRequestTests.swift index 1ccf3511c2..0857f61f08 100644 --- a/BitkitTests/PubkyAuthRequestTests.swift +++ b/BitkitTests/PubkyAuthRequestTests.swift @@ -1,5 +1,4 @@ @testable import Bitkit -import Paykit import XCTest /// Tests for PubkyAuthRequest capability parsing and permission display. @@ -86,25 +85,71 @@ final class PubkyAuthRequestTests: XCTestCase { XCTAssertEqual(request.relayDisplayUrl, "https://relay.example:8443/inbox/") - let displayUrls: [(relay: String, expected: String?)] = [ - ("https://httprelay.pubky.app/link", "https://httprelay.pubky.app/link"), - ("https://httprelay.pubky.app", "https://httprelay.pubky.app"), - ("http://user@10.0.2.2:15412/link?x=1#y", "http://10.0.2.2:15412/link?x=1"), - ("https://trusted.example@relay.example/in%20box/", "https://relay.example/in%20box/"), - ("ftp://relay.example/inbox/", nil), - ("relay.example/inbox/", nil), - ("https:///inbox/", nil), - ("", nil), + let shown = [ + "https://httprelay.pubky.app/link": "https://httprelay.pubky.app/link", + "https://httprelay.pubky.app": "https://httprelay.pubky.app", + "http://user@10.0.2.2:15412/link?x=1#y": "http://10.0.2.2:15412/link?x=1", + "https://trusted.example@relay.example/in%20box/": "https://relay.example/in%20box/", + "https://relay.example/a|b?c=^{d}`[e]": "https://relay.example/a|b?c=^{d}`[e]", + "https://relay.example?x=1": "https://relay.example?x=1", + "https://relay.example./link": "https://relay.example./link", + "https://-re_lay~.1abc/link": "https://-re_lay~.1abc/link", + "https://xn--e1aybc.example/link": "https://xn--e1aybc.example/link", + "https://[2001:DB8::1]:8443/link": "https://[2001:db8::1]:8443/link", + "https://127.0.0.1/link": "https://127.0.0.1/link", + "https://evil.example/@httprelay.pubky.app/link": "https://evil.example/@httprelay.pubky.app/link", ] - for (relay, expected) in displayUrls { - let request = PubkyAuthRequest( - rawUrl: url, kind: .signIn, clientID: "paykit.test", relay: relay, capabilities: "/pub/example/:rw", - permissions: [], serviceNames: [], bitkitClaim: nil, homeserverPublicKey: nil, signupToken: nil, - authorizationUrl: url - ) + for (relay, expected) in shown { + XCTAssertEqual(PubkyAuthRequest.displayRelay(relay), expected, relay) + } + } + + func testRelayWhoseDestinationCannotBeReadWithCertaintyIsNotShownAsAnotherHost() { + let unreadable = [ + "https://evil.example\\@httprelay.pubky.app/link", + "https://httprelay.pubky.app\\.evil.example/link", + "https://реле.example/link", + "https://%65vil.example/link", + "https://0x7f.1/link", + "https://2130706433/link", + "https://1.2.3/link", + "https://127.0.0.1./link", + "https://relay.example /link", + "https://relay\t.example/link", + "https://relay.example\n/link", + "https://relay.example:/link", + "https:///inbox/", + "https:/relay.example/inbox/", + "https:relay.example/inbox/", + "ftp://relay.example/inbox/", + "relay.example/inbox/", + "not a url", + "", + ] + for relay in unreadable { + XCTAssertNil(PubkyAuthRequest.displayRelay(relay), relay) + } + } + + func testRequestWithARelayThatCannotBeShownIsInvalid() throws { + // The Ring signup path hands the relay over as written, so it is the one the SDK would parse differently. + let ringSignup = "pubkyring://signup?hs=\(publicKey)&secret=\(secret)&caps=%2Fpub%2Fexample.app%2F%3Arw&relay=" + let request = try PubkyAuthRequest.parse(url: ringSignup + "https%3A%2F%2Frelay.example%2Finbox%2F") + XCTAssertEqual(request.relayDisplayUrl, "https://relay.example/inbox/") - XCTAssertEqual(request.relayDisplayUrl, expected, relay) + for relay in [ + "https%3A%2F%2Fevil.example%5C%40relay.example%2Finbox%2F", + "https%3A%2F%2Frel%C3%A4y.example%2Finbox%2F", + "https%3A%2F%2F0x7f.1%2Finbox%2F", + ] { + XCTAssertThrowsError(try PubkyAuthRequest.parse(url: ringSignup + relay), relay) { + XCTAssertEqual($0 as? PubkyAuthRequestError, .invalidUrl, relay) + } } + + let direct = try PubkyAuthRequest.parse(url: directSignupUrl(action: "direct_signup")) + XCTAssertEqual(direct.relay, "") + XCTAssertNil(direct.relayDisplayUrl) } func testProtocolUrlRejectsBitkitSpecificSetupHandoffWithoutClaimMarker() { diff --git a/journeys/pubky-auth/open-signin-link.xml b/journeys/pubky-auth/open-signin-link.xml index 7b6df6bf51..7c1d4f7a42 100644 --- a/journeys/pubky-auth/open-signin-link.xml +++ b/journeys/pubky-auth/open-signin-link.xml @@ -6,7 +6,7 @@ If the simulator asks to open the link in Bitkit, tap Open Verify the authorize button (id "PubkyAuthAuthorize") is visible Wait 5 seconds, then verify the authorize button (id "PubkyAuthAuthorize") is still visible - Verify the relay (id "PubkyAuthRelayOrigin") shows "https://httprelay.pubky.app/inbox/" next to a globe icon under the RELAY label + Verify the relay (id "PubkyAuthRelayOrigin") shows "https://httprelay.pubky.app/inbox/" next to a globe icon under the RELAY label and below the requested permissions Verify the Paykit access row (id "PubkyAuthPaykitAccess") is not visible Tap Cancel (id "PubkyAuthCancel") Verify the authorize button (id "PubkyAuthAuthorize") is no longer visible From 3689405851528255116e0e617c400b65dde02c6c Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Thu, 26 Nov 2026 13:32:33 -0300 Subject: [PATCH 4/6] fix: show pubky auth relays only as the sdk keeps them Co-Authored-By: Claude Fable 5.2 --- Bitkit/Models/PubkyAuthRequest.swift | 73 +++++++++++++++++++------ BitkitTests/PubkyAuthRequestTests.swift | 40 +++++++++++++- 2 files changed, 94 insertions(+), 19 deletions(-) diff --git a/Bitkit/Models/PubkyAuthRequest.swift b/Bitkit/Models/PubkyAuthRequest.swift index 706222aedf..48e2d766fa 100644 --- a/Bitkit/Models/PubkyAuthRequest.swift +++ b/Bitkit/Models/PubkyAuthRequest.swift @@ -192,36 +192,77 @@ struct PubkyAuthRequest { Self.displayRelay(relay) } - /// The relay as shown on the approval sheet: scheme, host, port, path and query. Nil when the destination the Pubky - /// SDK would send to cannot be read from `relay` with certainty: a backslash, a space, control or non-ASCII - /// characters, a missing or percent-encoded host, or a numeric host that is not a plain IPv4 address. + /// The relay as shown on the approval sheet: scheme, host, port, path and query, exactly as the Pubky SDK's URL parser + /// keeps them. Nil when `relay` is not already in that form apart from letter case, user info, the fragment and a + /// missing root path: a backslash, a space, control or non-ASCII characters, characters the parser percent-encodes, + /// a missing, percent-encoded or non-canonical host, a default, padded or out-of-range port, or a `.` or `..` path + /// segment. static func displayRelay(_ relay: String) -> String? { - guard relay.unicodeScalars.allSatisfy({ $0.value > 0x20 && $0.value < 0x7F && $0 != "\\" }), + let rewritten = "\\\"<>`{}^'".unicodeScalars + guard relay.unicodeScalars.allSatisfy({ $0.value > 0x20 && $0.value < 0x7F && !rewritten.contains($0) }), let schemeEnd = relay.range(of: "://"), schemeEnd.lowerBound > relay.startIndex else { return nil } let scheme = relay[.. Bool { let matches = { (pattern: String, value: String) in value.range(of: "^(?:\(pattern))$", options: .regularExpression) != nil && !value.contains("\n") } - guard matches(#"(\[[0-9a-f:.]+\]|[a-z0-9._~-]+)(:[0-9]{1,5})?"#, hostPort) else { return nil } - if !hostPort.hasPrefix("[") { - // A last label that reads as a number makes the SDK's URL parser treat the whole host as an IPv4 address. - let host = String(hostPort.split(separator: ":", omittingEmptySubsequences: false)[0]) - let trimmedHost = host.hasSuffix(".") ? String(host.dropLast()) : host - let lastLabel = String(trimmedHost.split(separator: ".", omittingEmptySubsequences: false).last ?? "") - let octet = "(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])" - if matches("[0-9]+|0x[0-9a-f]*", lastLabel), !matches("(\(octet)\\.){3}\(octet)", host) { - return nil + guard matches(#"(\[[0-9a-f:.]+\]|[a-z0-9._~-]+)(:[0-9]{1,5})?"#, hostPort) else { return false } + let portStart = hostPort.hasSuffix("]") ? nil : hostPort.lastIndex(of: ":") + let host = String(hostPort[..<(portStart ?? hostPort.endIndex)]) + if let portStart { + let portText = String(hostPort[hostPort.index(after: portStart)...]) + guard let port = Int(portText), String(port) == portText, port <= 65535, port != defaultPort else { return false } + } + if host.hasPrefix("[") { + return isCanonicalIpv6(String(host.dropFirst().dropLast())) + } + // A last label that reads as a number makes the SDK's URL parser treat the whole host as an IPv4 address. + let trimmedHost = host.hasSuffix(".") ? String(host.dropLast()) : host + let lastLabel = String(trimmedHost.split(separator: ".", omittingEmptySubsequences: false).last ?? "") + let octet = "(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])" + return !matches("[0-9]+|0x[0-9a-f]*", lastLabel) || matches("(\(octet)\\.){3}\(octet)", host) + } + + private static func isCanonicalIpv6(_ address: String) -> Bool { + let halves = address.components(separatedBy: "::") + let head = halves[0].split(separator: ":").map(String.init) + let tail = halves.count > 1 ? halves[1].split(separator: ":").map(String.init) : [] + let missing = 8 - head.count - tail.count + let isComplete = halves.count == 1 ? missing == 0 : halves.count == 2 && missing >= 1 + guard isComplete, !address.contains(".") else { return false } + let parsed = (head + Array(repeating: "0", count: missing) + tail).map { Int($0, radix: 16) } + let groups = parsed.compactMap { $0 } + guard groups.count == 8, groups.allSatisfy({ $0 <= 0xFFFF }) else { return false } + var runStart = 0 + var runLength = 0 + var index = 0 + while index < groups.count { + let end = groups[index...].firstIndex { $0 != 0 } ?? groups.count + if end - index > runLength { + runStart = index + runLength = end - index } + index = max(end, index + 1) } - let pathAndQuery = rest[authorityEnd...].prefix { $0 != "#" } - return "\(scheme)://\(hostPort)\(pathAndQuery)" + let hex = { (part: ArraySlice) in part.map { String($0, radix: 16) }.joined(separator: ":") } + let canonical = runLength < 2 + ? hex(groups[...]) + : "\(hex(groups[.. Bool { diff --git a/BitkitTests/PubkyAuthRequestTests.swift b/BitkitTests/PubkyAuthRequestTests.swift index 0857f61f08..438fa6fa72 100644 --- a/BitkitTests/PubkyAuthRequestTests.swift +++ b/BitkitTests/PubkyAuthRequestTests.swift @@ -87,11 +87,22 @@ final class PubkyAuthRequestTests: XCTestCase { let shown = [ "https://httprelay.pubky.app/link": "https://httprelay.pubky.app/link", - "https://httprelay.pubky.app": "https://httprelay.pubky.app", + "https://httprelay.pubky.app": "https://httprelay.pubky.app/", + "HTTPS://httprelay.pubky.app/link": "https://httprelay.pubky.app/link", + "http://localhost:8080/link": "http://localhost:8080/link", + "https://relay.example:0/link": "https://relay.example:0/link", + "https://relay.example:80/link": "https://relay.example:80/link", + "https://evil.example?@relay.example": "https://evil.example/?@relay.example", + "https://relay.example/?x=@evil.example": "https://relay.example/?x=@evil.example", + "https://evil.example#@relay.example": "https://evil.example/", + "https://relay.example/a/.../b/..c/": "https://relay.example/a/.../b/..c/", + "https://relay.example/inbox?next=../x": "https://relay.example/inbox?next=../x", + "https://[::1]/link": "https://[::1]/link", + "https://[2001:db8:0:1::]/link": "https://[2001:db8:0:1::]/link", "http://user@10.0.2.2:15412/link?x=1#y": "http://10.0.2.2:15412/link?x=1", "https://trusted.example@relay.example/in%20box/": "https://relay.example/in%20box/", - "https://relay.example/a|b?c=^{d}`[e]": "https://relay.example/a|b?c=^{d}`[e]", - "https://relay.example?x=1": "https://relay.example?x=1", + "https://relay.example/a|b?c=[e]": "https://relay.example/a|b?c=[e]", + "https://relay.example?x=1": "https://relay.example/?x=1", "https://relay.example./link": "https://relay.example./link", "https://-re_lay~.1abc/link": "https://-re_lay~.1abc/link", "https://xn--e1aybc.example/link": "https://xn--e1aybc.example/link", @@ -118,6 +129,27 @@ final class PubkyAuthRequestTests: XCTestCase { "https://relay\t.example/link", "https://relay.example\n/link", "https://relay.example:/link", + "https://relay.example:443/link", + "http://relay.example:80/link", + "https://relay.example:65536/link", + "https://relay.example:08443/link", + "https://relay.example/inbox/../../other/", + "https://relay.example/inbox/./x", + "https://relay.example/inbox/%2e%2e/other/", + "https://relay.example/inbox/%2E./other/", + "https://relay.example/inbox/..", + "https://relay.example/..?x=1", + "https://relay.example/a{b}", + "https://relay.example/a?b='c'", + "https://relay.example/a\"b", + "https://relay.example/a^b", + "https://[2001:db8:0:0:0:0:0:1]/link", + "https://[2001:0db8::1]/link", + "https://[1:0:0:2:0:0:0:3]/link", + "https://[::ffff:1.2.3.4]/link", + "https://[1::2::3]/link", + "https://[::12345]/link", + "https://[1:2:3:4:5:6:7:8:9]/link", "https:///inbox/", "https:/relay.example/inbox/", "https:relay.example/inbox/", @@ -141,6 +173,8 @@ final class PubkyAuthRequestTests: XCTestCase { "https%3A%2F%2Fevil.example%5C%40relay.example%2Finbox%2F", "https%3A%2F%2Frel%C3%A4y.example%2Finbox%2F", "https%3A%2F%2F0x7f.1%2Finbox%2F", + "https%3A%2F%2Frelay.example%2Finbox%2F..%2F..%2Fother%2F", + "https%3A%2F%2Frelay.example%2Finbox%2F%252e%252e%2Fother%2F", ] { XCTAssertThrowsError(try PubkyAuthRequest.parse(url: ringSignup + relay), relay) { XCTAssertEqual($0 as? PubkyAuthRequestError, .invalidUrl, relay) From 7115c8db479c8ac9f1e36109d91a82cab2f5a772 Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Thu, 26 Nov 2026 13:46:21 -0300 Subject: [PATCH 5/6] test: cover more pubky auth relay forms Co-Authored-By: Claude Fable 5.2 --- BitkitTests/PubkyAuthRequestTests.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/BitkitTests/PubkyAuthRequestTests.swift b/BitkitTests/PubkyAuthRequestTests.swift index 438fa6fa72..04933ab53f 100644 --- a/BitkitTests/PubkyAuthRequestTests.swift +++ b/BitkitTests/PubkyAuthRequestTests.swift @@ -98,6 +98,12 @@ final class PubkyAuthRequestTests: XCTestCase { "https://relay.example/a/.../b/..c/": "https://relay.example/a/.../b/..c/", "https://relay.example/inbox?next=../x": "https://relay.example/inbox?next=../x", "https://[::1]/link": "https://[::1]/link", + "http://[::1]:443/": "http://[::1]:443/", + "https://relay.example:65535/link": "https://relay.example:65535/link", + "https://[2001:DB8::1]/link": "https://[2001:db8::1]/link", + "https://[::ffff:102:304]/link": "https://[::ffff:102:304]/link", + "https://relay.example/a/..;x": "https://relay.example/a/..;x", + "https://relay.example/a/..%2f": "https://relay.example/a/..%2f", "https://[2001:db8:0:1::]/link": "https://[2001:db8:0:1::]/link", "http://user@10.0.2.2:15412/link?x=1#y": "http://10.0.2.2:15412/link?x=1", "https://trusted.example@relay.example/in%20box/": "https://relay.example/in%20box/", @@ -143,6 +149,12 @@ final class PubkyAuthRequestTests: XCTestCase { "https://relay.example/a?b='c'", "https://relay.example/a\"b", "https://relay.example/a^b", + "https://relay.example/ab", + "https://relay.example/a`b", + "https://relay.example/inbox/%2e/x", + "https://relay.example/inbox/.%2E/other/", + "https://[::1]:443/", "https://[2001:db8:0:0:0:0:0:1]/link", "https://[2001:0db8::1]/link", "https://[1:0:0:2:0:0:0:3]/link", From 01415bed7fb180297b857758c7444101972a8726 Mon Sep 17 00:00:00 2001 From: jvsena42 Date: Fri, 27 Nov 2026 05:46:34 -0300 Subject: [PATCH 6/6] fix: accept relay characters the sdk keeps unchanged Co-Authored-By: Claude Fable 5.2 --- Bitkit/Models/PubkyAuthRequest.swift | 21 ++++++++++++++------- BitkitTests/PubkyAuthRequestTests.swift | 19 ++++++++++++++++++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Bitkit/Models/PubkyAuthRequest.swift b/Bitkit/Models/PubkyAuthRequest.swift index 48e2d766fa..2cf9c13497 100644 --- a/Bitkit/Models/PubkyAuthRequest.swift +++ b/Bitkit/Models/PubkyAuthRequest.swift @@ -194,12 +194,15 @@ struct PubkyAuthRequest { /// The relay as shown on the approval sheet: scheme, host, port, path and query, exactly as the Pubky SDK's URL parser /// keeps them. Nil when `relay` is not already in that form apart from letter case, user info, the fragment and a - /// missing root path: a backslash, a space, control or non-ASCII characters, characters the parser percent-encodes, - /// a missing, percent-encoded or non-canonical host, a default, padded or out-of-range port, or a `.` or `..` path - /// segment. + /// missing root path: a space, control or non-ASCII characters, a backslash before the query, characters the parser + /// percent-encodes in the path or in the query, a missing, percent-encoded or non-canonical host, a default, padded + /// or out-of-range port, or a `.` or `..` path segment. static func displayRelay(_ relay: String) -> String? { - let rewritten = "\\\"<>`{}^'".unicodeScalars - guard relay.unicodeScalars.allSatisfy({ $0.value > 0x20 && $0.value < 0x7F && !rewritten.contains($0) }), + // rust-url 2.5.8 (`url/src/parser.rs`): the `PATH` set is percent-encoded in a path and a backslash becomes a + // slash; a query of an http(s) URL percent-encodes the `SPECIAL_QUERY` set. + let pathRewritten = "\\\"<>`{}" + let queryRewritten = "\"<>'" + guard relay.unicodeScalars.allSatisfy({ $0.value > 0x20 && $0.value < 0x7F }), let schemeEnd = relay.range(of: "://"), schemeEnd.lowerBound > relay.startIndex else { return nil } let scheme = relay[..'\\": "https://relay.example/inbox/", "https://relay.example?x=1": "https://relay.example/?x=1", "https://relay.example./link": "https://relay.example./link", "https://-re_lay~.1abc/link": "https://-re_lay~.1abc/link", @@ -148,7 +157,15 @@ final class PubkyAuthRequestTests: XCTestCase { "https://relay.example/a{b}", "https://relay.example/a?b='c'", "https://relay.example/a\"b", - "https://relay.example/a^b", + "https://relay.example/a}b", + "https://relay.example/a\\b", + "https://relay.example/a/\\..\\b", + "https://user\\@relay.example/inbox/", + "https://relay.example/inbox/?x=\"y\"", + "https://relay.example/inbox/?x=", + "https://relay.example/inbox/?x='y", + "https://relay.example/inbox/?x=a b", "https://relay.example/ab", "https://relay.example/a`b",