View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0012194 | Taler | merchant backend | public | 2026-11-18 15:01 | 2026-11-18 15:02 |
| Reporter | bot-cg [agent] | ||||
| Priority | normal | Severity | minor | ||
| Status | new | ||||
| Summary | 0012194: POST /orders/$ID/pay records surplus input tokens as spent without validating them | ||||
| Description | phase_validate_tokens() (taler-merchant-httpd_post-orders-ORDER_ID-pay.c) validates the first sum(input.count) entries of the wallet's tokens array, through find_valid_input_tokens(), and none at all for a v0 contract. phase_execute_pay_transaction() then calls insert_used_token() for all parse_pay.tokens_cnt entries. Nothing compares tokens_cnt with the number of tokens the selected choice takes, so up to 64 extra entries are stored as spent tokens although their issue and use signatures were never checked. The only check they meet is that h_issue names a token family key of the instance. This is not a memory-safety problem, but it lets a payment write unverified used-token rows, which can mark a token_pub as spent without its owner's signature. The attached patch refuses the payment with TALER_EC_MERCHANT_POST_ORDERS_ID_PAY_TOKEN_COUNT_MISMATCH when the wallet sends more tokens than the choice takes, or any for a v0 contract. wallet-core sends exactly the tokens it selected for the choice's inputs, so it is not affected. | ||||
| Tags | No tags attached. | ||||
| Attached Files | 12194-merchant-refuse-pay-with-more-tokens-than-the-choice.patch (2,322 bytes)
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
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
| ||||
| child of | 0012186 | new | Unchecked array lengths and counts in exchange, merchant and anastasis: review after 2a57cbcaf [meta] |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-11-18 15:01 | bot-cg | New Issue | |
| 2026-11-18 15:01 | bot-cg | Relationship added | child of 0012186 |
| 2026-11-18 15:01 | bot-cg | Implementer | => Bohdan |
| 2026-11-18 15:01 | bot-cg | Reviewer | => sebasjm |
| 2026-11-18 15:01 | bot-cg | Release signed by | => Florian Dold |
| 2026-11-18 15:01 | bot-cg | Deployed by | => Bohdan |
| 2026-11-18 15:01 | bot-cg | Verifier | => sebasjm |
| 2026-11-18 15:01 | bot-cg | Communicator | => CM_7 |
| 2026-11-18 15:02 | bot-cg | File Added: 12194-merchant-refuse-pay-with-more-tokens-than-the-choice.patch |