fix(l402): refuse unknown/unbounded invoice amount even with no max (#71) - #11
Merged
Merged
Conversation
…#71) The L402 amount/budget gate short-circuited when no `max_amount_sats` was configured (`if effective_max is None: return`) and paid ANY invoice — an unbounded, unaudited spend whenever a caller merely forgot to set a ceiling. Split the gate into two independent rules: 1. Unknown/unbounded amount (amountless, unparseable, or <= 0 — all reported as None by the decoder) is ALWAYS refused, whether or not a max is set. This is the fail-closed core of ledger #71. 2. The `amount > max` ceiling comparison applies ONLY when a max is configured. A KNOWN positive amount with no ceiling is still paid — the caller's documented opt-out — so this does not force every payment to declare a max. Flips the security-regression test that pinned the fail-open pay behavior to assert refusal, and adds a companion test proving a known amount with no ceiling is still paid. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ledger #71 — fail-closed the L402 amount/budget gate
The L402 amount/budget gate short-circuited when no
max_amount_satswas configured (if effective_max is None: return) and paid anything — an unbounded, unaudited spend whenever a caller merely forgot to set a ceiling.Change
L402Client._check_amount_against_maxis split into two independent rules:<= 0(all reported asNoneby_decode_invoice_amount_sats). Fail-closed core of #71.amount > max→ refuse) applies only when a max is configured.Result: unknown amount → refuse (even with no max); known positive amount + no max → pay (caller's opt-out); known positive amount + over max → refuse. It does not force every payment to declare a max.
Tests (failing-test-first)
test_unparseable_invoice_still_paid_when_no_budget_configured→test_unparseable_invoice_refused_even_when_no_budget_configured(was RED against pre-fix code: it paid; now GREEN). Mutation-checked: reverting the fix makes it pay again.test_known_amount_paid_when_no_budget_configuredpinning the opt-out half.Full suite: 211 → 212 passing (net +1 test).
Not published, no version bump.