Skip to content

fix: refuse pubky auth requests for another pubky - #2104

Merged
jvsena42 merged 6 commits into
masterfrom
fix/pubky-auth-spk
Nov 27, 2026
Merged

jvsena42 merged 6 commits into
masterfrom
fix/pubky-auth-spk

Conversation

@jvsena42

@jvsena42 jvsena42 commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Fixes #1761
Twin: synonymdev/bitkit-ios#1492

Grant sign-in links (pubkyauth://signin_grant) can carry spk=<z32 pubky>, the pubky the requesting app expects to approve (pubky/pubky-ring#399). Bitkit ignored it, signed with its own pubky, and the app then rejected the approval as a generic failure. Bitkit now refuses such a request and says which pubky it is for.

Description

  • Parsing: spk is read from the request's own query. Absent is fine. A repeated spk, an empty one, or anything other than a bare canonical 52-character z-base-32 key (so also pubky…/pk: prefixes, upper case, URL forms, padding variants) makes the request invalid, matching parse_expected_signer in the Pubky SDK (feat(sdk): let grant sign-in links require an expected identity pubky/pubky-homeserver#787). Signup requests ignore spk, as the SDK does. Every other request is held to it, so a sign-in link that the app's URL parser and the SDK read differently cannot skip the check.
  • Refusal before consent: when spk names a pubky other than this wallet's, the approval sheet does not open for consent. The user gets the existing auth error toast with "This request is for <first 4>...<last 4>, not this wallet's pubky."
  • Refusal before signing: the approval entry points compare spk with the public key derived from the secret key that would sign, and throw before any signing or relay call. This also covers the case where the wallet's pubky was not known when the sheet opened.
  • A request whose spk is this wallet's pubky behaves exactly as a request without spk.
  • No existing check is relaxed: the new checks only add rejections.
  • Android specifics: PubkyAuthRequest.parseExpectedSigner and expectedSigner; AppViewModel.handlePubkyAuth refuses before opening the sheet when the pubky is loaded, and PubkyAuthApprovalViewModel.load refuses and dismisses otherwise; PubkyRepo.checkExpectedSigner runs before a watch-only account is prepared; PubkyRepo.approveAuth and approveAuthWithCompanionClaim throw PubkyAuthRequestError.SignerMismatch before calling PubkyService. PubkyRepo.parseAuthUrl also checks that spk is a real public key. New string profile__auth_error_other_pubky in English and all 15 locales.

Where the parsing belongs

Both apps parse grant links with parse_pubky_auth_url from pubky/paykit-rs (paykit-sdk/src/pubky_session.rs), not bitkit-core. paykit 0.1.1-rc9 pins pubky 0.16.2, which predates spk (added in pubky-homeserver v0.18.0), so today it ignores the parameter and PubkyAuthDetails has no field for it. The parsing in this PR is an app-side stopgap. Once paykit-rs moves to an SDK with expected_signer and exposes it on PubkyAuthDetails, the SDK parser rejects malformed links and PubkySigner refuses a mismatch itself; the app then only needs the field for the message, and this parser can go.

Out of Scope

  • pubky/paykit-rs: exposing expected_signer from parse_pubky_auth_url and moving to a Pubky SDK that knows spk; this PR does not change the dependency.
  • PubkyAuthApprovalSheet.kt: an "app chose this pubky" notice on the approval screen, as Pubky Ring shows. Bitkit holds one pubky, and the issue asks only for the refusal.

Design

N/A — no design available. The Figma Auth (paykit) flow has no error or refusal state; the refusal uses the existing auth error toast ("Authorization Failed").

Preview

Pending device run.

QA Notes

Setup

Dev (regtest) debug build, package to.bitkit.dev, wallet onboarded, a Pubky profile created in Bitkit. Read the wallet's pubky from Profile > Share (the share preview shows pubky + 52 characters; OWN is the 52 characters). All links are dummy requests: do not tap Authorize.

OWN=<this wallet's pubky, 52 characters, no prefix>
OTHER=8um71us3fyw6h8wbcxb5ar3rwusy1a6u49956ikzojg3gcwd1dty
BASE='pubkyauth://signin_grant?caps=/pub/locks.app/:rw&relay=https%3A%2F%2Fhttprelay.pubky.app%2Finbox%2F&secret=e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3s&cid=locks.test&cpk=5jsjx1o6fzu6aeeo697r3i5rx15zq41kikcye8wtwdqm4nb4tryo'
open_link() { adb shell "am start -a android.intent.action.VIEW -d '$1' to.bitkit.dev"; }
open_link "$BASE&spk=$OWN"            # opens the approval sheet
open_link "$BASE&spk=$OTHER"          # refused: "This request is for 8um7...1dty, not this wallet's pubky."
open_link "$BASE&spk=$OWN&spk=$OWN"   # invalid link
open_link "$BASE&spk=pubky$OWN"       # invalid link
open_link "$BASE&spk=not-a-public-key" # invalid link

Journeys

  • J1: new signin-expected-pubky.xml — a sign-in link naming this wallet's pubky opens the sheet; another pubky is refused with a message naming it; a repeated, prefixed or malformed spk is an invalid request

Manual Tests

N/A

Automated Checks

  • added PubkyAuthRequestTest.kt — spk absent, matching, repeated, malformed, prefixed, non-canonical; control characters cannot hide it; signup requests ignore it; sign-in links the URL parser reads differently are still held to it; prefix handling when matching
  • added PubkyRepoTest.kt — a request naming another pubky, with a repeated or malformed spk, or with an spk that is not a public key never reaches PubkyService.approveAuth or approveAuthWithCompanionClaim; a matching request is signed; checkExpectedSigner passes for this pubky or none; a grant signup with an existing identity is approved whatever its spk says
  • added PubkyAuthApprovalViewModelTest.kt — a request naming another pubky is dismissed before consent with the message and no approval call is made; when this pubky was unknown at load, the refusal comes before any watch-only account is prepared; a matching request is approved
  • added AppViewModelSendFlowTest.kt — a link naming another pubky is refused before the "Use Pubky Ring" hint and opens no sheet

Evidence

Device screenshots: pending device run

Local checks at a81bee2a2:

  • ./gradlew compileDevDebugKotlin testDevDebugUnitTest detekt lintDevDebug --continue — detekt and Android Lint passed; 6936 tests ran with 1 failure, in the new AppViewModelSendFlowTest case, whose expected text had a typo (8um7...d1ty for 8um7...1dty).
  • After correcting the expectation: ./gradlew testDevDebugUnitTest --tests '*AppViewModelSendFlowTest' — BUILD SUCCESSFUL, 836 tests, 0 failures. The full suite was not run a second time.

Gaps

  • No device run yet; J1 is unverified on a device.

Review

An independent review (fresh agent, no implementation context) found nothing HIGH or MEDIUM. It confirmed that every signing entry point is guarded and that the parsing matches the SDK. Its LOW findings, each checked against the code first:

  • Control characters could hide spk (iOS). URLComponents percent-encodes a literal tab or line break, so s<TAB>pk= was not read as spk, while the SDK's parser drops those characters. Fixed on iOS: any ASCII control character makes the request invalid. Android's java.net.URI already rejects them; a test now asserts it.
  • spk that is canonical z-base-32 but not a public key. It was refused as "another pubky". It is now an invalid request: the value goes through the Paykit key normalizer (PaykitPublicKeys.normalize through PubkyService.validatePublicKey).
  • Side effects before the sign-time refusal (Android). When the wallet's pubky was unknown as the sheet loaded, the watch-only account was prepared before the refusal. Fixed: approveSignInRequest calls PubkyRepo.checkExpectedSigner first, so nothing is prepared and there is nothing to clean up; a view-model test covers that path.
  • Order with a Ring-managed pubky. iOS showed "Use Pubky Ring" first and Android the other-pubky message only once the sheet loaded. Both now refuse a request for another pubky first, then show the Ring hint.
  • Test gaps. Added an AppViewModel test for the pre-check and repository tests that a signup_grant with an existing identity is approved with a foreign, malformed or repeated spk. Also fixed swapped assertEquals arguments.
  • Legacy-link strictness. Kept: any request that is not a signup is held to spk, including legacy signin links the SDK would let through with a malformed value. Paykit accepts only grant links, so this changes nothing a user can reach.

Round 2 found no HIGH or MEDIUM; every signing entry point is checked.

  • signup_grant ignores spk. Confirmed against upstream, pubky/pubky-homeserver at d95161af3e: pubky-sdk/src/actors/auth/deep_links/signin_grant.rs:106 is the only caller of parse_expected_signer (query_params.rs:79), signup_grant.rs never reads spk, deep_link.rs:211 tests that signin and signup_grant ignore it, and docs/AUTH.md:81 scopes it to pubkyauth://signin_grant, as does the Open the pubky an auth request requires, instead of the key picker (expected identity) pubky/pubky-ring#399 spec ("Other request kinds don't carry it"). No behaviour change; the parser comment now cites these.

Merge order. This PR and #2075 edit neighbouring lines of the same files. Merge #2075 first; this PR then needs a rebase, keeping both sides of each conflict.

Review round, 2026-11-27.

  • ovi-reviewer LOW (inline thread), spk that is not an Ed25519 key reported as another pubky: real, fixed in 0f8fbc2d1. PaykitPublicKeys.normalize in paykit-android 0.1.1-rc9 checks only length and alphabet. PubkyService.validatePublicKey now calls the native normalizePubkyPublicKey, as iOS does, and AppViewModel.handlePubkyAuth compares only a validated value through the new PubkyRepo.validExpectedSigner.
  • New tests: AppViewModelSendFlowTest — an spk that is not a key is not reported as another pubky (837 tests); PubkyRepoTest uses the reviewer's value and covers validExpectedSigner (265 tests). detekt and Android Lint pass.
  • Limit: the unit tests mock PubkyService, since the native library does not load on the JVM, so the native rejection of ye + 50 y is unproven here and needs the device case re-run. The thread stays open until then.
  • iOS twin chore: add 3.0.0 translations #1492: not affected; it already validates through Paykit.normalizePubkyPublicKey before any comparison.

Review round, 2026-11-27 (2).

  • Merged origin/master in 7bb8bfd33 (relay PR fix: show relay on pubky auth approval #2075), keeping both sides. New test "expected signer and relay rules hold together": a punctuated relay is still shown for a matching spk and the request is still refused for another pubky.
  • piotr-iohk LOW (inline thread, confirmed on a device by ovi-reviewer at 7bb8bfd33), signer mismatch shown before the relay is validated: real, fixed in 465a4701b. PubkyRepo.validExpectedSigner now names a pubky only when parseAuthUrl accepts the whole request, so a link with an unusable relay always gets the invalid-link message. New tests: PubkyRepoTest "validExpectedSigner names a pubky only for a request that parses in full" (failed before, passes now), PubkyAuthApprovalViewModelTest "invalid link naming another pubky shows the invalid link message", and the ftp-relay case in AppViewModelSendFlowTest. detekt and Android Lint pass. iOS is not affected: it parses the whole request before comparing signers.

Models used

  • Planning/scoping: claude-fable-5-2 (reasoning: Not exposed)
  • Implementation: claude-fable-5-2 (reasoning: Not exposed)
  • Review: claude-fable-5-2 (reasoning: Not exposed)
  • Review rounds: 2

Metadata note: the sessions report the model id but no reasoning setting; the reviewer model is as reported by the coordinating session.

Device check at 0f8fbc2

Pixel_9, wallet A with a profile, dev debug build, install -r. Authorize never tapped.

Case Result Notes Screenshot
spk = ye + 50 y (52 chars) PASS Red toast "Authorization Failed / This Pubky authorization link is invalid." (the generic invalid-link toast; its title reads "Authorization Failed", not "Invalid auth request"). No sheet, no "This request is for". Log: native normalizer invalid Pubky public key, Failed to parse auth request. Run once during profile load (the link waited for the profile), once after. android r6 spk 52y
case 3 other pubky PASS Toast "This request is for 8um7...1dty, not this wallet's pubky."; Authorize never shown; log Refused auth request for another pubky. android r6 spk other pubky

Device check at 465a470

Pixel_9 (API 36, arm64), wallet A "LinkLink" with a profile, dev debug build, install -r, links sent to to.bitkit.dev. Authorize never tapped. Run after the profile finished loading.

Case Result Notes Screenshot
A: ftp:// relay, spk = other pubky (link with cid and cpk) PASS Toast "Authorization Failed / This Pubky authorization link is invalid." (shown while the sheet fades). No "This request is for". No sheet content, no Authorize. Log: Failed to parse auth request [InvalidUrl] from PubkyAuthApprovalVM. android A invalid link
B: valid https relay, spk = other pubky (same link, cid and cpk) PASS Toast "This request is for 8um7...1dty, not this wallet's pubky." No sheet. Log: Refused auth request for another pubky. android B other pubky

Notes: the first links I tried had no cid/cpk (the form in the task text). Those fail earlier with Missing query parameter cid, so they do not test the relay or spk checks. On that no-cid link the toast reads "Authorization Failed / Unknown error" instead of the invalid-link text (screenshot below). Neither the ftp:// nor the https variant reached the spk check.

android A no cid unknown error

🤖 Generated with Claude Code

Review round, 2026-11-27 (merge)

  • Merged origin/master in 7bb8bfd33 after the twin PR merged. Both sides of the conflicts are kept.
  • New test "expected signer and relay rules hold together" (PubkyAuthApprovalViewModelTest) checks that spk refusal and the relay rules work together.
  • Auth test classes pass after the merge.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from 465a470 (run).

Download bitkit-dev-debug universal APK (expires in 30 days).

jvsena42 and others added 2 commits November 26, 2026 13:01
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jvsena42
jvsena42 marked this pull request as ready for review November 26, 2026 18:20
@jvsena42
jvsena42 requested review from a team, ovitrif and piotr-iohk and removed request for a team November 26, 2026 18:20
@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The changes appear safe to merge; no new blocking issue was found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The changes appear safe to merge; no new blocking issue was found.

Summary

Bitkit refuses sign-in requests that name another wallet’s pubky, both before consent and before signing.

  • Sign-in links are approved only by the pubky they name.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Incoming sign-in link] --> B[Parse the whole request]
  B -->|Invalid| C[Show existing link error]
  B -->|Valid| D{Names another pubky?}
  D -->|Yes| E[Refuse before consent]
  D -->|No| F[Show approval sheet]
  F --> G[User approves]
  G --> H[Check the signing key]
  H -->|Mismatch| I[Refuse before signing]
  H -->|Match or no expected signer| J[Send approval]
Loading

Reviews (4) · Last reviewed commit: "fix: validate the whole request before t..." · Reviewed by Greptile

@talosmachina talosmachina left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No findings. Refuses a Pubky sign-in request whose spk names another pubky: parsed with the request (repeated, prefixed or non-canonical is an invalid link), checked before the sheet opens, before any watch-only account is prepared, and again in PubkyRepo right before approveAuth / approveAuthWithCompanionClaim sign. Reviewed baeabb308, full tier (auth path).

What I checked, and 4 candidates I ruled out

Read in full: PubkyAuthRequest.kt (parseExpectedSigner, isExpectedSigner, isSignupRequest), the auth region of PubkyRepo.kt, PubkyAuthApprovalViewModel.kt (load and approveSignInRequest), the AppViewModel pre-check, PubkyAuthErrorMessage.kt.
Signing entry points traced: pubkyService.approveAuth (from PubkyRepo.approveAuth and approveSignupAuth), approveAuthWithCompanionClaim, approveRingAuth. Every sign-in path goes through requireExpectedSigner; only the signup paths skip it, which matches the SDK reading spk for signin_grant alone.
CI at this head: build-local, Greptile green; build-and-test, compose-ui and e2e pending. Static review: on bitkit-android the PR's branch is not built or run by this reviewer, so this rests on the code and on CI.

Ruled out

  • Signup grant bypass: approveSignupAuth signs a grant without the check, but signup requests carry no spk upstream, so there is nothing to compare.
  • Prefixed identity key never matching: isExpectedSigner strips the pubky prefix from the local key only at its exact 57-character length, so the view model's identity key and the repo's publicKeyFromSecret match bare or prefixed; covered in PubkyAuthRequestTest.kt.
  • Query decoding differing from the SDK: URLDecoder turns + into a space as form_urlencoded does, and a key with a space fails the z-base-32 regex either way.
  • Malformed spk reaching the sheet through AppViewModel: the pre-check uses getOrNull(), but parseAuthUrl then calls validatedExpectedSigner first and fails the request as invalid.

Merge confidence: 4/5, no findings and each signing entry point has a repository test, but the auth path's e2e and build-and-test runs are still pending and the branch was not run here.

Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the session metadata names the model, not a reasoning setting)

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: full PR diff against its merge base, at baeabb3.

No new actionable code findings.

No actionable code findings. Both sign-in signing paths, PubkyRepo.approveAuth and approveAuthWithCompanionClaim, check spk against the public key derived from the secret key that would sign, before any PubkyService call. A mismatch is also refused before the sheet opens (AppViewModel.handlePubkyAuth, when the pubky is loaded), when the sheet loads (PubkyAuthApprovalViewModel.load), and before a watch-only account is prepared (checkExpectedSigner). A malformed spk that the AppViewModel pre-check lets through with getOrNull() still fails in PubkyRepo.parseAuthUrl as an invalid request. Signup and signup_grant ignore spk; the Pubky SDK at pubky/pubky-homeserver d95161af3e does the same (parse_expected_signer in query_params.rs:79, called only from signin_grant.rs). The app parser matches that SDK rule: spk must appear once and be a bare, canonical z-base-32 key that the Paykit key normalizer accepts. Holding legacy signin links to spk is stricter than the SDK, and the PR says this is deliberate.

Validation: I ran a small Kotlin script with copies of the parseExpectedSigner and isExpectedSigner logic, using java.net.URI and URLDecoder as the app does. It accepted a valid key and a percent-encoded spk name. It rejected repeated, pubky-prefixed, uppercase, empty, valueless and non-canonical values, and malformed percent escapes. It ignored spk on signup_grant and in the fragment. Prefixed and bare local keys both matched. I did not run the PR's unit tests here. CI build-and-test, lint and detekt passed at this head. All 15 translations of the new string use the %1$s placeholder.

Parity: I compared synonymdev/bitkit-ios#1492 at 45a49bb for the shared behaviour only; this is not a review of that PR. It uses the same parse rules and the same signup exemption. It also refuses another pubky before the "Use Pubky Ring" hint and checks the signer again at signing time. iOS rejects ASCII control characters explicitly; Android's java.net.URI rejects them already, so a malformed link fails closed. One presentation difference: iOS closes the scanner sheet when it refuses, while Android leaves the scanner as its existing "Use Pubky Ring" path already does.

External reviews: Talos and Greptile reported no findings at this head. There are no inline review threads.

Device testing: not performed in this review. The author attributes emulator evidence to baeabb308. The new journey pubky-auth/signin-expected-pubky.xml was not run here.

Ready for device testing: no outstanding code concerns or prerequisites.

Suggested additional test cases

  • Android and iOS, locked or terminated app: with a wallet that has a Bitkit-managed Pubky identity, open BASE&spk=OTHER (links from the journey) while the app is terminated or on the PIN screen, then unlock. Expected: the "This request is for 8um7...1dty, not this wallet's pubky." toast appears, the authorize button never becomes available, and nothing is signed. On Android this goes through the session-restoring path, where the sheet opens and load dismisses it.
  • Android and iOS, in-app scanner: scan a QR code of BASE&spk=OTHER from the main scanner. Expected: the other-pubky toast is visible, no approval sheet opens, and the scanner closes or can be dismissed normally.

Reviewer model: claude-opus-5-5
Reasoning effort: high

@ovi-reviewer ovi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: ⛔️ Request changes — invalid public keys get the wrong refusal reason.

Findings:

  • LOW — Validate the key before reporting an identity mismatch. app/src/main/java/to/bitkit/services/PubkyService.kt:151 calls the Android PaykitPublicKeys.normalize, which checks only length and alphabet. It accepts ye followed by 50 y characters, the canonical encoding of a point the native Ed25519 decoder rejects. On device this shows “This request is for yeyy...yyyy, not this wallet’s pubky” instead of the invalid-link error. AppViewModel.kt:10733 also compares this unvalidated value before repository validation, so both paths need the real key check. The new repository test mocks the validation failure and misses this. Requests remain refused; no signing bypass was found.

QA for baeabb3:

Dev regtest debug build, Android emulator, API 37. No dummy request was authorized.

Reject a canonical value that is not a public key ❌ An invalid Ed25519 point is reported as another wallet’s pubky.

The recording shows the incorrect error. The pinned Android helper accepts this value; ed25519-dalek rejects the same bytes with Cannot decompress Edwards point.

g1-invalid-point-2x.2x.mp4
Refuse Paykit setup without creating a watch-only account ✅ The refusal appears and Server Accounts stays empty.

The recording shows the empty list before and after the foreign-pubky setup request, with no Earn or authorization sheet.

g2-no-watch-only-account-2x.2x.mp4
Refuse another pubky after a cold start ✅ Profile restoration finishes with the foreign-pubky refusal and no authorization sheet.

The app was force-stopped before opening the request; the recording includes the cold launch and profile-loading message.

g3-cold-start-2x.2x.mp4
Refuse another pubky from the main scanner ✅ The QR request is refused and the scanner closes without opening authorization.

Used the main scanner’s gallery button to decode a QR image containing the foreign-pubky sign-in link. The recording shows image selection and the return to Home. The separate screenshot captures the refusal toast; the app log also records the refusal.

g4-main-scanner-2x.2x.mp4

https://github.com/user-attachments/assets/f95220fe-eb5a-4d85-9163-ecd8da379302

Check: build and authorization tests ✅ The head builds and the focused parser, repository, approval-view-model and app-view-model tests pass.

Ran assembleDevDebug and testDevDebugUnitTest filtered to PubkyAuthRequestTest, PubkyRepoTest, PubkyAuthApprovalViewModelTest and AppViewModelSendFlowTest.

The unchanged J1 cases for absent, matching, foreign, repeated, prefixed, malformed and empty spk rely on the author’s exact-head evidence, whose screenshots were inspected. The additional cold-start and scanner checks come from the QA review. Signing and relay delivery were not driven on device: the dummy-link journey explicitly stops before Authorize; the signing guards were checked in the focused tests.

Full review of 576ac14..baeabb3, including all changed code, translations, tests and journey files and the reached signing callers. Translations were inspected, not exercised in every device locale.

Twin: synonymdev/bitkit-ios#1492 matches the intended signer constraint and signup exemption. Its parser uses native key normalization, unlike the Android helper identified above; the twin was compared in code and was not device-tested here.


Reviewed by gpt-6.1-sol-high

@jvsena42
jvsena42 marked this pull request as draft November 27, 2026 08:20
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jvsena42
jvsena42 marked this pull request as ready for review November 27, 2026 09:28

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: changes since baeabb3, including affected code paths and prior findings, at 0f8fbc2. Baseline: previous QA review. Coverage for the spk parser, the approval sheet's refusal path, the refusal string and its localizations, and the journey/docs carries over from that baseline; the follow-up commit did not touch them.

No new actionable code findings.

No new actionable code findings in the follow-up.

PubkyService.validatePublicKey now calls the native normalizePubkyPublicKey instead of the Kotlin PaykitPublicKeys.normalize, which only checks length and alphabet. PubkyRepo.validatedExpectedSigner is its only caller. I checked paykit-rs at tag v0.1.1-rc9 (0b9c63d25dbd), the version pinned in gradle/libs.versions.toml. There, normalize_pubky_public_key (paykit-ffi/src/session.rs:1005) goes through PubkyPublicKey::from_raw_or_app_key and then pubky::PublicKey::try_from_z32 (paykit-sdk/src/identity.rs:23-34), so it decodes the key rather than only checking its spelling. AppViewModel.handlePubkyAuth now uses the new PubkyRepo.validExpectedSigner. That returns null for a missing or invalid spk. The request then goes on to the sheet, where parseAuthUrl fails with InvalidUrl and shows the invalid-link message instead of the other-pubky message. A valid spk for a different key is still refused before the sheet or the Ring hint, and both signing paths still check it again through requireExpectedSigner. The extra hop on the single-threaded PUBKY service queue happens on the same queue the sheet uses as soon as it loads, so it adds no new blocking state.

Prior concern: the review bot's LOW finding on spk point validation is marked resolved. At this head the code fixes it: real key check in the service, plus the pre-check routed through the repository validation. The author reports a device check at 0f8fbc2 showing the invalid-link toast for ye followed by 50 y. That is the author's evidence, not a test this reviewer ran.

Parity: the iOS twin bitkit-ios#1492 at 45a49bb already validates spk with Paykit.normalizePubkyPublicKey while parsing (Bitkit/Models/PubkyAuthRequest.swift:385), so this aligns Android with iOS. Only this flow was compared.

Limits: I ran no tests. The unit tests stub validatePublicKey and validExpectedSigner, so rejecting a real invalid key in native code is not covered by unit tests. I did not fetch the source of the pubky 0.16.2 / pkarr 8.1.0 crates; the claim that try_from_z32 decompresses the Ed25519 point relies on the paykit-sdk call chain and the bot's dalek observation.

Device testing: not performed in this review.

Suggested additional test cases

  • Android, wallet with a local Pubky secret key: open pubkyauth://signin_grant?caps=/pub/paykit/v0/:rw&spk=ye followed by 50 y characters, by deeplink and again by scanner. Expected: the invalid authorization link error, not "This request is for yeyy...yyyy", and nothing is signed or prepared. This could be added as a case in journeys/pubky-auth/signin-expected-pubky.xml.

Reviewer model: claude-opus-5-5
Reasoning effort: high

@piotr-iohk

Copy link
Copy Markdown
Collaborator

@jvsena42 please resolve conflicts.

@ovi-reviewer ovi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: ✅ Approve

Findings: None. The earlier LOW finding is fixed: the exact invalid Ed25519 point now gets the invalid-link message, and real foreign keys still get the other-pubky refusal.

QA for 0f8fbc2:

Dev regtest debug build. Android 17 (API 37), with scanner cases on Android 16 (API 36) and Android 11 (API 30). No dummy request was authorized.

Reject a canonical value that is not a public key ✅ Warm and cold-start requests with the invalid point show the invalid-link error without consent.

Used ye followed by 50 y characters. The recordings show “This Pubky authorization link is invalid.” App logs confirm rejection inside the native normalizePubkyPublicKey, followed by PubkyAuthRequestError.InvalidUrl.

g1-invalid-point-2x.2x.mp4
g1-cold-finish-2x.2x.mp4
Accept this wallet and reject invalid expected signers ✅ Matching and absent signers open consent; foreign and invalid signers are refused.

J1, signin-expected-pubky.xml, plus absent and empty spk. Matching and absent requests show this wallet’s pubky. A foreign key gets the message naming 8um7...1dty; repeated, prefixed, malformed and empty values are invalid. Consent visibility was checked in device UI dumps; error messages were checked in screenshots and the app log. Every consent sheet was canceled.

j1-expected-signers-2x.2x.mp4
Refuse Paykit setup without creating a watch-only account ✅ The foreign-pubky request is refused and Server Accounts stays empty.

The recording shows the empty list before and after the setup request, with no consent sheet.

g2-no-watch-only-account-2x.2x.mp4
Refuse another pubky after a cold start ✅ Profile restoration ends with the foreign-pubky refusal and no authorization sheet.

The app was force-stopped before opening the link. The recording includes the cold launch, profile-loading message and refusal.

g3-cold-start-2x.2x.mp4
Refuse another pubky from the main scanner ✅ The gallery QR request is refused without opening authorization.

Selected a QR image containing the foreign-pubky sign-in link through the main scanner’s gallery button. The recording shows the selection and return to Home; the app log confirms the refusal.

g4-main-scanner-2x.2x.mp4
Reject an invalid public key from the main scanner ✅ The invalid-point QR produces the invalid-link error, without consent or a foreign-pubky refusal.

Selected a QR containing ye followed by 50 y through the main scanner’s gallery button. The recording shows the invalid-link message. App logs confirm the scanner entry and native key rejection; fresh UI dumps confirm no authorization sheet and an empty Server Accounts list before and after.

g5-invalid-scanner-2x.2x.mp4
Check: build and authorization tests ✅ The head builds and the focused authorization tests pass.

Ran assembleDevDebug and testDevDebugUnitTest filtered to PubkyAuthRequestTest, PubkyRepoTest, PubkyAuthApprovalViewModelTest and AppViewModelSendFlowTest.

The invalid-point scanner case follows the latest QA review.

Delta review of baeabb3..0f8fbc2, plus the LOW finding from the earlier review. The author’s device recheck independently confirms native rejection at this head.

Signing and relay delivery were not driven on device: the dummy-link journey stops before Authorize. Signing guards, companion claims and the unchanged signup exemption were checked in the focused unit tests. Translations were not exercised in every device locale.

Twin: synonymdev/bitkit-ios#1492 at 45a49bb matches the native key validation, signer constraint and signup exemption; compared in code, not device-tested here.


QA-advice execution metadata records the model but no reasoning setting.


Reviewed by gpt-6.1-sol-high

ovitrif
ovitrif previously approved these changes Nov 27, 2026

@ovitrif ovitrif left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utAck

@jvsena42
jvsena42 marked this pull request as draft November 27, 2026 10:57
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jvsena42

Copy link
Copy Markdown
Member Author

@piotr-iohk conflicts resolved: merged origin/master in 7bb8bfd, keeping both sides (the spk parser and the relay display code in PubkyAuthRequest.kt, both test sets, both strings). After the merge: compile, detekt and Android Lint pass; PubkyAuthRequestTest 43, PubkyRepoTest 265, PubkyAuthApprovalViewModelTest 41 and AppViewModelSendFlowTest 866 pass. A new view-model test, "expected signer and relay rules hold together", checks that a request with a punctuated relay still shows the relay when spk matches and is still refused when it names another pubky.

@jvsena42
jvsena42 marked this pull request as ready for review November 27, 2026 11:12

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: Full reassessment of Android #2104 at 7bb8bfd after the merge base changed and brought in the relay-display rules.

1 actionable finding — resolve or provide an evidence-backed rebuttal.

Both Android sign-in approval paths compare spk with the public key derived from the exact secret they pass to Paykit. The checks precede identity republication, companion claim signing and relay submission. The sheet checks the loaded or locally recovered identity before consent, then checks the signing key again before preparing a watch-only account. Signup still ignores spk under the upstream contract. The merged relay display and confirmation recheck remain in the approval flow. The early Android deeplink refusal can mask a relay validation error.

Compared shared contracts only with iOS #1492 at 45a49bb. Both platforms validate the signer, enforce the constraint at signing time and exempt signup. iOS parses through Paykit before choosing the mismatch or Ring message. Its relay presentation shows the origin, while Android retains the displayable path and query. This was a source comparison.

The earlier invalid Ed25519 point concern is resolved and the fix is present at the pinned head. Android routes signer validation through the native decoder before comparing keys. A local Rust probe with pkarr 8.1.0 and url 2.5.8 accepted the fixture keys, rejected the earlier invalid point and confirmed the FTP relay survives URL normalization. The reviewer's device evidence applies to the older 0f8fbc2 build. Resolved thread

Validation included a focused Kotlin/JVM probe of the pinned signer and relay helpers, journey XML and translation placeholder checks, and git diff --check on both pins. The local Gradle run timed out before the four focused unit classes executed. The author reports those classes, compilation and lint passed at the pinned head. The PR description bundled requirements with prior review discussion, so discovery was not blind. Dependency source checked included Paykit rc9, Pubky 0.16.2, Pubky 0.18.0 for the upstream signer contract, and companion Appium coverage, whose adjacent signup case does not exercise grant sign-in. Author's post-merge results

Device testing was not performed in this review. For J1, use the pinned dummy BASE on an unlocked to.bitkit.dev regtest wallet with Paykit UI enabled and a locally managed Pubky profile. Matching OWN must show Authorize and the expected profile key fragment, then Cancel. OTHER must show 8um7...1dty in the refusal with no Authorize button after five seconds. Repeated OWN, pubky-prefixed OWN, and not-a-public-key must each show the invalid-link toast with no Authorize button. Never tap Authorize or submit a grant. Pinned J1 fixture and steps

Suggested additional test cases

  • Android, with the same warm regtest wallet, replace the dummy grant's relay with the URL-encoded ftp://relay.example/inbox/. Open it once with OWN and once with OTHER. Expect the invalid-link toast and no consent in both cases. Add the same invalid-request assertion to the deeplink unit coverage. The existing combined view-model test supplies an already parsed request with a valid relay, so it cannot catch this precedence issue.

Findings

  • [LOW] Validate the relay before showing the signer mismatch — inline at app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt:10870.

Reviewer model: gpt-6.2-sol
Reasoning effort: low

@ovi-reviewer ovi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: ⛔️ Request changes — an unsupported relay gets a misleading signer-mismatch message.

Findings:

  • LOW — Validate the relay before showing the signer mismatch. AppViewModel.kt:10870 validates spk and returns the other-wallet message before the full request parser checks the relay. With relay=ftp://relay.example/inbox/, this wallet's signer correctly gets “This Pubky authorization link is invalid”; a foreign signer instead gets “This request is for 8um7...1dty, not this wallet's pubky.” Both are refused before consent. This confirms @piotr-iohk's existing finding; no duplicate inline finding.

QA for 7bb8bfd:

Dev regtest debug build, Android 11 emulator. Dummy requests were cancelled; Authorize was never tapped.

Accept this wallet and refuse foreign or invalid expected signers ✅ J1: matching and absent signers reach consent with the relay; foreign and malformed signers are refused.

Repeated, prefixed, malformed and empty spk produce invalid-link errors. The matching requests show this wallet's pubky and https://httprelay.pubky.app/inbox/. Error messages were checked in the recording and app log; consent and relay text were checked in fresh UI dumps.

j1-2x.2x.mp4
Keep signer and relay validation after the merge ✅ The [invalid-point fix](https://github.com//pull/2104#discussion_r4718316593) holds, and matching signers remain subject to relay validation.

ye followed by 50 y shows the invalid-link error; the app log confirms rejection in native normalizePubkyPublicKey. A matching signer with a malformed relay is refused. A matching signer with https://Relay.Example.com:8443/inbox/o'connor?token={abc} reaches consent, showing the complete lower-cased-host destination; exact text was checked in the UI dump. Consent was cancelled.

g1-2x.2x.mp4
Report unsupported relays as invalid for either signer ❌ An FTP relay gives different refusal reasons depending on the signer.

The recording shows the invalid-link toast for this wallet's signer, then the incorrect other-wallet toast for the foreign signer. Neither request exposes Authorize. The app log confirms Unreadable Pubky auth relay for the first request and the early signer-mismatch branch for the second.

g2-2x.2x.mp4
Check: build and authorization tests ✅ The head builds, focused authorization tests pass, and detekt and Android Lint pass.

Ran assembleDevDebug, testDevDebugUnitTest filtered to PubkyAuthRequestTest, PubkyRepoTest, PubkyAuthApprovalViewModelTest and AppViewModelSendFlowTest, plus detekt and lintDevDebug. The new signer/relay interaction test passes.

Not repeated: foreign-key cold-start/scanner refusal, invalid-point scanner rejection and setup refusal without creating a watch-only account rely on the passing review at 0f8fbc2; the merge leaves those guards and routing unchanged. Signing and relay delivery were not driven: the dummy-link journey stops before Authorize. Signing-time guards and the unchanged signup exemption were checked in the focused tests. Other locales were not driven.

Coverage: delta 0f8fbc2..7bb8bfd, the merge conflict resolutions, both parser test sets, translations and reached authentication callers. Unrelated changes inherited from master were outside this PR's review scope. The latest QA review supplied the FTP-relay case, independently reproduced here.

Twin: synonymdev/bitkit-ios#1492 at 45a49bb matches native signer validation, signing-time constraints and the signup exemption. Compared in code; no iOS device run here.


Reviewed by gpt-6.1-sol-high

@jvsena42
jvsena42 marked this pull request as draft November 27, 2026 11:57
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jvsena42
jvsena42 marked this pull request as ready for review November 27, 2026 12:39
@jvsena42
jvsena42 requested a review from piotr-iohk November 27, 2026 12:39

@ovi-reviewer ovi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: ✅ Approve

Findings: None. The earlier LOW finding is fixed: an unsupported relay now produces the invalid-link error for both matching and foreign signers.

QA for 465a470:

Dev regtest debug build, Android 11 (API 30), locally managed Pubky profile. Dummy requests were cancelled; Authorize was never tapped.

Report unsupported relays as invalid for either signer ✅ Both FTP-relay requests show the invalid-link error without consent.

Opened the complete dummy grant with relay=ftp://relay.example/inbox/, first with this wallet's signer and then with the foreign signer. Both show “This Pubky authorization link is invalid.” Fresh UI dumps confirm no Authorize button; app logs confirm InvalidUrl caused by Unreadable Pubky auth relay in both cases.

r1-2x.2x.mp4
Accept this wallet and refuse foreign or invalid expected signers ✅ J1 passes; matching and absent signers reach consent, while foreign and invalid values are refused.

Repeated, prefixed, malformed, empty and invalid-point (ye followed by 50 y) values produce invalid-link errors. The foreign key gets the refusal naming 8um7...1dty. Messages were checked in screenshots and app logs; consent, the profile key fragment and the relay were checked in fresh UI dumps. Both consent sheets were cancelled and their dismissal verified.

j1-2x.2x.mp4
Preserve the full valid relay for a matching signer ✅ A punctuated HTTPS relay opens consent for this wallet; a foreign signer is still refused.

The matching request shows https://relay.example.com:8443/inbox/o'connor?token={abc}; exact text was checked in the UI dump. The foreign request shows the other-pubky refusal with no consent. The matching sheet was cancelled.

r2-2x.2x.mp4
Check: build and authorization tests ✅ The head builds; focused authorization tests, detekt and Android Lint pass.

Ran assembleDevDebug, testDevDebugUnitTest filtered to PubkyAuthRequestTest, PubkyRepoTest, PubkyAuthApprovalViewModelTest and AppViewModelSendFlowTest, plus detekt and lintDevDebug.

The earlier relay-precedence finding is verified fixed. The author's current-head device check independently confirms the foreign-signer FTP refusal and valid HTTPS control.

Not repeated: cold-start and scanner refusal, invalid-point scanner rejection, and setup refusal without creating a watch-only account rely on the passing review at 0f8fbc2. Their entry routes and signing/preparation guards are unchanged; the shared deeplink pre-check is exercised above. Signing and relay delivery were not driven: the dummy-link journey stops before Authorize. Signing guards and the signup exemption remain covered by the focused unit tests. Other locales were not driven.

Coverage: delta 7bb8bfd..465a470, its three changed test files, the reached parser and authentication callers, and the open relay-precedence finding. No signing implementation or translated copy changed in this delta.

Twin: synonymdev/bitkit-ios#1492 at 45a49bb matches native signer validation, signing-time constraints and the signup exemption. Its handler parses before comparing signers; the relay validation in synonymdev/bitkit-ios#1502 at c9332b9 also precedes that comparison. Compared in code; no iOS device run here.


Reviewed by gpt-6.1-sol-high

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved 465a470. QA Watch verified the earlier findings were fixed and found no new actionable issues.

The Pixel 6 regtest retest passed. A valid matching signer opened consent and I dismissed it without submitting a grant. A valid foreign signer showed the mismatch message. Both unsupported FTP relay variants and the malformed signer cases showed the invalid-link message with no consent available.

The exact-head unit tests and lint passed. The replacement build check and required E2E are still running. Unit test job · E2E

@jvsena42
jvsena42 enabled auto-merge November 27, 2026 12:54
@jvsena42
jvsena42 merged commit 70b04f5 into master Nov 27, 2026
38 of 40 checks passed
@jvsena42
jvsena42 deleted the fix/pubky-auth-spk branch November 27, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refuse a Pubky auth request that names another pubky (spk)

4 participants