refactor: Security audit fixes (certs, webview, RNG) + drop 5 dependencies - #2557
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
db9edcc to
540a4ea
Compare
|
1. App-bar drag regression (exchange home) — accepted as a trade-off rather 2. Exact-host match narrowing + silent blocks — both 3. |
|
@wired-pasteque can you give it a manually QA please? |
|
@ethicnology, manual QA - all good ✅ On the Electrum side, default servers (mainnet + testnet) still show online/connected, adding a custom server with a self-signed cert still succeeds and shows online, and toggling between default and custom updates the status indicator correctly. Screen.Recording.2026-08-04.at.11.43.51.AM.movFor the exchange auth webview, the login flow completes end-to-end, terms/privacy links open fine, also navigating inside is working as usual. No regressions on my end. |
# Conflicts: # lib/features/settings/ui/screens/all_settings_screen.dart
The transaction datasource always opened a CA-validated TLS socket built from the bare host and port, ignoring both the url scheme and the user's validateDomain setting. A personal node reached over tcp://, or serving a self-signed certificate, therefore synced fine through BDK/LWK but failed on every transaction-detail fetch. ElectrumConnection already carries the resolved url, validateDomain and timeout — its doc even names the electrum-client repository as a consumer — so pass it down instead of a lone url string. The socket now follows the scheme, validates certificates exactly like the sync path, and applies the configured timeout, which was missing altogether and could hang the fallback loop. Bare host:port urls, how Liquid servers are persisted, keep defaulting to TLS rather than being read as a scheme by Uri.parse.
The status probe decided its own certificate policy — lax for custom servers, strict for defaults — instead of asking the setting the BDK/LWK sync obeys. The two could therefore disagree: a personal node serving a self-signed certificate passed the probe, was saved, and only then failed to sync, with nothing pointing at the certificate. checkElectrum now takes validateDomain and forwards it to onBadCertificate, so "online" means the wallet can really use the server. ElectrumConnectivityAdapter reads it from the electrum settings of the network being checked, which also replaces a SettingsRepository fetch whose result was being discarded; AddCustomServerUsecase reads it before probing and propagates a load failure rather than probing with a guess. Consequence worth knowing: while validateDomain is on (the default), adding a self-signed server now fails instead of succeeding and syncing badly. The message is still the generic "unreachable" one — telling the user to turn domain validation off is a separate change.
A codebase audit (security + dependencies) found three vulnerabilities and five
removable dependencies:
onBadCertificate: (_) => trueapplied to all servers, letting a network attacker MITM the connectivity probe
and make a malicious server look healthy.
startsWith('https://accounts')would also match lookalike hosts such as
https://accounts.evil.com.decimal,flutter_animate,font_awesome_flutterandsliver_toolswere each usedin a single file;
httpwas unused.What changes
ServerStatusPort.checkElectrumtakes a requiredallowSelfSigned.Default servers now enforce strict CA validation; self-signed certs are only
tolerated for user-configured custom servers (personal nodes).
non-HTTPS navigation is blocked outright.
Random.secure().bolt11 amounts via exact rational arithmetic (same truncation semantics, covered by
a new unit test), a plain
Duration, a local GitHub SVG tinted from the theme, anda
Stackoverlay instead ofSliverStack+ pinnedSliverAppBar(behaviourallyidentical — see code comment).
What deliberately does NOT change
decimalandhttpstay in the lockfile as transitive deps (other packagesneed them); only the direct dependency is dropped.
gapis kept: used in 244 files and already owned and re-exported bybull_ui.Migrating the remaining root imports to the
bull_uibarrel belongs to thedesign-system migration, not this PR.
pull-to-refresh untouched).
Security review notes
Touches TLS validation (Electrum probes) and the exchange auth webview navigation
policy — worth a careful look. No key material, signing, or backup/recovery code
involved.
Commit reading order
1–3: the three security fixes (independent, individually revertable).
4–8: one commit per dropped dependency, each carrying its pubspec.yaml + pubspec.lock
hunk so every intermediate state resolves under
--enforce-lockfile.Test plan
Automated (already in this PR):
make analyze— no issues found (matches CI:--fatal-warnings --fatal-infos)make unit-test— all green, including 4 newSwap.amountSattests(
test/core_test/swaps/swap_entity_test.dart): exact bolt11 decode(2500u → 250 000 sats), empty invoice → 0, unparseable invoice → 0,
chain swap passthrough
Manual QA:
Electrum (cert validation):
Settings → Electrum server
Exchange auth webview: