fix: guard settings screens against long-hostname freeze#629
Merged
Conversation
Greptile SummaryThis PR prevents long hostnames from freezing the Electrum and RGS settings screens. The main changes are:
Confidence Score: 5/5This looks safe to merge.
|
| Filename | Overview |
|---|---|
| Bitkit/Utilities/URLValidationPattern.swift | Adds bounded hostname and URL patterns to avoid catastrophic regex backtracking. |
| Bitkit/ViewModels/Extensions/SettingsViewModel+Electrum.swift | Moves Electrum validation off the main thread and applies the bounded host pattern. |
| Bitkit/ViewModels/Extensions/SettingsViewModel+Rgs.swift | Revalidates the current RGS URL before applying it and adds an endpoint check. |
| Bitkit/ViewModels/SettingsViewModel.swift | Adds debounced background RGS validation and stores its result for UI state. |
| BitkitTests/SettingsUrlValidationTests.swift | Adds coverage for long inputs and representative valid and invalid server addresses. |
Reviews (2): Last reviewed commit: "fix: cehck if endpoint is reachable" | Re-trigger Greptile
jvsena42
marked this pull request as draft
July 15, 2026 14:01
jvsena42
marked this pull request as ready for review
July 15, 2026 14:09
jvsena42
enabled auto-merge
July 15, 2026 14:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR:
Freeze fix. Both screens validated hostnames with a regex whose nested quantifiers could backtrack catastrophically (ReDoS): a long hostname without dots scaled exponentially — roughly 0.1s at 24 characters, 5s at 28, and over 30s at 30 — and, because validation ran on the main thread, it froze the UI. The Electrum screen froze on tapping Connect, and the RGS screen froze while typing, since it re-validated (and rebuilt its regex) on every keystroke. The fix replaces the pattern with a linear, length-bounded one pulled into reusable named constants, rejects over-long hosts before matching, precompiles and debounces the RGS check, and moves all hostname validation off the main thread.
RGS connect verification. RGS connect previously just saved the URL and restarted the node, always reporting success — so a well-formed but wrong URL (e.g. a typo in the snapshot path) looked like it connected. Connect now re-validates the exact current URL and then confirms the endpoint actually serves a snapshot with a lightweight reachability check before restarting, matching the behavior already shipped in bitkit-android.
This mirrors the Android fix for the same issue.
Linked Issues/Tasks
Screenshot / Video
electrum.mov
rgs-server.mov
QA Notes
Manual Tests
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa): typing stays responsive and Connect stays disabled.https://URL → tap Connect: success toast..../rgs/snapshotttt) → tap Connect: error toast, not success.host:port→ tap Connect: connects as before.regression:RGS/Electrum → enter a normal domain, an IPv4 address, and a.localhost: each is accepted as before.regression:RGS Server → clear the field → tap Connect: RGS is disabled (empty URL) without a reachability error.Automated Checks
BitkitTests/SettingsUrlValidationTests.swiftcovers the long-dotless-host timeout regression (asserts validation completes in under 100ms) plus domain, IPv4,.local, and empty/non-https correctness for both validators.