Skip to content

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

Merged
ovitrif merged 7 commits into
masterfrom
fix/profile-link-validation
Nov 27, 2026
Merged

ovitrif merged 7 commits into
masterfrom
fix/profile-link-validation

Conversation

@jvsena42

@jvsena42 jvsena42 commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Fixes #1882
Twin: synonymdev/bitkit-ios#1503

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.
  • isWebLink uses the same check, so IDN and underscore hosts (bücher.de, my_site.example.com) are accepted as web links, as on iOS. Localhost and IP hosts are unchanged.
  • New strings added to every locale; copy is identical to the iOS 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 PubkyAppLinkTest.kt — 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

  • updated WebLinkTest.kt — IDN, underscore and query-with-| hosts are web links

  • updated PaykitExceptionExtTest.kt — only Paykit 0.1.1-rc9's exact non-web link context is a non-web link rejection

  • updated EditProfileViewModelTest.kt — a stored URL the parser accepts does not block the save, another link refusal marks no row, unchanged stored links are not checked, a bad stored link blocks the save once links change, an added link is held to the limits, a Paykit link refusal points to the stored non-web link

  • added EditProfileViewModelTest.kt — a url edit that normalizes to the stored link leaves stored links unchecked

  • added EditProfileViewModelTest.kt — a pubky app refusal stays on its link until that link changes

Evidence

Device screenshots: pending device run.

Local, commit c53b977da: compileDevDebugKotlin, detekt and lintDevDebug pass. Unit tests EditProfileViewModelTest (26), PubkyAppLinkTest (11) and PubkyRepoTest (259): 0 failures. The full unit suite was not run (shared machine, targeted classes only).

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 6593d03ac:

  • 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 isWebLink refused IDN and underscore hosts; it now uses the same check.

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

  • MEDIUM: isWebLink accepted https:example.com, https:/example.com and https:\\example.com, as WHATWG skips slashes after a special scheme, while Paykit needs the literal http:// or https://. It now requires // after the scheme and no \ in the authority.
  • LOW: a trailing-dot host (https://example.com.) was refused; one trailing dot is now dropped before the IPv4 and top-label checks.
  • LOW: a control-only label left Save disabled with no message; control characters are now dropped as they are typed, so the field reads as empty.
  • LOW: percent-encoded hosts and the other rare parser differences are noted under Out of Scope.
  • Nits: removed the inline comment in Content; the URL check reuses URI_SCHEME.

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

  • 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.
  • LOW (not reproduced): NBSP-like characters (U+00A0, U+2007, U+202F) already count as whitespace, because Kotlin's Char.isWhitespace also checks Character.isSpaceChar. Tests added to WebLinkTest; no code change.

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

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

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 b503a4229.
  • 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 c53b977da.
  • Both fixes are on the twin as well (synonymdev/bitkit-ios c9c492466, db99adb2c).

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>
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from c53b977 (run).

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

jvsena42 and others added 4 commits November 26, 2026 13:26
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: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 latest changes appear safe to merge and address the reported link-error problems.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest changes appear safe to merge and address the reported link-error problems.

Summary

This PR checks profile links before saving and shows errors beside the fields that need fixing.

  • Add Link checks profile labels and URLs before they can be added.
  • Edit Profile marks links that would stop a changed profile from saving.
  • Profile publishing and migration use the same URL rules as profile editing.

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 profile links against the pubky.app rules Paykit enforces (title and URL length, a URL url::Url::parse accepts, http(s) only for new links), shows the error inline in Add Link and under stored rows once the link list changes, and moves link normalization into PubkyAppLink.kt. Reviewed 381aca948, full tier.

What I checked, and 4 candidates I ruled out

Read in full: PubkyAppLink.kt, String.kt (isWebLink), PaykitExceptionExt.kt, EditProfileViewModel.kt, AddLinkSheet.kt, the save and fitted paths of PubkyRepo.kt.
Moved code: singleLine, toPubkyAppLinkUrl, isEmailAddress, isPhoneNumber moved from PubkyRepo to PubkyAppLink.kt; the only behaviour change there is scheme detection by regex instead of java.net.URI, which the body names.
Call sites traced: isWebLink (now only pubkyAppLinkError), toPubkyAppLinkUrl (save, fitted, rejectedLinkIndex), isSocialV1WebUri (fitted, rejectedLinkIndex).
CI at this head: lint and Greptile green; build-and-test and compose-ui 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

  • Stored invalid link blocking an unrelated save: linkErrors is empty while links == storedLinks, and PubkyRepo sends links only when they differ from the base, so an untouched bad link never blocks name or bio edits.
  • Stale row mark after an edit: rejectedLinkIndex is cleared on add, edit and remove, so a mark never points at a shifted row.
  • Validation stricter than the save: the check runs on the same normalized URL the save sends (toPubkyAppLinkUrl), so a bare domain is measured with its https://.
  • Contact links: webLinksOnly stays false there, so Contacts keeps accepting any text, as stated.

Merge confidence: 4/5, no findings and the rules are covered by PubkyAppLinkTest.kt and EditProfileViewModelTest.kt, but build-and-test is 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)

@jvsena42
jvsena42 marked this pull request as draft November 26, 2026 19:54
jvsena42 and others added 2 commits November 26, 2026 16:57
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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: 💬 Comment — draft candidate verified at c53b977; no findings.

Findings: None.

QA for c53b977: DevDebug on Android 16 (API 36.1), staging/regtest, disposable unfunded profile. J1 and manual cases 1–2 used the pristine build; manual case 3 used the input-seeding hook below.

Reject malformed profile links and save a bare domain ✅ Malformed text and email were refused; a bare domain saved successfully.

J1: the inline URL error disabled Add Link Save for not a url and me@example.com. example.com cleared the error and enabled Save. The profile showed “Profile saved”, and reopening the editor showed https://example.com.

J1-2x.2x.mp4

Enforce the label length limit ✅ 100 code points were accepted and 101 refused, with both ASCII and emoji.

Manual 1: both 101-character inputs showed the label error and disabled Save; reducing either to 100 cleared it and enabled Save. Counts were checked by comparing the field's full UI text with the exact input strings.

1-2x.2x.mp4

Count the URL scheme in the length limit ✅ 300 normalized code points enabled Save; 301 showed the length error.

Manual 2: example.com/ plus 281 ASCII characters was refused; 280 was accepted. The exact field text was checked, and the count includes the eight-character https:// prefix.

2-2x.2x.mp4

Check stored invalid links only when links change ✅ The stored row blocked Save after adding a link, and removing it enabled Save.

Manual 3, with the hook: a stored 101-character label showed no error while unchanged, including after changing its URL from https://example.com to the equivalent example.com. Adding a valid Blog link marked the stored row with remove-and-add guidance and disabled Save. Removing that row cleared the error and enabled Save.

The hook only seeds the editor's loaded input; validation is unchanged. This checks the form behavior, without publishing a synthetic invalid profile or creating one through another client.

3-2x.2x.mp4

Test hook — not pushed
diff --git a/app/src/main/java/to/bitkit/ui/screens/profile/EditProfileViewModel.kt b/app/src/main/java/to/bitkit/ui/screens/profile/EditProfileViewModel.kt
index 226709f9a..c65e6bd84 100644
--- a/app/src/main/java/to/bitkit/ui/screens/profile/EditProfileViewModel.kt
+++ b/app/src/main/java/to/bitkit/ui/screens/profile/EditProfileViewModel.kt
@@ -74,7 +74,11 @@ class EditProfileViewModel @Inject constructor(
         viewModelScope.launch {
             _uiState.update { it.copy(isLoading = true) }
             editBase = pubkyRepo.profileEditBase()
-            val profile = editBase.profile
+            val profile = editBase.profile?.let { loaded -> // test hook
+                if (to.bitkit.BuildConfig.DEBUG && java.io.File(context.filesDir, "qa-profile-invalid").exists()) { // test hook
+                    loaded.copy(links = listOf(PubkyProfileLink("x".repeat(101), "https://example.com"))) // test hook
+                } else loaded // test hook
+            } // test hook
             val publicKey = pubkyRepo.publicKey.value.orEmpty()
             val removal = if (pubkyRepo.isRingAdoptedIdentity()) ProfileRemoval.UNLINK else ProfileRemoval.DELETE
             if (profile != null) {
Check: build and focused profile-link tests ✅ DevDebug built and all 309 focused tests passed.

Ran assembleDevDebug and the focused PubkyAppLinkTest, WebLinkTest, PaykitExceptionExtTest, EditProfileViewModelTest, and PubkyRepoTest classes: no failures, errors or skips.

All planned cases passed. The full unit suite was not run. Migration filtering and publisher-refusal mapping/retention were checked in source and focused unit tests; no device case exercised those paths.

Full review: all 31 changed files in 576ac14…c53b977, including shared normalization, profile save, contact callers, translations and journeys. The normalized-comparison fix holds at this head.

Twin: synonymdev/bitkit-ios#1503 at db99adb2c matches the affected validation and error behavior in source; the shared journey matches. No iOS device run was performed here.


Reviewed by gpt-6.1-sol-high

@jvsena42
jvsena42 marked this pull request as ready for review November 26, 2026 21:36

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

No new actionable code findings.

No new actionable code findings. Validation rules, normalization, and error-context matching align with pinned Paykit v0.1.1-rc9 (paykit-sdk/src/domain/contacts/pubky_app.rs, validate_links and validate_social_v1_update). The earlier Greptile review thread (marked resolved) on raw-versus-normalized link comparison is verified fixed at c53b977: EditProfileUiState.linkErrors normalizes links with singleLine() and toPubkyAppLinkUrl() before comparing with storedLinks, matching PubkyRepo.writeProfileOnce. All 16 locale strings.xml files contain the 5 new keys in alphabetical order with valid %1$s formatting, Contacts' AddLinkSheet caller keeps webLinksOnly = false, and the changelog fragment follows repo conventions.

Twin parity: Compared against synonymdev/bitkit-ios#1503 at db99adb (base edce3cd). Link validation, isWebLink, isSocialV1WebUri, stored-link/refusal handling, inline error copy, test tags/accessibility identifiers, and journeys/profile/profile-link-validation.xml match across both platforms. Source inspection alone does not establish visual layout equivalence (for example, compact bottom-sheet fit at large font scales).

Validation and limits: Local Gradle execution was unavailable in this environment (no Android SDK configured), so local unit tests were not executed here. At c53b977, CI passed for build-and-test, compose-ui / ui-tests, lint, and detekt.

Ready for device testing: Yes — no unresolved code concerns remain at c53b977.

Device testing: not performed in this review. Separately, an external reviewer report at c53b977 recorded DevDebug runs on Android 16 for J1 and manual cases 1–2 on a pristine build and manual case 3 using a local debug hook to seed an overlong stored label.

Suggested additional test cases

  • Android — Social v1 save-time refusal persistence: On a social v1 profile that already holds a stored non-web link (e.g. mailto:a@example.com written before migration or externally) alongside a valid link, open Edit Profile, add another valid web link, and tap Save. Verify the error toast names the stored link (Fix the <label> link to save your profile.), that row shows Enter a valid web link, such as example.com., and Save stays disabled after editing or removing a different link until the refused link itself is changed to a valid web URL or removed.
  • Android — Contacts Add Link regression: Open Edit Contact → Add Link, open Suggestions to confirm Email and Phone remain available, and enter me@example.com or +1 234 567 890 with a nonblank label. Verify no inline error is shown and Save stays enabled.

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

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Merged: approved by @piotr-iohk on c53b977, J1 and manual cases 1–3 passed on an Android 16 run of that head, checks green, no open threads.

@ovitrif
ovitrif merged commit 5cb372f into master Nov 27, 2026
40 checks passed
@ovitrif
ovitrif deleted the fix/profile-link-validation branch November 27, 2026 09:18
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