Closed
Description
Reproduction
- Create backend with 2 endpoints, "a" and "b"
- "a" is 1 Satoshi, "b" is 10 Satoshis
- Client sends initial request to each
- Client pays invoice for "a"
- Client sends final request to "b", but with the preimage of the payment for "a"
- => Request works although the client didn't pay the related invoice
Problem
The middleware doesn't track which invoice was created for which endpoint, it doesn't know about the endpoints at all. It just checks if the preimage was already used as payment proof and then checks the LN node for the invoice's existence and settlement.
Possible solution
- When the initial request arrives we're in the correct middleware instance, so we cache the URL path along with the preimage or its hash
- When the final request arrives we don't just check if it's valid (not used before, invoice settled), but also if the current request URL path is the same we previously cached. (Lookup via the preimage or its hash)
Note 1: It's not enough to have an in-memory cache of just the preimage or its hash per middleware instance, because in case of a horizontally scaled web service the caches wouldn't work properly anymore. It's probably best to use the existing storage client implementations, so the web service developer can choose for example Redis when he wants to scale horizontally.
Activity