Skip to content

fix: validate profile links against pubky.app rules - #1503

Merged
jvsena42 merged 8 commits into
masterfrom
fix/profile-link-validation
Nov 28, 2026
Merged

jvsena42 merged 8 commits into
masterfrom
fix/profile-link-validation

Conversation

@jvsena42

@jvsena42 jvsena42 commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Fixes #1301
Twin: synonymdev/bitkit-android#2126

Edit Profile's Add Link sheet accepted any nonblank label and URL, but Paykit refuses to publish a profile to pubky.app when a link's title is over 100 Unicode code points, its URL is over 300, or the URL does not parse. Because the publisher checks every link whenever the link list changes, one bad link blocked saving all other edits with a generic error (Greptile finding).

Description

  • The rules come from Paykit v0.1.1-rc9 (paykit-sdk/src/domain/contacts/pubky_app.rs, validate_links), which re-implements the pubky-app-specs PubkyAppUserLink rules: title trimmed, non-empty, no control characters, at most 100 chars; URL trimmed, at most 300 chars, url::Url::parse must succeed; on a social v1 profile the URL must also be http(s):// with a host. The Paykit bindings expose no validator, so the app checks the same rules itself, after the normalization the save already does (bare domain gains https://).
  • Add Link (profile) shows an inline error on the field that needs fixing and keeps Save disabled: "Label must be 100 characters or fewer.", "Link must be 300 characters or fewer.", or "Enter a valid web link, such as example.com.". Bare domains are accepted; email and phone stay refused on the profile sheet, as on master (social v1 profiles reject them).
  • Edit Profile: once the link list changes, every link, stored ones included, is checked; a stored link that breaks a rule (saved before this fix or by another client) shows the error under its row and Save is disabled until it is fixed or removed. Unchanged links are not sent, so they never block a save.
  • If pubky.app still refuses a link at save time (a social v1 profile with a stored mailto: link), the toast names the link ("Fix the link to save your profile.") and that row is marked, instead of the raw Paykit error.
  • The URL check is a WHATWG-style reading of what url::Url::parse refuses (a control character, an empty or forbidden-character host on a special URL, a port over 65535, a host ending in a non-IPv4 all-digit label). Paths and queries the parser accepts, such as ?q=a|b, a bare % or brackets, are accepted, so profiles that saved before still save. The same check runs on both apps.
  • A label that is empty once control characters are removed is refused. A stored row whose label pubky.app refuses says "This link's label can't be saved. Remove the link and add it again.", as form rows edit only the URL.
  • Only Paykit's exact non-web link refusal (pinned to Paykit 0.1.1-rc9 in one constant with a test) marks a row; other link refusals show the plain save error with no row marked.
  • Link normalization moved out of the profile store into a shared helper so the sheet, the form and the save use one implementation.
  • New strings added to every locale; copy is identical to the Android twin.

Out of Scope

  • Known rare differences from url::Url::parse, left as they are: a percent-encoded host (https://%65xample.com) is refused, as are hex or octal IPv4 forms; invalid IDNA and malformed IPv6 hosts are accepted here and refused by Paykit; ports on file: URLs are not checked. None of these are links people type.
  • Contacts → Add Link: contact links are not published to pubky.app, so the sheet keeps accepting any text there.
  • Profile name, bio and link-count limits: already enforced by the form.

Design

Add Link populated (Handoff v63, Profile). Figma has no error state, so the error uses the app's existing inline field error (red text under the field, as in Add Contact).

Preview

Device screenshots: pending device run.

QA Notes

Setup

Dev/regtest build of this branch. A disposable wallet signed in to a Pubky profile with at most four links, PIN off, English. No funds needed.

Journeys

  • J1: new profile-link-validation.xml — Add Link shows an inline error and keeps Save disabled for an invalid URL or an email, and accepts a bare domain

Manual Tests

  • 1. Add Link with a 101-character label and example.com → label error, Save disabled; 100 characters → accepted — long text input is not reliable through the journey runner
  • 2. Add Link with example.com/ plus 281 a (301 with https://) → URL length error; one fewer → accepted — long text input is not reliable through the journey runner
  • 3. Profile with a stored link that breaks a rule → no error while links are unchanged; after adding a link, the stored row shows the error and Save is disabled; removing it re-enables Save — needs a profile written outside this build

Automated Checks

  • added PubkyAppLinkTests.swift — 100/101 code points with emoji, 300/301 after normalization, invalid URLs, normalizable inputs, web-only refusal, |/%/brackets in paths, forbidden host characters, ports over 65535, control characters, empty labels, stored links without a host, stored-link checks and the rejection mapping pinned to Paykit 0.1.1-rc9

  • added PubkyAppLinkTests.swift — a URL edit that normalizes to the stored link leaves stored links unchecked

  • added PubkyAppLinkTests.swift — a refusal stays on its link until that link changes

Evidence

Device screenshots: pending device run.

Local, commit db99adb2c: xcodebuild test with -only-testing PubkyAppLinkTests, PubkyAppProfileStoreTests, WebLinkTests on the iPhone 17 Pro simulator: 33 tests, 0 failures. SwiftFormat lint on the changed Swift files: clean.

Gaps

Device cases J1 and 1-3 not run yet (pending device run). Case 3 needs a profile with a stored invalid link, which this build cannot create.

Review

Independent review by claude-opus-5-5, round 1, at the first commit. No HIGH findings; the label rules, code-point counting and normalize-then-validate order matched Paykit. Fixed in 30c9c9578:

  • MEDIUM: Android validated URLs with java.net.URI, which refuses |, brackets, braces, ^, " and a bare % that url::Url::parse accepts, so a stored link such as https://example.com/?q=a|b would block Save; a failed parse also produced https://https://…. Both apps now use the same WHATWG-style check and detect the scheme with a regex.
  • LOW: ports over 65535, control characters in a URL (iOS), https:// with no host on stored rows (iOS), and labels made only of control characters were accepted although Paykit refuses them. All refused now, with tests.
  • LOW: any "Pubky profile link" refusal marked the first non-web row. Only the exact non-web context does now, kept in one constant pinned to Paykit 0.1.1-rc9 with a test.
  • LOW: a stored label over 100 characters showed the length message under the URL field, which cannot edit the label. The row now says to remove the link and add it again.
  • LOW (Android only): isWebLink alignment; iOS already accepted IDN and underscore hosts.

Round 2, re-review by claude-opus-5-5 of round 1. Fixed in 61978829b:

  • MEDIUM: the IPv4 check refused https://example.com., which saved before and Paykit accepts; one trailing dot is now dropped before it.
  • LOW: isWebLink used URLComponents while Android uses the hand-written check. iOS now uses the same check, requiring // after the scheme and no \ in the authority, so https:example.com is refused on both apps.
  • LOW: control characters are dropped from the label as they are typed, as on Android.
  • LOW: percent-encoded hosts and the other rare parser differences are noted under Out of Scope.

Round 3, re-review by claude-opus-5-5 of round 2. Fixed in cb512b9dd:

  • MEDIUM: isWebLink accepted an empty authority with extra slashes (https:///example.com, https:////example.com, and /example.com, which becomes https:///…), which Paykit refuses. The host is now read as Paykit's is_social_v1_web_uri reads it (authority up to /, ? or #, after the last @, up to : unless it starts with [) and must be non-empty; https://. and https://.. are refused too.
  • LOW: control characters in a typed or pasted label now become spaces, as singleLine does, so Line1\nLine2 keeps its word break.

Round 3 result, re-review by claude-opus-5-5 of round 3: no HIGH or MEDIUM. LOW findings fixed in 96785bbef:

  • The migration filter checked only the http(s):// prefix, so a legacy https:///example.com passed it and failed the save. It now uses a Paykit-exact predicate (is_social_v1_web_uri: lowercase http:// or https://, no control or whitespace character, non-empty host).
  • The save-rejection mapping used the stricter input check, so a stored https://localhost or https://[::1] could be blamed. It now uses the same Paykit-exact predicate on the normalized URL; isWebLink stays for input.
  • Added NBSP, U+2007 and U+202F cases to WebLinkTests, matching Android.

Review round (Greptile):

  • Stored links were checked against the raw form values while the save compares normalized ones, so a URL edit that normalizes back to the stored link (for example https://example.com to example.com) could block a save with a stored over-long label. Verdict: real. Fixed in c9c492466.
  • A refusal was cleared by editing any link, so the refused row lost its error and the next save failed on it again. Verdict: real. The refusal is now kept on the refused link until that link is edited or removed. Fixed in db99adb2c.
  • Both fixes are on the twin as well (synonymdev/bitkit-android b503a4229, c53b977da).

Models used

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

The session metadata available to the agent names the model but not a reasoning setting.

🤖 Generated with Claude Code

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

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; the latest changes address the reported problems without introducing a new actionable issue.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the latest changes address the reported problems without introducing a new actionable issue.

Summary

Adds profile-link checks, inline errors, translated messages, and regression tests.

  • Profile links show rule-specific errors before they can be added.
  • Edit Profile points to links that stop a profile save.

Reviews (2) · Last reviewed commit: "fix: keep a pubky.app link refusal on it..." · 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. Validates Edit Profile and Add Link input against the link rules Paykit 0.1.1-rc9 applies before publishing to pubky.app (title, URL length, url::Url::parse, the social v1 web-URL rule), and maps Paykit's non-web refusal to the offending row. Reviewed 96785bbef, full tier, static only: Bitkit iOS does not build on this reviewer's Linux machine, so this is reasoned from the code and CI.

What I checked, and 6 candidates I ruled out

Read in full: PubkyAppProfileStore.swift (the link helpers, fitted, normalized, update(from:base:)), PubkyProfile.swift, AddLinkSheet.swift, EditProfileView.swift, ProfileEditFormView.swift, PubkyAppLinkTests.swift, WebLinkTests.swift
Compared against: Paykit v0.1.1-rc9 paykit-sdk/src/domain/contacts/pubky_app.rs (validate_links, max_chars, uri, validate_social_v1_update, is_social_v1_web_uri), the version Package.resolved pins
Call sites traced: both ProfileEditFormView( callers (Edit Profile, Edit Contact), every linkUrl( and isWebLink caller
CI: SwiftFormat failed on a segfault of swiftformat_linux (exit 139), and the same head passed the lint workflow at 17:56; build-local failed its "Checked-out merge does not match the PR's current base and head" step, a checkout race, not a build error. Unit and integration tests were still running at review time.

Ruled out

  • isSocialV1WebUrl drifts from Paykit: same lowercase prefix, ASCII-control and Unicode White_Space refusal, last-@ split and [/: host read as is_social_v1_web_uri.
  • Label or URL counted differently: Paykit counts chars(), the app counts unicodeScalars, and the label is checked after singleLine, which is what normalized sends.
  • Row refusal points at the wrong link: rejectedLinkIndex re-applies linkUrl(...) ?? url, the exact transform normalized applies before the publish.
  • Unchanged stored links blocked: linkErrors returns empty while the links equal the stored ones, and update(from:base:) sends links: nil then, so Paykit skips validate_links.
  • Edit Contact loses its old behaviour: it passes neither webLinksOnly nor linkErrors, so Save keeps its name-only gate as on master.
  • Static members of the actor called from views: static members are not actor-isolated, and the new static lets are Sendable.
  • The rejected-row reset on any link edit is already raised by Greptile on EditProfileView.swift.

Merge confidence: 3/5, CI is red for reasons not tied to the diff (a SwiftFormat crash, a merge-checkout mismatch) and the unit tests had not finished.

Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the runtime does not report a reasoning setting for this session)

@jvsena42
jvsena42 marked this pull request as draft November 26, 2026 19:54
jvsena42 and others added 2 commits November 26, 2026 17:00
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jvsena42
jvsena42 marked this pull request as ready for review November 26, 2026 21:36

@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.

QA for db99adb: Debug/regtest build on iPhone 17 Pro 2x, iOS 27.0, English, disposable unfunded wallet and staging Pubky profile.

J1: Reject invalid links and save a bare domain ✅ Invalid URL and email kept Save disabled; example.com saved as https://example.com with the Profile updated toast.
J1-2x.2x.mp4
1: Enforce the label length limit ✅ 101 code points showed an error and disabled Save; 100 cleared the error and enabled Save.

Input lengths were checked from accessibility values.

label-2x.2x.mp4
2: Enforce URL length after normalization ✅ 301 code points after adding https:// showed an error and disabled Save; 300 cleared the error and enabled Save.

Input lengths were checked from accessibility values.

url-2x.2x.mp4
3: Identify a stored invalid link after links change ✅ With a seeded invalid loaded link, adding Blog marked the invalid row and disabled Save; removing that row enabled Save again.

The unchanged invalid link initially showed no error and left Save enabled. This case used db99adb plus a local debug hook to seed the loaded form state; it did not create an invalid remote profile.

stored-2x.2x.mp4
Test hook

Not pushed. Seeds Legacy invalid in the editor's current and stored link arrays; validation and Save decisions are unchanged.

diff --git a/Bitkit/Views/Profile/EditProfileView.swift b/Bitkit/Views/Profile/EditProfileView.swift
index 003a3f6fd..697991599 100644
--- a/Bitkit/Views/Profile/EditProfileView.swift
+++ b/Bitkit/Views/Profile/EditProfileView.swift
@@ -172,6 +172,14 @@ struct EditProfileView: View {
         links = profile.links.map { ProfileLinkInput(label: $0.label, url: $0.url) }
         storedLinks = profile.links.map { PubkyProfileData.Link(label: $0.label, url: $0.url) }
         rejectedLink = nil
+        #if DEBUG // test hook
+            if ProcessInfo.processInfo.arguments.contains("-review-invalid-link") { // test hook
+                let invalid = PubkyProfileData.Link(label: "Legacy invalid", url: "not a url") // test hook
+                links.append(ProfileLinkInput(label: invalid.label, url: invalid.url)) // test hook
+                storedLinks.append(invalid) // test hook
+                Logger.info("Test hook seeded Legacy invalid in current and stored links", context: "Review1503") // test hook
+            } // test hook
+        #endif // test hook
         tags = profile.tags
         baseRevision = profile.revision
         baseTagsUnread = profile.tagsUnread
INFOℹ️: Test hook seeded Legacy invalid in current and stored links - Review1503 [EditProfileView.swift: loadProfileData() line: 180]
Check: Link validation and profile publishing helpers ✅ Targeted unit tests, changed-file SwiftFormat 0.64.6 lint and translation validation passed.

Ran PubkyAppLinkTests, PubkyAppProfileStoreTests and WebLinkTests, including refusal retention, normalized unchanged links, Unicode limits and publisher error mapping.

No planned case was left unrun.

Full review: edce3cd..db99adb, including profile/contact form callers, normalization, publishing, migration, locale additions and test isolation. The migration branch and save-time non-web refusal were checked through code and unit tests; device cases cover pre-save validation and normal publication. The rare parser differences listed under Out of Scope remain outside this review.

Twin: synonymdev/bitkit-android#2126 matches the validation, normalization and refusal-retention behavior inspected here; Android was not device-tested in this run.

The earlier static review covered 96785bb. The refusal-retention fix was checked at db99adb against the view and regression test.


Reviewed by gpt-6.1-sol-high

@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

@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 db99adb.

No new actionable code findings.

All link normalization, validation, social v1 predicate, and Paykit rejection-mapping changes match pinned Paykit v0.1.1-rc9 (pubky/paykit-rs paykit-sdk/src/domain/contacts/pubky_app.rs, 0b9c63d) and align with the Android twin synonymdev/bitkit-android#2126 at c53b977. EditContactView keeps unrestricted contact links, and journeys/profile/profile-link-validation.xml identifiers match both platforms. The previously resolved Greptile thread (#discussion_r4712407195) is verified fixed at db99adb: EditProfileView retains rejectedLink by value across unrelated edits and row removals, backed by PubkyAppLinkTests.testRefusalStaysOnItsLinkUntilThatLinkChanges.

Validation & limitations: Local node scripts/validate-translations.js passed with 0 errors across all 15 locales. On db99adb, CI Run Tests, Run Integration Tests, SwiftFormat, and validate passed. build-local failed its pre-build merge-ref freshness check (Checked-out merge does not match the PR's current base and head, unrelated to the diff). Native Swift compilation and Xcode tests could not be run locally on this Linux host, and visual layout of inline error text inside AddLinkSheet and ProfileEditFormView was not verified at runtime.

Suggested additional test cases

  • iOS — Contacts → Add Link remains unrestricted: Open an existing contact → Edit Contact → Add Link, enter a non-empty label with me@example.com or not a url, and confirm no inline link error appears and Save remains enabled.
  • iOS — Social v1 save-time refusal stays on its row: On a social v1 profile with a stored non-web link (e.g., mailto:a@example.com) and another valid link, add a new web link and tap Save; confirm the error toast names the non-web link and marks its row, editing or removing another row keeps that row marked and Save disabled, and fixing or removing the marked link re-enables Save.

Ready for device testing.

Device testing: not performed in this review (code-only). ovi-reviewer's review reports running J1 and manual cases 1–3 on db99adb (with case 3 seeded via a local debug hook).

Reviewer model: gemini-4-neon
Reasoning effort: high

github-actions Bot added a commit that referenced this pull request Nov 27, 2026
{"kind":"bitkit-retarget-execution-v1","repository":"synonymdev/bitkit-ios","pr":1503,"generation":"45964992159-1","sourceSha":"003a8dc146e649f4534472458f04dc1f697f76de","sourceRef":"003a8dc146e649f4534472458f04dc1f697f76de","owner":"github-actions[bot]"}
@jvsena42
jvsena42 enabled auto-merge November 27, 2026 12:55

@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 at bb396f5, re-reviewed because the comparison base moved to 676956b. The head adds only a merge of master. The PR's own source, test and journey files are byte-identical to the previously reviewed db99adb.

No new actionable code findings.

The new link rules match Paykit 0.1.1-rc9 (paykit-sdk/src/domain/contacts/pubky_app.rs at 0b9c63d), the version Package.resolved pins. That covers the label and URL limits counted after Paykit's trim, the refusal of control characters, the empty-title rule, the web-only (social v1) predicate, and the order of the generic and social v1 checks. The exact error text the app matches to mark a refused link reaches the app unchanged. The save path still sends links only when they differ from the stored ones after normalization, and the form gate uses the same comparison. Edit Contact still accepts any link text.

Validation and limits: I extracted the link helpers from the pinned source into a Linux Swift 6.4.2 package (Paykit error type stubbed) and ran the PR's PubkyAppLinkTests and WebLinkTests there: 23 tests, 0 failures. This is Linux Foundation, not an iOS build. A wider probe of common inputs (bare domains, IDN, | and % in queries, ports, trailing dot, email, phone) gave the expected accept or refuse result. scripts/validate-translations.js passes for every locale. crates.io was not reachable from this sandbox, so I could not run url::Url::parse itself. The rare parser differences the PR lists as out of scope remain unverified at runtime. At this head, CI Run Tests, Run Integration Tests and build-local were still pending.

Parity: Compared with the Android twin synonymdev/bitkit-android#2126 at c53b977: journeys/profile/profile-link-validation.xml is identical on both platforms. Stored-link checking, the unchanged-links short-circuit and keeping a refusal on its link match too.

Existing threads: The Greptile thread on a refusal being cleared by unrelated edits is marked resolved, and the fix holds at this head. rejectedLink is kept by value and is set only when the form still matches the saved links. Its regression test passed in the Linux run.

Recommended before device testing: let the pending Run Tests, Run Integration Tests and build-local jobs finish at bb396f5.

Device testing: not performed in this review. ovi-reviewer reports J1 and manual cases 1–3 passing on db99adb (case 3 with a locally seeded invalid link). The current head differs from it only by the master merge, which does not touch the PR's files.

Suggested additional test cases

  • iOS, social v1 profile with a stored mailto: link written outside Bitkit: add a valid web link and tap Save. Expected: the toast reads "Fix the link to save your profile." and only the mailto: row shows ProfileEditLinkError_<index>. Then edit a different row's URL. Expected: the mailto: row stays marked and Save stays disabled until that row is edited or removed.

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

@jvsena42
jvsena42 merged commit 5afa337 into master Nov 28, 2026
20 of 21 checks passed
@jvsena42
jvsena42 deleted the fix/profile-link-validation branch November 28, 2026 01:51
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.

[Bug]: Invalid profile links can prevent saving an existing profile

4 participants