Repository navigation
Unbeholden Wallet: add package and NixOS module - #230
Conversation
ostermayer
left a comment
There was a problem hiding this comment.
Thanks for this. I read the module and the pinned v0.3.0 source, including container/serve.ts. The packaging looks right: the source and node_modules are pinned by hash, the install runs with --ignore-scripts, and serve.ts imports only Bun built-ins, so nothing is fetched at runtime. A few things I'd change before merging:
-
The onion option publishes an open Electrum relay.
nix-bitcoin.onionServices.unbeholden-walletforwards straight to the server, and the server has no auth. Anyone who gets the onion address can use the node's electrs or Fulcrum through/electrum(address queries, subscriptions, broadcasts) and can write to the journal throughPOST /log. It doesn't leak the owner's xpub, since the wallet keeps that in the browser. I'd drop the onion option until the server has auth, or document this and point to Tor client authorization (services.tor.relay.onionServices.unbeholden-wallet.authorizedClients). -
The WebSocket origin check passes DNS rebinding.
serve.tscomparesOriginwith the request's ownHost. A rebinding page sends a matching pair (evil.example:60846for both), so a site the user visits can reach the relay on localhost. The impact is small, it only gets the relay, but it's worth fixing upstream by checkingHostagainst the listen address or an allowlist. A test that sendsOrigin: http://attacker.invalidwould cover the check. -
nginx can't reach the wallet with netns-isolation. nginx gets its own namespace when it's enabled, and the wallet's namespace only accepts its Electrum peer. The reverse-proxy docs need
nix-bitcoin.netns-isolation.services.nginx.connections = [ "unbeholden-wallet" ];, or the module could add it when nginx is on. A proxy in the host namespace, like Caddy, works through the bridge.
Smaller:
- The CI matrix runs the wallet only with Fulcrum. The focused scenarios, including the default electrs backend, aren't in it.
test/ci/scan-node.nixdoesn't enable the wallet, so the CVE scan misses it and Bun.
This was a static review plus a red-team run over the branch. Nothing else came up in the files this PR touches. I didn't build it or run the VM tests.
## Summary The bridge compared `Origin` with the request's own `Host`. A DNS rebinding page controls both (`evil.example:8080` → `127.0.0.1`), so any site the user visited could use the Electrum relay. Raised in review of bitcoinix/bitcoinix#230. ```diff fetch(req) + if ELECTRUM set and Host is not an IP, localhost or in ALLOWED_HOSTS + 403 "Add <name> to ALLOWED_HOSTS…" + if Origin present and its host ≠ Host + 403 "Wrong origin" /log, /electrum, /electrum.json, files bridge(req) - if Origin host ≠ Host → 403 ``` The Origin check now covers every route, so another site can't POST to `/log` either (a `text/plain` POST needs no preflight). `ALLOWED_HOSTS` is new, comma-separated, passed through `compose.yaml`, and documented in the README and `self-hosting.md`. ## Evidence New `container/serve.test.ts` spawns `bun container/serve.ts` and sends raw `Host`/`Origin` headers. - **Before:** 3 of 5 fail: rebinding `Host: evil.example` → 200; cross-site `POST /log` → 204, with and without `ELECTRUM`. - **After:** 5 pass. Full suite 557 passed; typecheck, app build and site build pass. ## Merge Danger **Door:** Two-way. **Blast Radius:** Self-hosters. Anyone running the container with `ELECTRUM` behind `tailscale serve` or a domain proxy gets a 403 naming the variable until they set `ALLOWED_HOSTS`, both after the next release. Hosted app, demo and site run without `ELECTRUM` and are unaffected. Reviewed-on: https://git.home.unbeholden.dev/unbeholden/unbeholden-wallet/pulls/165
|
Thank you for the review. Updated to v0.4.0 in 63f35e0, including the Host and Origin checks and The package build and local checks pass. VM integration tests remain for CI. |
|
Hello @unbeholdendev , looks good, thanks for the changes! Re-checked 63f35e0: the three review items are addressed and CI is green. Before merge:
Assisted-by: Claude Code (claude-fable-5-1) |
63f35e0 to
bd48bd7
Compare
ostermayer
left a comment
There was a problem hiding this comment.
Thanks, this fixes everything from my first review. I read the update and the v0.4.0 serve.ts:
- The onion option is gone.
serve.tsrefuses names that aren't an IP,localhostor inALLOWED_HOSTS, and it checksOriginon every request. So a rebinding page gets a 403 on/electrumand/log. I didn't find a way around it.- The netns connection list works both ways, so nginx and the wallet can reach each other.
- CI runs both electrs scenarios, and
netnsRegtestcovers Fulcrum under netns. The CVE scan includes the wallet. bun.lockandpackage.jsonare the same in v0.3.0 and v0.4.0, so keeping thenode_moduleshash is right.
A few small things:
- The branch now conflicts with master in
test/tests.nix. - The server still has no auth, and a client that isn't a browser can leave out
Origin. So anyone who can reach an https proxy in front of it can use the Electrum relay and write to the journal through/log. I'd say in the docs that the proxy should stay on a trusted network or have its own auth. - With
netns-isolation, nginx runs in its own namespace, and namespaces drop LAN connections (seedocs/configuration.md). So under netns an nginx proxy doesn't help other devices on the LAN. A proxy in the host namespace does. The docs line about nginx could say that. allowedHostsentries must be host names without a port.wallet.example.com:8443never matches. The option description could say so.- No bitcoinix test sends a foreign
Hostor setsallowedHosts. A curl with-H 'Host: evil.example'that expects a 403 would catch a later rename ofALLOWED_HOSTS.
This was a static review of the update. I didn't build it or run the VM tests. CI passes.
|
Thanks. All five are in 16b0748. The |
Closes bitcoinix#212. The package builds the wallet from source with Bun and Vite and wraps the wallet's own server, which serves it and relays its WebSocket connection to an Electrum server. The module runs that server against electrs or Fulcrum, with netns isolation, an optional onion service and a nodeinfo entry. Assisted-by: Claude Code (claude-opus-5-5)
Check the selected backend in the relay response instead of assuming Fulcrum. Add focused scenarios for electrs and Fulcrum with and without network isolation. Keep the broad scenarios on Fulcrum. Assisted-by: Codex (gpt-6.1-sol)
The default mainnet fixture never synchronises, so Fulcrum does not open its Electrum listener. Checking the wallet relay there timed out after 900 seconds. Keep the page check in every scenario and exercise the relay on regtest, where the backend can finish synchronising. Assisted-by: Codex (gpt-6.1-sol)
…etns, add allowedHosts The server has no auth, so an onion service would publish an open Electrum relay. allowedHosts sets ALLOWED_HOSTS, which the server checks against DNS rebinding from the next release. CI runs the electrs scenarios with and without netns, and the CVE scan covers the wallet. Assisted-by: Claude Code (claude-opus-5-5)
Includes the Host and Origin checks and ALLOWED_HOSTS support for the Electrum relay. Assisted-by: Codex (GPT-6.1-sol)
The server has no auth, and its Host and Origin checks stop only browsers, so the docs say to keep a proxy on a trusted network or give it its own auth. Under netns-isolation nginx can't serve the LAN, so the docs point to a proxy in the host namespace. allowedHosts takes names without a port. The test expects a 403 for a foreign Host and a 200 for each allowed name. Assisted-by: Claude Code (claude-opus-5-5)
16b0748 to
72c749e
Compare
ostermayer
left a comment
There was a problem hiding this comment.
Thanks, this answers all five. I read 72c749e and checked the rebase.
- The rebase only resolves the three conflicts with master and adds the 0.1.6 release note. The rest of the series is the same as 63f35e0.
- The docs now say the service has no auth, so the proxy needs a trusted network or its own auth. They also say nginx under netns can't serve the LAN, and they point to a proxy in the host namespace.
- The
allowedHostsdescription says names go without a port. - The test expects a 403 for a foreign
Hostand a 200 forwallet.test. All four wallet scenarios import the electrs one, so it runs with electrs, Fulcrum and both netns setups. curl sends noOrigin, so the 403 can only come from the Host check. The module always setsELECTRUM, so that check is always on.
The test and docs workflows for this head are waiting for a maintainer to approve them, so the new test hasn't run in CI yet. I didn't run it myself.
@ostermayer approved. |
viberaven
left a comment
There was a problem hiding this comment.
Reviewed commit 72c749e. No new correctness findings in the PR changes.
I checked the package, module/backend wiring, systemd hardening, namespace connections, nodeinfo, documentation and test registration against the pinned v0.4.0 server and frontend source. The previous review items are addressed. The frontend derives the WebSocket scheme from the browser URL, so HTTPS termination at the documented proxy is compatible with the HTTP backend.
CI has now completed successfully, including ci_gate, both focused electrs scenarios, netnsRegtest, flake checks and the docs build. I also inspected the electrs scenario log: the foreign-Host rejection, allowed wallet.test Host and server.version request through the WebSocket relay all ran successfully. I did not independently rerun builds or VM tests locally, or exercise the browser signing flow.
Before merge, resolve the current conflicts with master (GitHub currently reports CONFLICTING) and rerun CI on the updated head. The PR description also still describes v0.3.0 and an optional onion service; please update it to match the final v0.4.0 implementation.
Assisted-by: Codex (gpt-6-astra)
|
Thanks. The conflicts are resolved. I've updated the description for v0.4.0: the onion service is gone, and it now covers the Host and Origin checks and the no-auth proxy advice. The tests and docs workflows for c55439d are waiting for a maintainer to approve them. |
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [bitcoinix/bitcoinix](https://github.com/bitcoinix/bitcoinix) | patch | `v0.1.5` → `v0.1.6` | --- ### Release Notes <details> <summary>bitcoinix/bitcoinix</summary> ### [`v0.1.6`](https://github.com/bitcoinix/bitcoinix/releases/tag/v0.1.6): bitcoinix 0.1.6 [Compare Source](bitcoinix/bitcoinix@v0.1.5...v0.1.6) **Security release with breaking changes.** Narrows Tor enforcement to local addresses, closes a netns-isolation bypass, hardens RTL and the custom lnd macaroons, and updates lnd to 0.21.8-beta. All users should upgrade. Evaluation fails with a message for each breaking change that affects your config; act on it, then set `nix-bitcoin.configVersion = "0.1.6";`. Deploying restarts every netns-isolated service and each RTL backend once. #### Security - **Tor enforcement allowed more than Tor.** Services with `tor.enforce` and charge-lnd could reach every link-local address `169.254.0.0/16`, including a cloud provider's metadata service, and could resolve names through the host's resolver sockets. They now reach only localhost and, with netns-isolation, the namespace subnet, and can't use the nscd, systemd-resolved, D-Bus and Avahi sockets ([#​264](bitcoinix/bitcoinix#264), [GHSA-cgh8-4w2p-8fr8](GHSA-cgh8-4w2p-8fr8)). - **netns-isolation:** with `br_netfilter` loaded, which Docker does, a service without `tor.enforce` could reach the listeners of namespaces it isn't connected to. Traffic between namespaces is no longer masqueraded ([#​239](bitcoinix/bitcoinix#239)). - **RTL verifies its backends.** RTL sent the lnd admin macaroon and the clightning admin rune to any server on a backend's port. It now requires the backend's pinned TLS certificate ([#​258](bitcoinix/bitcoinix#258)) and stops when lnd or clightning stops, instead of polling a port that another local user could take over ([#​250](bitcoinix/bitcoinix#250)). - **RTL two-factor authentication survives restarts.** Before, each restart turned 2FA off without a warning. `RTL-Config.json`, which holds the 2FA secret, is now readable only by RTL's user ([#​254](bitcoinix/bitcoinix#254)). - **Custom lnd macaroons** (`services.lnd.macaroons`, used by BTCPay Server and charge-lnd) are now readable only by their `user`. Before, the user's primary group could read them, which for `operator` is `users`, so other normal users could. If other users log in to your node, [revoke all macaroons](https://docs.bitcoinix.net/services.html#revoke-all-macaroons) ([#​255](bitcoinix/bitcoinix#255)). Each custom macaroon now has its own root key, so one can be revoked without the others ([#​236](bitcoinix/bitcoinix#236)). - **Root scripts no longer load config files from a service user's home.** The lnd user could make root's `curl` and `jq` load `~/.curlrc` and `~/.jq` from lnd's data dir ([#​241](bitcoinix/bitcoinix#241), [GHSA-cwmc-wjvh-3qp6](GHSA-cwmc-wjvh-3qp6)). - **Backups fail when a database dump fails.** Before, duplicity succeeded without the database. With `services.postgresqlBackup.compression` set to `"zstd"` or `"none"`, backups left out the BTCPay and NBXplorer databases; they are now included, so run `systemctl start duplicity` after upgrading if you use one of these ([#​225](bitcoinix/bitcoinix#225)). - **Multipath TCP:** service namespaces now copy the host's `net.mptcp.enabled`, so the setting of `hardened-extended` reaches netns-isolated services ([#​206](bitcoinix/bitcoinix#206)). - **Secrets:** `setup-secrets` rejects empty secret files, and secret generation no longer replaces an empty TLS, WireGuard or replication SSH key ([#​244](bitcoinix/bitcoinix#244)). - **WireGuard preset:** evaluation fails for firewall setups in which the preset's rules can't run or don't stay loaded ([#​188](bitcoinix/bitcoinix#188)). - **lnd [0.21.8-beta](https://github.com/lightningnetwork/lnd/blob/master/docs/release-notes/release-notes-0.21.8.md)** fixes correctness bugs in channel state persistence, gossip validation, the sweeper and HTLC recovery ([#​263](bitcoinix/bitcoinix#263)). #### Breaking changes - **Tor enforcement:** a service with `tor.enforce` that connects to a non-local address or by host name needs a change. netns-isolation rejects `addressblock` 169 and 170 ([#​264](bitcoinix/bitcoinix#264)). - **Onion address access:** `lndconnect.onion` and `clnrest.lnconnect.onion` give the operator user access only when `nix-bitcoin.operator.enable` is set. `nix-bitcoin.onionAddresses.access` accepts only users that are defined and enabled in `users.users` ([#​170](bitcoinix/bitcoinix#170)). - **Secrets:** an empty or non-regular secret file now fails `setup-secrets`, and then no service can read its secrets. Check before deploying: `find /etc/nix-bitcoin-secrets -maxdepth 1 -type f -empty`. Set `nix-bitcoin.secrets.<name>.allowEmpty = true` for a secret that may be empty ([#​244](bitcoinix/bitcoinix#244)). - **lnd wallet:** lnd stops when `wallet.db` isn't a regular file, or when its seed file is a symlink to a missing file while it has no wallet ([#​244](bitcoinix/bitcoinix#244)). - **lnd macaroons:** bitcoinix deletes unused root keys with IDs `0x6e62000000000000` to `0x6e62ffffffffffff` on each lnd start; check `lncli listmacaroonids` before deploying. lnd's `no-macaroons` option isn't supported. Restart services that read a custom macaroon only at startup ([#​236](bitcoinix/bitcoinix#236)). A program that read a custom macaroon through the group needs its own macaroon ([#​255](bitcoinix/bitcoinix#255)). - **RTL:** with both backends enabled, stopping one stops RTL for both ([#​250](bitcoinix/bitcoinix#250)). `LN_SERVER_URL`/`LND_SERVER_URL`, another `Settings.lnServerUrl`, a proxy without `no_proxy` for the backend, and servers with a self-signed certificate no longer work as before ([#​258](bitcoinix/bitcoinix#258)). - **WireGuard preset:** fails evaluation with the nftables firewall package without iptables, with `networking.nftables.flushRuleset`, and with an `ip` or `ip6` table named `filter` in `networking.nftables.tables` ([#​188](bitcoinix/bitcoinix#188)). - **extra-container [1.0.1](https://github.com/extra-container/extra-container/releases/tag/v1.0.1):** containers can no longer reach the host's Nix daemon socket, so `nix build`, `nix run`, `nix develop` and `nix-shell` fail inside them. `extra.hostNixDaemon = true;` restores the old behavior; read the security section of the extra-container README first ([#​211](bitcoinix/bitcoinix#211)). - **Packages:** `rtl` and `trustedcoin` moved to `legacyPackages.<system>.pinned`. Trezor is `nix-bitcoin.pkgs.nbPython3Packages.trezor`. `nbPython3Packages` uses the Python interpreter of nixpkgs-unstable, so build custom Python environments with `nbPython3Packages.python` ([#​245](bitcoinix/bitcoinix#245)). - **nodeinfo:** every bitcoinix update now produces a new system generation, because the revision is part of the script. Set `nix-bitcoin.revision = null;` to opt out ([#​243](bitcoinix/bitcoinix#243)). See [Upgrading to config version 0.1.6](https://docs.bitcoinix.net/upgrading.html#upgrading-to-config-version-016). #### New - **[Unbeholden Wallet](https://docs.bitcoinix.net/services.html#connect-to-unbeholden-wallet):** a watch-only wallet that runs in the browser and hands transactions to an air-gapped signer over QR codes. Enable it with `services.unbeholden-wallet.enable = true;` ([#​230](bitcoinix/bitcoinix#230)). - **nodeinfo** shows the bitcoinix revision and the package version of each service. `nodeinfo --version` prints only the revision, `nodeinfo NAME ...` only the given entries ([#​243](bitcoinix/bitcoinix#243)). #### Fixes - lnd announces its onion address with the port Tor forwards. With a `services.lnd.port` other than 9735, peers couldn't reach the node over Tor ([#​228](bitcoinix/bitcoinix#228)). - clnrest replaces an empty or `null` admin rune on start. Generate connection URLs from `lnconnect-clnrest` again if they were created with such a rune ([#​217](bitcoinix/bitcoinix#217)). - btcpayserver with the clightning backend joins `services.clightning.group`, so a custom group works ([#​238](bitcoinix/bitcoinix#238)). - The lnd seed and electrs index migration steps keep the data when an earlier step fails ([#​242](bitcoinix/bitcoinix#242)). #### Updates | Package | 0.1.5 | 0.1.6 | | ----------------------------- | ----------- | -------------------------------------------------------------------------------- | | lnd | 0.21.6-beta | [0.21.8-beta](https://github.com/lightningnetwork/lnd/releases/tag/v0.21.8-beta) | | RTL | 0.15.16 | [0.15.17](https://github.com/Ride-The-Lightning/RTL/releases/tag/v0.15.17) | | extra-container (flake input) | 0.17 | [1.0.1](https://github.com/extra-container/extra-container/releases/tag/v1.0.1) | | Unbeholden Wallet | – | [0.4.0](https://github.com/unbeholdendev/unbeholden-wallet/releases/tag/v0.4.0) | Also: mempool builds with Node.js 24 ([#​246](bitcoinix/bitcoinix#246)); the docs say what netns-isolation doesn't isolate ([#​237](bitcoinix/bitcoinix#237)) and how to close public SSH without losing access ([#​234](bitcoinix/bitcoinix#234)). Contributors: [@​msgilligan](https://github.com/msgilligan), [@​ostermayer](https://github.com/ostermayer), [@​prusnak](https://github.com/prusnak), [@​seberm](https://github.com/seberm), [@​unbeholdendev](https://github.com/unbeholdendev), [@​viberaven](https://github.com/viberaven). Full changes: <bitcoinix/bitcoinix@v0.1.5...v0.1.6> </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4yNDEuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjI0MS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Co-authored-by: agent <[email protected]> Reviewed-on: https://git.home.unbeholden.dev/unbeholden/infra/pulls/140
Closes #212.
Summary
Add Unbeholden Wallet v0.4.0, a watch-only browser wallet that builds PSBTs and exchanges them with an air-gapped signer over animated QR.
Browser → wallet HTTP/WebSocket server → electrs or Fulcrum
The package builds from source with Bun and Vite. The module runs the wallet’s server under systemd hardening, defaults to electrs, and supports network namespace isolation and nodeinfo.
The service listens on localhost by default. The server refuses any
Hostthat isn't an IP,localhostor listed inallowedHosts(names without a port), and checksOriginon every request. It has no auth, so remote access needs an HTTPS reverse proxy on a trusted network or with its own auth; HTTPS is also what the browser needs for the camera. Under netns isolation, run the proxy in the host namespace, since nginx in its own namespace can't serve the LAN. Localhost access through an SSH tunnel also works.Evidence
Previously, bitcoinix had no package or service module for the wallet.
Validated:
netnsRegtest(Fulcrum under netns), flake checks and the docs build.Hostand 200 for each name inallowedHosts.The full multi-application VM suite was not completed.
Merge Danger
Door: Two-way. The service is disabled by default.
Blast Radius: Opt-in. Enabling the wallet also enables its selected Electrum backend.