[feature]: don't return `r_preimage` for unsettled invoices to `invoices:read` callers
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 85/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- go
- Domain
- backend-api-design
Research direction
The issue identifies lnrpc/invoicesrpc/utils.go as the file containing CreateRPCInvoice, the function that builds invoice RPC responses and currently sets RPreimage without checking invoice state. Start by opening that file, adding a check for the invoice's settled status before populating the RPreimage field, then run the relevant invoice RPC tests to confirm the preimage is only returned for settled invoices.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
A macaroon holding only invoices:read can read the preimage of an invoice that has not been paid yet.
LookupInvoice, ListInvoices and SubscribeInvoices require only that permission, and they build their responses with CreateRPCInvoice, which sets RPreimage whenever the invoice has a stored preimage, without looking at the invoice state (lnrpc/invoicesrpc/utils.go). A regular invoice has one from creation, since AddInvoice generates it so the node can settle on its own; hold and AMP invoices store none and are unaffected. invoices:read is part of both the default readonly.macaroon and invoice.macaroon.
Verified on regtest (master at 90ea05d5a; the code path has been in place since at least v0.6.0-beta): a macaroon baked with only invoices:read is denied AddInvoice, yet lookupinvoice and listinvoices return an open invoice with an r_preimage whose sha256 equals its r_hash.
The preimage of an unpaid invoice is what lets a node on the payment path settle the incoming HTLC without forwarding it, so a read-only credential is more powerful than it looks whenever its holder is also a channel peer or an LSP. I raised this with [email protected] first; they do not consider it a security issue, since it requires a macaroon in the first place, which is why I am opening it here instead.
Describe the solution you'd like
Include r_preimage in invoice responses only once the invoice is settled. If the current behaviour needs to be preserved for the node operator, an alternative would be to include it only for callers that also hold invoices:write.
Describe alternatives you've considered
- Documenting it only.
docs/macaroons.mdpresents read entities as harmless, so a note there would help, but it leaves the default macaroons as they are. - Narrowing permissions when delegating. This does not work today: a service that issues invoices needs
invoices:read(the hold invoice flow needsSubscribeSingleInvoice), and naming methods throughuri:does not change what a response contains.
Additional context
Other implementations do not expose it. Core Lightning adds payment_preimage only when status == paid (lightningd/invoice.c, and doc/schemas/listinvoices.json, where the field is described as "Proof of payment"). LDK derives the preimage from the node's key material at claim time rather than storing it.
Happy to open a PR if there is agreement on a direction.
- Dominant language
- Go
- Stars
- 8.2k
- Forks
- 2.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 103
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lightningnetwork/lnd
-
funding: failure logs print `<nil>` error and zero channel IDPossibly taken @litbot-9000 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
lightningnetwork/lnd#11676 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 85/100
lightningnetwork/lnd#11674 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
lightningnetwork/lnd#11672 ·
Maintainers usually reply within 1 day
-
test flake
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
lightningnetwork/lnd#11663 · 1 comment ·
Maintainers usually reply within 1 day
-
[flake]: lnwallet/test/bitcoind.TestLightningWalletBitcoindRPCPolling/spend_unconfirmed_outputsOpentest flake
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
lightningnetwork/lnd#11642 · 1 comment ·
Maintainers usually reply within 1 day
All issues in lightningnetwork/lnd
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
containers/gvisor-tap-vsock#796 ·
Maintainers usually reply within 2 days
-
external needs:triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
celestiaorg/celestia-node#5448 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
[Bug]: Azure SAS signing uses local time instead of UTC, shifting validity window on non-UTC hostsPossibly taken @huanghaoyuanhhy claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
zilliztech/milvus-backup#1418 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
projectdiscovery/nuclei#8423 ·
Maintainers usually reply within 1 day