vibe-audit.lab

guides · 2026-11-14

Mass Assignment: How Passing req.body to Your Model Lets Users Promote Themselves

Published 2026-11-14 · Reviewed 2026-11-14 · By the Ingenious AI team

The short answer

When a create or update call consumes the entire request body, the client chooses which fields to set — and they will choose isAdmin, role, credits or emailVerified, fields your form never rendered. Replace body passthrough with explicit allow-lists of assignable fields per endpoint, and treat any privileged field arriving in a request as a probe worth logging.

Check your own app free: paste your code or enter your site URL on the Vibe-Code Audit homepage — the free scan checks for exposed secrets, injection flaws, XSS patterns, missing headers and exposed .env/.git paths, with a copy-paste fix for every finding. No credit card.

The two lines that create the bug

It looks like good, DRY code: const user = await User.create(req.body), or profile.update(**request.json). The form only sends name and bio, so the developer sees no risk. But the endpoint does not know what the form sent — it knows what the request contains, and adding "role": "admin" or "credits": 100000 to the JSON is a ten-second edit in any HTTP client. Vibe-Code Audit carries both signatures as detectors — .create/.update/.save called with req.body, and **request.json splats — because this is one of the most reliably exploitable patterns in generated CRUD code, and it hides inside otherwise clean-looking endpoints.

Registration and profile-update are the classic sinks, but the class appears anywhere models are built from payloads: settings, orders (status: 'paid', price overrides), organisations (owner_id), and API-key creation (scopes). Any model with a field you would not put on a form deserves the question.

Why frameworks keep enabling it

Mass assignment is a feature misapplied: ORMs offer it for trusted data (seed scripts, internal jobs), and tutorials use it to keep examples short. AI models, trained on those tutorials, reproduce the shortest path. TypeScript types and DTO classes sometimes create false confidence — if the runtime does not actually validate (many 'typed' handlers still pass the raw body through), the types are documentation, not enforcement. The check that matters is at runtime: which keys did the handler actually copy?

What is Mass assignment (over-posting)?

a flaw where a framework binds an entire request payload onto a model object automatically. Fields the developer never intended as input — privileges, balances, ownership — become writable by anyone who adds them to the request.

The allow-list fix, per endpoint

For each endpoint, enumerate the fields a client may legitimately set there — registration gets email, password, display name; profile gets bio and avatar; neither gets role. Build the model from an explicit pick: { email: body.email, ... } or a schema (zod, pydantic) that strips or rejects unknown keys — prefer rejecting on sensitive resources, because a rejected 'isAdmin' in a request is a signal worth logging, while silently stripping it teaches you nothing. Privileged transitions (role changes, credit grants, verification flags) get their own admin-only endpoints with their own authorization checks, never a field on a general-purpose update.

Sweep for the pattern across the codebase, including the update paths nobody demos: settings import, bulk edit, webhook-driven updates. Then probe your own staging: PATCH your profile with each privileged field your models define and confirm none of them change.

Designing models so the bug matters less

Longer term, separate the shapes: request schemas distinct from database models, so 'what the client may say' is a designed list rather than an accident of the table. Keep truly dangerous fields (role, balance, verified) out of generic update machinery altogether — dedicated code paths with explicit checks and audit logging. When an AI assistant generates a new endpoint, the repo's existing allow-list pattern is the strongest defence: models replicate the codebase's conventions, so make the safe convention the visible one.

Worked example: CraftBoard, a project marketplace

CraftBoard (fictional), with 4,700 registered makers, built registration and profile updates on body passthrough. A scan flagged both mass-assignment patterns. The founder's staging probe — registering with an extra "plan": "team" field — created a Team-tier account worth $149 without payment. All eleven body-passthrough endpoints were converted to schema-based allow-lists over a weekend; role, plan and credits moved behind admin-only actions; and any request containing a privileged key is now logged. Log review for the prior quarter found 3 accounts with plans they had not paid for, which were contacted and corrected — the quiet cost of a loud bug.

Five things to do before you ship

  1. Grep for create/update/save calls receiving req.body, request.json or **request splats, and inventory every hit.
  2. Define an explicit allow-list schema per endpoint containing only the fields that endpoint may set.
  3. Move privileged fields (role, plan, credits, verified, owner) behind admin-only actions with their own checks and audit logs.
  4. Probe staging by adding each privileged field to registration and profile requests; confirm none take effect, and log the attempts.
  5. Re-scan and repeat the probe after any new endpoint is generated — new CRUD is where the pattern returns.

Sources

Frequently asked questions

My frontend never sends those fields. Why is it still a vulnerability?

Because attackers do not use your frontend. The endpoint's contract is what the server accepts, and an HTTP client can add any field in seconds. Judge endpoints by what they accept, not by what your form renders.

Does validation middleware I already have cover this?

Only if it strips or rejects unknown keys and is actually applied to these routes. Many validators check the fields they know and pass the rest through untouched — test by sending an extra privileged field and watching the database.

Should unknown fields be stripped or rejected?

Strip for low-risk public endpoints if you must; reject (400) on account, billing and settings resources. Rejection gives you a log signal that someone is probing, which silent stripping discards.

Is this the same as IDOR?

Cousins, not twins: IDOR is reaching another user's object by ID; mass assignment is writing fields you should not write on an object you can reach. Both stem from trusting client-supplied structure — and the ID-based file guide covers the other half.

Related guides

Browse the full library on the guides index, run the checks in the launch audit, or compare plans on pricing.


Informational explainer, not a security guarantee. Scan your code free before every deploy.

← all guides

← Back