Repository navigation
fix: refuse pubky auth requests for another pubky - #1492
Conversation
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
[Medium impact] The PR appears safe to merge; no actionable issue was found. SummaryBitkit now reads
Intentional scope recorded from Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Receive auth link] --> B[Parse request and spk]
B -->|Invalid| C[Show invalid request message]
B --> D{Names another pubky?}
D -->|Yes, key known| E[Show refusal message]
D -->|No or key unknown| F[Open consent sheet]
F --> G[User approves]
G --> H[Compare spk with signing key]
H -->|Mismatch| E
H -->|Matches or absent| I[Continue approval]
Reviews (1) · Last reviewed commit: "docs: cite upstream spk scope in pubky a..." · Reviewed by Greptile |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Reads spk from sign-in requests, refuses a request naming another pubky before the sheet opens, and throws signerMismatch at every signing entry point before any signing or relay call. Reviewed 45a49bb, full tier.
What I checked, and 5 candidates I ruled out
Read in full: the diff of PubkyAuthRequest.swift, PubkyService.swift, AppViewModel.swift, PubkyAuthApprovalSheet.swift, the new tests in PubkyAuthRequestTests.swift and PubkyAuthApprovalSheetTests.swift
Call sites traced: approveAuth, approveAuthWithCompanionClaim, approveAuthRequest, approveSignupAuthorization, performAuthorization, handlePubkyAuthApproval, AdoptedPubkyReference.current
CI: SwiftFormat, translations validate and Greptile green; Run Tests, Run Integration Tests and build-local pending.
Build: Not built here: iOS does not build on Linux, so this review is reasoned from the code and from CI.
Ruled out
- A signing path that skips the check:
approveAuthRequestchecks before the USDT endpoint, watch-only preparation and both approvals, andapproveAuth/approveAuthWithCompanionClaimcheck again on entry, soapproveSignupAuthorization's grant branch is covered too. The Ring signup path (approveRingAuth) is a signup, which upstream does not hold tospk. - Prefix mismatch:
pubkyPublicKeyFromSecretmay returnpubky…(other call sites strip it), andisExpectedSignerdrops the prefix only for a 57-characterpubky…key;AdoptedPubkyReference.pubkyis the bare z32 Ring publishes. The test drives the prefixed form. - Bitkit handoff URLs bypassing the parser:
parse(url:)normalisesbitkit://pubky-auth/...topubkyauth://signin_grantbeforemakeRequest, and the sheet passesrequest.rawUrl, so the sign-time re-parse sees the same URL. - Repeated or hidden
spk: duplicate values throw, and any C0 or DEL character in the URL is rejected beforeURLComponentscan percent-encode it. - Locale placeholder:
pubky_auth__other_pubkycarries{pubky}in all 15Localizable.strings.
Merge confidence: 4/5, CI has not finished (Run Tests pending). The security path itself has tests for both the pre-sheet refusal and every signing entry point.
Reviewer model: Claude Opus 5.5 (claude-opus-5-5)
Reasoning effort: Not exposed (the run reports the model id only)
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: full PR diff against its merge base, at 45a49bb.
No new actionable code findings.
All changed surfaces were inspected against #1195, pinned pubky/paykit-rs (0b9c63d), upstream pubky/pubky-homeserver (d95161a), and twin synonymdev/bitkit-android#2104 at baeabb3. PubkyAuthRequest.parseExpectedSigner matches upstream canonical bare z-base-32 and Ed25519 key checks while rejecting ASCII control characters and duplicates and ignoring spk on signup links; AppViewModel.presentPubkyAuthApproval refuses foreign spk requests before consent (including ahead of the Ring hint for adopted identities); and every signing entry point (approveAuthRequest, approveAuth, approveAuthWithCompanionClaim) throws signerMismatch before USDT loading, watch-only preparation, identity republish, or relay calls. The new signin-expected-pubky.xml journey matches the Android twin and uses verified iOS accessibility identifiers. Existing PR reviews (talosmachina, Greptile) report no open concerns.
Validation and limitations: Executed node scripts/validate-translations.js locally at 45a49bb (0 errors across all 15 .lproj/Localizable.strings files). CI SwiftFormat and validate passed at 45a49bb. iOS Xcode build and BitkitTests could not be executed in this Linux review environment, and CI Run Tests, Run Integration Tests, and build-local were still in progress when checked.
Recommended before device testing
- Wait for CI Run Tests and Run Integration Tests at 45a49bb to finish green.
Device testing: not performed in this review. The author reports passing simulator screenshots for cases 1–7 at 45a49bb (noting that Settings > Watch-Only Accounts was not checked for case 6); J1 (signin-expected-pubky.xml) still requires QA execution.
Suggested additional test cases
- iOS — Paykit
/setuphandoff with foreignspkleaves watch-only accounts unchanged: On an onboarded regtest build with a local Pubky identity, note the current entries in Settings > Watch-Only Accounts, then openbitkit://pubky-auth/setup?caps=<Paykit required capabilities>&relay=https%3A%2F%2Fhttprelay.pubky.app%2Finbox%2F&secret=e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3s&cid=paykit.test&cpk=5jsjx1o6fzu6aeeo697r3i5rx15zq41kikcye8wtwdqm4nb4tryo&x-bitkit-claim=watch-only-account-v1&spk=8um71us3fyw6h8wbcxb5ar3rwusy1a6u49956ikzojg3gcwd1dty. Expected:PubkyAuthOtherPubkyToastshowsThis request is for 8um7...1dty, not this wallet's pubky., neitherPubkyAuthWatchOnlyConsentnorPubkyAuthAuthorizeopens, and Settings > Watch-Only Accounts remains unchanged.
Reviewer model: gemini-4-neon
Reasoning effort: high
There was a problem hiding this comment.
Verdict: ✅ Approve
Findings: None.
QA for 45a49bb: Debug regtest build, E2E mode, iPhone 17 Pro simulator on iOS 27.0.
Sign in with the expected pubky (J1) ✅ Matching spk opened approval with the wallet's pubky; foreign, repeated, prefixed and malformed values were refused.
Drove signin-expected-pubky.xml: copied the profile pubky, confirmed the matching approval card, and cancelled. The foreign-key toast named 8um7...1dty, with no approval sheet after five seconds. Repeated, prefixed and malformed spk showed PubkyAuthInvalidRequestToast without an Authorize button. Nothing was authorized.
signin.2x.mp4
Refused setup leaves watch-only accounts unchanged ✅ The foreign-key setup request opened no consent sheet, and Server Accounts stayed empty after reopening it.
Checked the additional case requested in the QA review. The /setup handoff carried watch-only-account-v1 and the foreign spk. The refusal named the other pubky, neither consent nor Authorize appeared, and Settings → Advanced → Server Accounts remained at zero after reopening the list.
setup.2x.mp4
Auth parser and signing checks ✅ The focused XCTest suites passed; assertions were checked in XCTest output.
Ran xcodebuild test for PubkyAuthRequestTests, PubkyAuthApprovalSheetTests and PubkyAuthURLSchemeTests. They cover malformed and repeated keys, prefix handling, signup exemptions, pre-sheet refusal, and rejection before ordinary/companion approval or watch-only preparation. The recording shows the hosted test app; the pass result comes from XCTest output.
auth-unit.2x.mp4
Live relay delivery was not driven: the journey uses dummy requests and stops before authorization. The author's Preview and Evidence cover the unchanged no-spk and scanner-paste cases; those were not repeated here.
Reviewed the full edce3cd..45a49bb diff, all 24 changed files, and the ordinary, companion, signup and Ring approval paths. Sign-time guards and signup exemptions were exercised by XCTest rather than live relay approval. This agrees with the existing code review. SwiftFormat and translation validation passed.
Twin: synonymdev/bitkit-android#2104 at baeabb3 matches the validation and refusal behavior; iOS uses its dedicated bitkit://pubky-auth handoff.
Reviewed by gpt-6.1-sol-high
|
Merged: approved on 45a49bb, J1 and the refused setup case passed on a simulator run of that head, checks green, no open threads. |
Fixes #1195
Twin: synonymdev/bitkit-android#2104
Grant sign-in links (
pubkyauth://signin_grant, and Bitkit'sbitkit://pubky-auth/signinand/setuphandoffs) can carryspk=<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
spkis read from the request's own query. Absent is fine. A repeatedspk, an empty one, or anything other than a bare canonical 52-character z-base-32 key (so alsopubky…/pk:prefixes, upper case, URL forms, padding variants) makes the request invalid, matchingparse_expected_signerin the Pubky SDK (feat(sdk): let grant sign-in links require an expected identity pubky/pubky-homeserver#787). Signup requests ignorespk, 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.spknames 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."spkwith 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.spkis this wallet's pubky behaves exactly as a request withoutspk.PubkyAuthRequest.parseExpectedSignerandexpectedSigner;AppViewModel.presentPubkyAuthApprovalshows the toast (idPubkyAuthOtherPubkyToast) instead of the sheet;PubkyService.approveAuthRequest,approveAuthandapproveAuthWithCompanionClaimthrowPubkyAuthRequestError.signerMismatchbefore any signing call. New stringpubky_auth__other_pubkyin English and all 14 other locales.Where the parsing belongs
Both apps parse grant links with
parse_pubky_auth_urlfrom pubky/paykit-rs (paykit-sdk/src/pubky_session.rs), not bitkit-core.paykit0.1.1-rc9 pinspubky0.16.2, which predatesspk(added in pubky-homeserver v0.18.0), so today it ignores the parameter andPubkyAuthDetailshas no field for it. The parsing in this PR is an app-side stopgap. Once paykit-rs moves to an SDK withexpected_signerand exposes it onPubkyAuthDetails, the SDK parser rejects malformed links andPubkySignerrefuses a mismatch itself; the app then only needs the field for the message, and this parser can go.Out of Scope
expected_signerfromparse_pubky_auth_urland moving to a Pubky SDK that knowsspk; this PR does not change the dependency.PubkyAuthApprovalSheet.swift: 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
Simulator run on iPhone 17 Pro (iOS 26.5), Debug regtest build at 45a49bb. Authorize was never tapped.
QA Notes
Setup
Debug simulator build (regtest), wallet onboarded, a Pubky profile created in Bitkit. Read the wallet's pubky with Profile > Copy (
ProfileCopy) andxcrun simctl pbpaste <UDID>;OWNis the 52 characters after thepubkyprefix. All links are dummy requests: do not tap Authorize.Journeys
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 (PubkyAuthOtherPubkyToast); a repeated, prefixed or malformedspkis an invalid request (PubkyAuthInvalidRequestToast)Manual Tests
N/A
Automated Checks
PubkyAuthRequestTests.swift—spkabsent, matching, repeated, malformed, prefixed, non-canonical, throughpubkyauth://signin_grantand thebitkit://pubky-auth/signinhandoff; control characters cannot hide it; a canonical value that is not a public key is invalid; signup requests ignore it; sign-in links the URL parser reads differently are still held to it; prefix handling when matchingPubkyAuthApprovalSheetTests.swift— a request naming another pubky shows the refusal toast and opens no sheet, with or without a readable key; it throws before the ordinary or companion approval runs and prepares no watch-only account;approveAuthandapproveAuthWithCompanionClaimrefuse it before anything else; a matching request opens the sheet and is approved; a grant signup with an existing identity is approved whatever itsspksays; the message names the pubkyEvidence
Simulator device run: cases 1 to 7 pass, see Preview. Expected log lines were not confirmed.
Local checks at
6186f224a:xcodebuild test -scheme Bitkit -configuration Debug -destination 'platform=iOS Simulator,name=iPhone 17' -only-testing:BitkitTests— 4646 passed, 5 failed. The 5 failures areAddressTypeIntegrationTests(3) andUtxoSelectionTests(2), which need a local regtest electrs ("LocalRegtest funds the local bitcoind, but the node syncs from ssl://electrs.bitkit.stag0…"); they do not touch this change.PubkyAuthRequestTests,PubkyAuthApprovalSheetTestsandPubkyAuthURLSchemeTestspassed.swiftformat --linton the changed Swift files — 0 files require formatting.node scripts/validate-translations.js— 0 errors.Gaps
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:
spk(iOS).URLComponentspercent-encodes a literal tab or line break, sos<TAB>pk=was not read asspk, while the SDK's parser drops those characters. Fixed on iOS: any ASCII control character makes the request invalid. Android'sjava.net.URIalready rejects them; a test now asserts it.spkthat 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 (Paykit.normalizePubkyPublicKey).approveAuthRequest.handlePubkyAuthApprovalnow ends inpresentPubkyAuthApproval, which a test drives directly (toast shown, no sheet). Added a test that asignup_grantwith an existing identity is approved with a foreign, malformed or repeatedspk.spk, including legacysigninlinks 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_grantignoresspk. Confirmed against upstream, pubky/pubky-homeserver atd95161af3e:pubky-sdk/src/actors/auth/deep_links/signin_grant.rs:106is the only caller ofparse_expected_signer(query_params.rs:79),signup_grant.rsnever readsspk,deep_link.rs:211tests thatsigninandsignup_grantignore it, anddocs/AUTH.md:81scopes it topubkyauth://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 #1502 edit neighbouring lines of the same files. Merge #1502 first; this PR then needs a rebase, keeping both sides of each conflict.
Models used
claude-fable-5-2(reasoning:Not exposed)claude-fable-5-2(reasoning:Not exposed)claude-fable-5-2(reasoning:Not exposed)Metadata note: the sessions report the model id but no reasoning setting; the reviewer model is as reported by the coordinating session.
🤖 Generated with Claude Code