Implement session-scoped ndebit authorization for cash-in security #8
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The current mock-machine implementation auto-approves all debit requests, creating a vulnerability:
clink:ndebit...?amount=X) could claim those satsResearch Summary
Analysis of Lightning.Pub, ShockWallet, and CLINK spec reveals the intended security model:
How ndebit Authorization Works
(pointer, requestor_pubkey)pairAuthorization Flow
Key Insight: Pointer Scoping
The pointer doesn't have to be the user ID - it can be a session identifier. This enables session-scoped authorization:
Recommended Solution: Session-Scoped Pointers
Flow
Security Properties
amount = exact_invoice_amountImplementation Tasks
1. Lightning.Pub API Extension (may need upstream contribution)
Need API endpoint to pre-create debit authorization:
Alternatively, use existing
RespondToDebitwithtype: 'authorize'but triggered proactively.2. ATM Session Manager
3. Update mock-machine.mjs
Replace current auto-approve with session-based flow:
Alternative: Simplified First-Scan Lock
If Lightning.Pub API extension is not feasible, simpler approach:
This is simpler but has a small race window between QR display and first scan.
Priority
P1 - Security critical for production deployment
References
/clink/specs/clink-debits.mdsrc/services/main/debitManager.tssrc/services/storage/entity/DebitAccess.ts[reserved] migration number alignmentto Implement session-scoped ndebit authorization for cash-in securityCLINK scope note + LNbits migration impact
ndebit (CLINK kind-21002 + response 21003) is Lightning.Pub-specific — it lives in the CLINK protocol (https://github.com/shocknet/CLINK) embedded in LP. LNbits has zero knowledge of CLINK and the
nostr-native-transportwork onaiolabs/lnbits(see #22) does not add CLINK support.This means the session-scoped ndebit pre-authorization design in this issue — the proposed
POST /api/app/debit/authorizeon LP — stays scoped to Lightning.Pub. The LNbits-side migration neither blocks nor obviates it.What changes / doesn't change with the migration:
GetLiveDebitRequestssubscription,RespondToDebit, and the actualPayInvoicethat resolves the ndebit request.PayInvoicecall could in principle target an LNbits wallet via the new transport'spay_invoiceRPC — but only if you decide LNbits is the funds-bearing side. If LP is still the wallet, no change.subscribe_payments— but that's outcome parity, not protocol parity. It does not consume ndebit semantics.Future LNbits CLINK adoption: possible but deferred. If at some point LNbits should grow first-class CLINK (e.g. so an LNbits wallet can be the target of an ndebit request), that's a new protocol module alongside
lnbits/core/services/nostr_transport/, not part of it. The relay-pool and NIP-44 plumbing in the transport branch is the natural building block, but the decision is non-trivial and worth its own design.Net: this issue stays valid and LP-scoped. No re-architecture needed.