Skip to content

A client can cheat if the backend has multiple endpoints with different prices #16

Closed
@philippgille

Description

Reproduction

  1. Create backend with 2 endpoints, "a" and "b"
    • "a" is 1 Satoshi, "b" is 10 Satoshis
  2. Client sends initial request to each
  3. Client pays invoice for "a"
  4. Client sends final request to "b", but with the preimage of the payment for "a"
  5. => 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

  1. 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
  2. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions