Repository navigation
unbeholden-lnurl: update to 0.7.1, grant the payments and webhook RPCs - #352
Conversation
sebsgent
left a comment
There was a problem hiding this comment.
Code looks correct: I checked the granted LND/CLN methods against everything unbeholden-lnurl v0.7.0 calls (internal/lnd/client.go, internal/cln/client.go, cmd/unbeholden-lnurl/main.go), and each feature gets exactly what it uses. One should-fix item, in the docs.
Should fix
docs/service/unbeholden-lnurl.mdsays not to route/paymentsthrough a public reverse proxy. But whennix-bitcoin.onionServices.unbeholden-lnurl.enableis set (the same page suggests it), the onion service forwards the whole listener,/paymentsincluded, to anyone with the onion address. Also,allowed_ipscan't tell onion clients from local processes: Tor connects from127.0.0.1(or, with netns-isolation, from the bridge address that every host process uses). So a client restricted toallowed_ips: ["127.0.0.1"]is still reachable through the onion with its token. The page should say this, since the payments API spends from the node balance.
Optional
- Docs: payments clients without
max_payment/daily_budgethave no limit and can spend the whole Lightning balance, and withoutallowed_ipsany address can use them. Worth saying next to "the clients' limits". - Docs: restoring a backup also rolls back
payments.json. Daily budgets then reset, and a client that retries a Lightning Address payment with the same ID after the restore gets paid again. The page mentions the same issue for voucher claims. test/tests.nix: the new lines landed between# Talks to the Electrum relayand thewebsocatline, so that comment now describes the lnurl line.- The PR body misses two points from the commit message: the ntfy versioning notice and running the new scenarios in CI.
Tested: read the upstream v0.4.0..v0.7.0 diff. go.mod/go.sum are unchanged, so vendorHash holds, and 0.4.0 state.json voucher claims stay valid. CI is green, including the new unbeholden-lnurl-webhooks-{lnd,cln} scenarios.
Assisted-by: Claude Code (Claude Opus 5.5)
ostermayer
left a comment
There was a problem hiding this comment.
@unbeholdendev I ran our gate on 4de0a8a with DeepSeek V4.1 Flash 1017 (max), Gemini 4 Carbon (high), Gemini 4 Neon (high), Claude Opus 5.5 (high) and GPT-6 Astra (max), with the 0.7.0 source next to the module, and checked each finding against the code. These come on top of sebsgent's points.
- The module accepts
tokeninpayments.clientsandsecretinnotifications.webhooks(modules/unbeholden-lnurl.nix:101-117). A config that follows the upstream example puts them in the world-readable Nix store. Any local user can then read a payments token and spend from the node, andallowed_ips = [ "127.0.0.1" ]doesn't stop a local process. A path literal intoken_fileorsecret_filecopies the file into the store too. An assertion that rejectstokenandsecretthere, and wantstoken_fileandsecret_fileas strings, would close this. The tests attest/tests.nix:903andtest/tests.nix:922would then need files. - With the onion service on,
trusted_proxieslets onion clients forge their address. Tor connects from127.0.0.1, or with netns-isolation from the host's bridge address. A local reverse proxy connects from the same address, so following the docs atdocs/service/unbeholden-lnurl.md:28puts Tor intrusted_proxies.clientIP(internal/server/server.go:69in 0.7.0) then takes the right-most forwarded address, and the payments API checksallowed_ipsagainst it (internal/payments/payments.go:181). So an onion client that sendsX-Forwarded-Forwith an allowed address passes anyallowed_ips, not only127.0.0.1. A warning when both are set, or a sentence in the docs, would help. - Without netns-isolation, the payments API is plain HTTP on
127.0.0.1:8081(cmd/unbeholden-lnurl/main.go:226). Nothing holds the port while the service restarts, or while it connects to its node at startup before it listens. Another local user who binds the port then gets the bearer tokens that clients send, and can use them from127.0.0.1. That's the port problem of #342, for a credential that spends funds. The docs could recommend netns-isolation for payments clients, as #347 does for the REST ports. notifiesatmodules/unbeholden-lnurl.nix:156counts every webhook, but the service watches invoices only for endpoints withpayment.receivedinevents(cmd/unbeholden-lnurl/main.go:202-213). So a webhook for onlypayment.sentorpayment.failedstill grantsLookupInvoice,ListInvoicesandSubscribeInvoices, orlistinvoicesandwaitanyinvoice. Counting only webhooks whoseeventscontainpayment.receivedwould fix it.
|
@unbeholdendev We also found security problems in the payments API of unbeholden-lnurl itself, in 0.6.0 and 0.7.0. Could you turn on private vulnerability reporting for the unbeholden-lnurl repo? We'll send the details there. Until there's a fixed release, could the maintainers hold this PR? |
4de0a8a to
9eb88ff
Compare
|
@unbeholdendev Thanks, 9eb88ff covers all four points. The assertion catches |
|
@ostermayer Thanks for checking the fixes. Private vulnerability reporting is now on for unbeholden-lnurl: https://github.com/unbeholdendev/unbeholden-lnurl/security/advisories/new I'll keep this PR on hold until a release fixes the payments API, then update it to that version. |
|
I sent unbeholden-lnurl a private security report. This PR should pin the release that fixes it. |
9eb88ff to
c122f15
Compare
|
@ostermayer Thanks for the report. 0.7.1 fixes it, see GHSA-5qpc-6rv4-34pp: GHSA-5qpc-6rv4-34pp c122f15 updates this PR to 0.7.1. On the bitcoinix side:
Since go.mod is unchanged, vendorHash still holds, and the service calls no new RPCs. Ready for another look. |
sebsgent
left a comment
There was a problem hiding this comment.
The upstream problems are fixed: I checked each finding of GHSA-5qpc-6rv4-34pp against the v0.7.0..v0.7.1 diff (amount cap and overflow-checked budget, refresh results bound to their record, AlreadyExists/earlier listpays treated as failure with invoice-matched lookups, public-only dialing without a proxy, amountless voucher invoices rejected). The module changes since my last review look right, including the voucher ID expansion, which matches upstream's %03d.
Should fix
-
Payments clients fail open: these configs evaluate without a warning or assertion, although the docs added here warn about them, and a client token can spend the whole Lightning balance:
settings.payments.clientswithout netns-isolation: 0.7.1 opens its port only after connecting to the node and setting up settlement tracking (cmd/unbeholden-lnurl/main.go:174-249), and nothing holds the port while the service or its backend is down. Another local user can listen there, collect the clients' bearer tokens and use them from127.0.0.1wherever a client'sallowed_ipsallows that address.settings.payments.clientswithnix-bitcoin.onionServices.unbeholden-lnurl.enable: the onion service maps to the listener, so/paymentsis reachable by anyone with the onion address. Ifsettings.trusted_proxiescontains the address Tor connects from, an onion client passes anyallowed_ipsby sendingX-Forwarded-Forwith an allowed address (clientIP,internal/server/server.go:69).
Operators who skim the page won't notice. Evaluation should make these visible.
Optional
- Docs: without
tor.proxy, a payments client's Lightning Address lookup tells the address's server the node's IP address. The page says this for zaps but not for lookups. - No test scenario sets up withdraw vouchers, so 0.7.1's new directory syncs on voucher claims (
atomicfile.WriteDurable, every parent directory up to/) aren't exercised under the service's sandbox.
Tested: read the upstream v0.7.0..v0.7.1 diff and the published advisory. Evaluated the PR head with payments clients, no netns-isolation, the onion service and trusted_proxies = ["127.0.0.1"]: no warnings or failed assertions, onion target 127.0.0.1:8081. go.mod is unchanged, so vendorHash holds. CI is green on c122f15, including the webhook scenarios.
Assisted-by: Claude Code (Claude Opus 5.5)
|
Thanks. ee2ce5a makes evaluation warn about payments clients without netns-isolation and with the onion service. I made these warnings rather than assertions, so existing configs still deploy. The docs now say that a payments client's Lightning Address lookup shows the node's IP address without |
sebsgent
left a comment
There was a problem hiding this comment.
Thanks, the warnings and the lookup docs cover my last review. I rechecked the cases against v0.7.1, and two of them need an assertion instead of a warning, because there the config promises a restriction that isn't enforced. The no-netns-isolation case and onion clients without allowed_ips are fine as warnings. Also, payments clients are new in this PR, so assertions don't break any existing config.
Must fix
- Rebase onto master: #370's lint commit conflicts in the
nix-bitcoin.secretsblock ofmodules/unbeholden-lnurl.nix. Keep master'sinherit (cfg) user;and usemkIf nostrfor the Nostr secret. With that resolution, deadnix and statix pass. - Assert, with payments clients and
nix-bitcoin.onionServices.unbeholden-lnurl.enable, that the address Tor connects from is in neithersettings.trusted_proxiesnor any client'sallowed_ips. With netns-isolation, that's the bridge address169.254.<addressblock>.10. Without it, Tor connects tonbLib.connectAddress cfg.address(the onion target) and, since that's a local address, from that same address:127.0.0.1by default,::1for::. Both options take CIDRs (config.Prefix), so check containment, not string equality:127.0.0.0/8must count too. Only prefixes of the same family as that address can match (netip.Prefix.Containsdoesn't match across families);lib.network.ipv6can parse IPv6 prefixes.- In
trusted_proxies, any onion client passes every client'sallowed_ipsby sendingX-Forwarded-Forwith an allowed address (clientIP,internal/server/server.go:69). - In
allowed_ips, onion clients pass that client's restriction directly. A local shop withallowed_ips = [ "127.0.0.1" ]and the onion service on for Lightning Addresses is the obvious config that hits this.
- In
Should fix
docs/service/unbeholden-lnurl.md:76: "A local reverse proxy connects from the same address as Tor" isn't true for nginx with netns-isolation. Bitcoinix runs nginx in its own namespace (nb-nginx), so it connects from its namespace address, not the bridge address. It's true without netns-isolation, or for a proxy in the host namespace. Say that listing nginx's namespace address intrusted_proxiesis safe.- Once 2. is an assertion, drop the
trusted_proxiespart from the onion warning, and mention the assertion in the docs next to the warnings. - PR body: mention the new warnings and the assertion.
Optional
- Upstream: a unix socket listener, or systemd socket activation, would let the module hold the payments port while the service is down and close the no-netns-isolation case instead of warning about it.
Tested: read v0.7.1's clientIP, allows and config.Prefix. Checked in modules/netns-isolation.nix and modules/onion-services.nix where Tor (host namespace, bridge address or the onion target) and nginx (nb-nginx) connect from, and with ip route get that a connection to a local address uses that address as its source. Resolved the rebase conflict locally and ran deadnix and statix. CI is green on ee2ce5a.
@ostermayer could you do another round on this PR, and recheck the findings above, especially which cases should be assertions and which warnings?
Assisted-by: Claude Code (Claude Opus 5.5)
ee2ce5a to
4d9f75c
Compare
|
Thanks. 4d9f75c covers the review, rebased onto master with the #370 conflict resolved as you described:
|
viberaven
left a comment
There was a problem hiding this comment.
Reviewed 4d9f75c. The RPC grants match upstream v0.7.1, and the earlier secret-file and ordinary Tor-address cases are covered. I found two remaining cases where the new Tor assertions accept a configuration whose IP restrictions still admit onion clients; details inline. These require a valid payments token, but defeat the additional allowed_ips restriction.
Validation:
- Built
checks.x86_64-linux.module-config(256 configuration tests),checks.x86_64-linux.test-runner(14 tests), andunbeholden-lnurl, including its upstream Go tests; all passed. - Reproduced the assertion gaps with Nix evaluations. Confirmed zoned-address behavior against v0.7.1's actual config parser and HTTP handler, and the wildcard-address case with Tor 0.4.9.17 config validation and Linux socket connections.
- Current GitHub checks are green. I did not rerun VM integration tests locally.
Assisted-by: Codex (GPT-6 Astra)
|
@viberaven Thanks. 23147e5 covers both:
|
sebsgent
left a comment
There was a problem hiding this comment.
Thanks, 23147e5 covers viberaven's two cases, and everything else from the earlier rounds is fixed. One gap is left in the Tor address check.
Must fix
- Without netns-isolation, the module takes the onion target as the address Tor connects from. That's only true for
127.0.0.1among the loopback addresses. For any other127.0.0.0/8address, Linux connects from127.0.0.1(ip route get 127.0.0.2givessrc 127.0.0.1). Withaddress = "127.0.0.2", the onion service and a payments client withallowed_ips = [ "127.0.0.1" ], ortrusted_proxies = [ "127.0.0.1" ], evaluation passes, and onion clients with the token get past thatallowed_ips.docs/service/unbeholden-lnurl.md("Tor connects from the onion target address") is wrong for this case too, andtestLnurlRejectsTorAddresshas no case for it.
Tested: evaluated the PR head with address = "127.0.0.2" and the configs above: no failed assertion, onion target 127.0.0.2:8081. A socat listener on 127.0.0.2 saw the connection come from 127.0.0.1. Tor 0.4.9.17 binds onion service streams to a source address only with OutboundBindAddress*, which the generated torrc doesn't set. Compared the module's prefix parsing and voucher ID expansion with v0.7.1's config.Prefix.UnmarshalText, clientIP, allows and ExpandVouchers; they match. CI is green on 23147e5.
Assisted-by: Claude Code (Claude Opus 5.5)
|
@sebsgent Thanks. fc7fc70 fixes it:
|
sebsgent
left a comment
There was a problem hiding this comment.
Thanks, fc7fc70 fixes the last gap: a target elsewhere in 127.0.0.0/8 is now checked as both itself and 127.0.0.1, the docs describe it, and testLnurlRejectsTorAddress covers both cases. Every finding from the earlier rounds is fixed, and CI is green. Approving.
Assisted-by: Claude Code (Claude Opus 5.5)
0.5.0 adds signed webhooks. 0.6.0 adds a payments API and LUD-18 payer data, and tracks voucher payouts with TrackPaymentV2. 0.7.0 sends an ntfy message for every payment event: voucher payouts are now titled "Payment sent" instead of "Voucher claimed", and failed payments are reported too. - Declare `settings.payments.clients` and `settings.notifications.webhooks`. - Payments clients get the same node access as vouchers: LND SendPaymentV2, TrackPaymentV2 and GetInfo, CLN pay, listpays and getinfo. LND vouchers now get TrackPaymentV2 too. - Webhooks count as notifications and get the invoice RPCs, so a webhooks-only config passes evaluation and starts. - Accept payments clients alone in the feature assertion. - Warn configs with ntfy and vouchers about the new ntfy title. - The VM test checks the service's macaroon and rune against the RPCs each feature calls. Add webhooks-only scenarios for both backends and run them in CI. Share the lnd permission check with the RTL test. Assisted-by: Claude Code (Claude Opus 5.5)
- Reject `token` in payments clients and `secret` in webhooks, and `token_file`/`secret_file` values that are Nix paths or carry store context. The VM scenarios read them from files. - Grant the invoice RPCs only to webhooks with `payment.received` in `events`, the only event that makes the service watch invoices. - Docs: the onion service exposes `/payments`, `allowed_ips` can't tell Tor from local processes, `trusted_proxies` with Tor lets onion clients forge their address, and without netns-isolation a local user can take the port. Clients without limits can spend the whole balance, and a restored backup rolls back `payments.json`. Assisted-by: Claude Code (Claude Opus 5.5)
0.7.1 fixes GHSA-5qpc-6rv4-34pp in the payments API, makes voucher claims durable before paying, and refuses Lightning Address lookups to private addresses without an outbound proxy. go.mod is unchanged, so vendorHash holds, and the service calls no new RPCs. - 0.7.1 refuses duplicate voucher IDs at startup. Assert this at evaluation, including IDs expanded from `prefix` and `count`. - 0.2.1 is released: move the release note and the ntfy notice to 0.2.2. Assisted-by: Claude Code (Claude Opus 5.5)
The docs warn that payments clients leak their tokens without netns-isolation, and that the onion service exposes /payments, but evaluation said nothing. A client token can spend the node's balance, so warn about both configs. The docs also say that without the Tor proxy, a payments client's Lightning Address lookup shows the node's IP address to that address's server. Assisted-by: Claude Code (Claude Opus 5.5)
With the onion service, Tor connects from the onion target address, or with netns-isolation from the bridge address. If trusted_proxies contains it, an onion client passes any allowed_ips by sending X-Forwarded-For. If a client's allowed_ips contains it, onion clients pass that restriction. Both configs promise a restriction that isn't enforced, so fail evaluation instead of warning. Payments clients are new, so no existing config breaks. Match prefixes as the service does with netip: CIDRs by containment, only within one address family, and bare IPv4-mapped addresses as IPv4. The onion warning now names the clients without allowed_ips. The docs no longer claim that nginx connects from Tor's address: with netns-isolation it uses its own namespace address. Assisted-by: Claude Code (Claude Opus 5.5)
…ed entries Without netns-isolation, map any all-zero bind address, such as `::0` or `0:0:0:0:0:0:0:0`, to loopback when deriving the address Tor connects from, not only the literal `::` and `0.0.0.0`. With payments clients and the onion service, `trusted_proxies` and `allowed_ips` entries the module can't parse, such as zoned IPv6 addresses that the service accepts, now fail evaluation. Assisted-by: Claude Code (Claude Opus 5.5)
…targets Without netns-isolation, Linux connects to an onion target elsewhere in 127.0.0.0/8 from 127.0.0.1, unless the target is assigned to an interface itself. Check both addresses, so `address = "127.0.0.2"` with `127.0.0.1` in `allowed_ips` or `trusted_proxies` fails evaluation. Assisted-by: Claude Code (Claude Opus 5.5)
fc7fc70 to
5270a24
Compare
unbeholden-lnurl: update to 0.7.1, grant the payments and webhook RPCs
0.5.0 adds signed webhooks. 0.6.0 adds a payments API and LUD-18 payer
data, and tracks voucher payouts with TrackPaymentV2. 0.7.0 sends an
ntfy message for every payment event: voucher payouts are now titled
"Payment sent" instead of "Voucher claimed", and failed payments are
reported too. 0.7.1 fixes GHSA-5qpc-6rv4-34pp in the payments API, makes
voucher claims durable before paying, and refuses Lightning Address
lookups to private addresses without an outbound proxy. go.mod is
unchanged from 0.6.0, so vendorHash holds.
settings.payments.clientsandsettings.notifications.webhooks.SendPaymentV2, TrackPaymentV2 and GetInfo, CLN pay, listpays and
getinfo. LND vouchers now get TrackPaymentV2 too.
payment.receivedin
eventsget the invoice RPCs, so a webhooks-only config passesevaluation and starts.
tokenandsecretfor payments clients and webhooks, andtoken_file/secret_filevalues that are Nix paths or carry storecontext, which would put them in the world-readable store.
from
prefixandcount, since 0.7.1 refuses them at startup.trusted_proxiesand
allowed_ipsentries that contain the address Tor connects from(the onion target, or the bridge address with netns-isolation),
including ranges such as
127.0.0.0/8. Warn about clients withoutallowed_ipsthere, and about payments clients withoutnetns-isolation.
"Payment sent" title.
allowed_ipsandtrusted_proxiesbehind Tor, the port withoutnetns-isolation, clients without limits, backups rolling back
payments.json, and Lightning Address lookups without the Tor proxy.each feature calls. Add webhooks-only scenarios for both backends and
run them in CI. Share the lnd permission check with the RTL test.
Assisted-by: Claude Code (Claude Opus 5.5)