Skip to content

fix: settlement cache reuse must match payee/token/amount, not just nonce+chain - #5

Open
holistis wants to merge 1 commit into
melonask:mainfrom
holistis:fix/settlement-cache-match-requirements
Open

holistis wants to merge 1 commit into
melonask:mainfrom
holistis:fix/settlement-cache-match-requirements

Conversation

@holistis

@holistis holistis commented Nov 9, 2026

Copy link
Copy Markdown

Title: fix: settlement cache reuse must match payee/token/amount, not just nonce+chain

Body:

POST /settle checks findExistingSettlement before doing any real verification. That lookup matches on nonce and chainId only (findByNonceAndChain), and when it finds a confirmed record it returns success: true straight away with the stored txHash and payer, using whatever network the current request sent.

The problem: a confirmed settlement's nonce can be reused in a new /settle request with completely different paymentRequirements (different payTo, asset, or amount), and the cache hit still returns success without checking any of that. The response looks like a real settlement for the new requirements even though the on-chain transaction never paid that payee or amount. GET /settlements?payer= is also unauthenticated, so a nonce from any payer's past confirmed settlement is easy to look up.

This PR adds the missing check: a cached settlement is only reused when its stored payee, token, and amount match the current request's paymentRequirements. Anything else falls through to the normal facilitator.settle() path, which does full verification.

No other behavior changes. Happy to add a test for this if useful, let me know what fixture setup you'd prefer for the DB layer.

…once+chain

POST /settle checks findExistingSettlement before doing any real verification.
That lookup matches on nonce and chainId only, and when it finds a confirmed
record it returns success: true straight away with the stored txHash and
payer, using whatever network the current request sent.

A confirmed settlement's nonce can be reused in a new /settle request with
completely different paymentRequirements (different payTo, asset, or
amount), and the cache hit still returned success without checking any of
that. GET /settlements?payer= is also unauthenticated, so a nonce from any
payer's past confirmed settlement is easy to look up.

This adds the missing check: a cached settlement is only reused when its
stored payee, token, and amount match the current request's
paymentRequirements. Anything else falls through to the normal
facilitator.settle() path, which does full verification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant