Mass assignment in AI-built apps: the extra JSON field that makes a user an admin (and a 3-minute test)
Mass assignment is when your API takes the whole request body and writes it to the database. The user sends {"name": "Sam"} and nothing goes wrong. An attacker sends {"name": "Sam", "role": "admin", "plan": "pro"} and your app saves all of it. AI-generated CRUD code does this a lot, because update(req.body) is the shortest way to write an endpoint.
1. The pattern to look for
Unsafe:
app.patch("/api/profile", async (req, res) => { await db.user.update({ where: { id: req.user.id }, data: req.body }); res.json({ ok: true }); }); Safer:
const { name, avatarUrl } = req.body; await db.user.update({ where: { id: req.user.id }, data: { name, avatarUrl } }); Search your code for data: req.body, ...req.body, Object.assign(user, req.body), .update(body) and .insert(body).
2. Fields worth protecting
-
role,is_admin,isAdmin,permissions -
plan,tier,credits,balance,is_paid -
user_id,owner_id,org_id(so nobody moves a record to another account) -
email_verified,verified -
id,created_at
3. A 3-minute test
- Open your app signed in as a normal test user and save any form, such as profile settings.
- In your browser's network tab, copy the request as cURL.
- Add one extra field to the JSON body, for example
"role":"admin"or"plan":"pro". - Send it, then reload the profile. If the new value stuck, the endpoint is open to mass assignment.
Use your own test account and your own app only.
4. Supabase and Firebase apps
If the browser talks to your tables directly, the same problem shows up as a row policy that lets users update every column. A policy like "users can update their own row" also lets them update role on that row. Fix it with a column allow list, a trigger that blocks changes to sensitive columns, or by moving role and plan into a table users cannot write to.
5. Fixes that hold up
- Use an explicit allow list of fields on every write endpoint.
- Validate the body with a schema (Zod, Joi, Pydantic) that rejects unknown keys.
- Keep roles and plans in a separate table or claim that only server code can change.
- Re-check ownership on every update, never trust an
owner_idsent by the client.
What an outside scan can and cannot tell you
A scan that never signs in cannot see your write endpoints, so it cannot confirm or rule out mass assignment. Do this check by hand, on a logged-in test account, as part of your pre-launch pass.
Check your own app from the outside, free. Run the free ProofForge scan on your live URL. No account needed for the first scan. It looks at your public site the way a stranger would and says pass, fail or inconclusive, so you know what is confirmed and what it could not see. One-time reports start at $9: see pricing. Building with an AI agent? There is an MCP server so it can check before it deploys.