From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 18 Nov 2026 16:01:54 +0100 Subject: [PATCH] merchant: refuse /pay with more tokens than the choice takes Every token recorded as spent must have been validated against one of the choice's inputs. Issue: https://bugs.taler.net/n/12194 Assisted by LLM --- ...-merchant-httpd_post-orders-ORDER_ID-pay.c | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c index 38c2854a..f6a9f728 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c +++ b/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c @@ -4220,7 +4220,18 @@ phase_validate_tokens (struct PayContext *pc) switch (pc->check_contract.contract_terms->pc->base->version) { case TALER_MERCHANT_CONTRACT_VERSION_0: - /* No tokens to validate */ + /* No tokens to validate, so none may be spent */ + if (0 != pc->parse_pay.tokens_cnt) + { + GNUNET_break_op (0); + pay_end (pc, + TALER_MHD_reply_with_error ( + pc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_TOKEN_COUNT_MISMATCH, + "contract takes no tokens")); + return; + } pc->phase = PP_COMPUTE_MONEY_POTS; pc->validate_tokens.max_fee = pc->check_contract.contract_terms->pc->details.v0.max_fee; @@ -4295,6 +4306,19 @@ phase_validate_tokens (struct PayContext *pc) wallet_off += input->details.token.count; } } + if (wallet_off != pc->parse_pay.tokens_cnt) + { + /* every token we record as spent must have been validated + against one of the inputs above */ + GNUNET_break_op (0); + pay_end (pc, + TALER_MHD_reply_with_error ( + pc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_TOKEN_COUNT_MISMATCH, + "more tokens than the choice takes")); + return; + } /* calculate pc->output_tokens_len */ output_off = 0; -- 2.47.3