Mass assignment and over-posting
Stage 4 · Lesson 3 · 20 minutes · Requires Lesson 1
The one-line answer
Mass assignment is when an API takes every field you send in a request and copies it straight onto a stored object — so sending an extra field like "role": "admin" can change things you were never meant to control.
The boundary: changing your own role or balance on a real service is unauthorised modification, even on your own account. Labs only.
Why you should care
It's a quiet bug: the request looks completely normal, just with one extra field. But it can turn a free account into an admin, mark an unpaid order as paid, or verify an unverified account. OWASP groups it under API3: Broken Object Property Level Authorization — the API checks which object you can touch but not which properties of it.
Recall the Stage 0 Lesson 8 example of a client sending something the server shouldn't accept — this is that idea, applied to every field in a JSON body.
How it actually works
Why developers do it
Modern frameworks make it easy to take a JSON request and turn it into a database object in one line. Instead of:
user.name = body["name"]
user.email = body["email"]a developer writes something like:
user.update(**body) # copy every field from the request onto the userConvenient — and dangerous, because the User object probably has fields the user should never set.
The bug
The "edit profile" screen sends:
PATCH /api/users/me HTTP/2
Content-Type: application/json
{"name": "Priya", "email": "priya@mail.com"}But a GET /api/users/me response shows the full object:
{
"id": 1043,
"name": "Priya",
"email": "priya@mail.com",
"role": "user",
"is_verified": false,
"credit_balance": 0
}So the tester (on an authorised target) adds one field to the update:
{"name": "Priya", "email": "priya@mail.com", "role": "admin"}If the API blindly binds every field, the account is now an admin. The front-end never offered a "role" box — it didn't need to.
This is also called over-posting: sending more than the form intended.
Finding the hidden fields
How does anyone know role exists? The same recon skills as before:
- API responses that return more fields than the UI displays (Lesson 1). The read response often tells you exactly what the write might accept.
- Documentation / OpenAPI specs listing the object's full schema.
- Other endpoints — e.g. an admin's user-list response shows fields like
is_admin. - Naming guesses:
role,isAdmin,is_admin,verified,status,price,discount,balance.
What makes a field dangerous
| Field type | Example | If mass-assignable |
|---|---|---|
| Permissions | role, is_admin | Privilege escalation |
| Status | is_verified, order_status | Skip verification or payment |
| Money | credit_balance, price, discount | Free money or goods |
| Ownership | owner_id, account_id | Move objects to/from other users (links to BOLA) |
| Internal | created_at, internal_notes | Tamper with audit data |
See it yourself
- Read OWASP API3: Broken Object Property Level Authorization (link below).
- On PortSwigger, find the API testing lab on exploiting a mass assignment vulnerability. Compare the GET response with the request the checkout sends — which field exists in one but not the other?
- In Repeater, add that field to the request, following the lab, and observe the result.
- Write down: the endpoint, the hidden field, where you discovered it, and its effect.
How attackers abuse this
Attackers read every API response carefully for fields the UI hides, then try sending them back in update or create requests. Registration endpoints are favourite targets ("role":"admin" at sign-up), as are checkout and profile endpoints.
The defensive fix:
- Allowlist bindable fields. For each endpoint, explicitly list which fields a client may set (e.g. profile update:
name,emailonly). Ignore or reject everything else. - Never auto-map request bodies to database models. Use separate input objects (DTOs / schemas) that only contain allowed fields.
- Use your framework's protection: most have a way to mark fields as read-only or to declare permitted parameters. Use it everywhere.
- Reject unknown fields rather than silently ignoring them, where practical — it makes mistakes visible.
- Return only what's needed in responses (the other half of API3: don't expose sensitive properties).
- Set sensitive fields only via dedicated, authorised flows — roles changed by an admin endpoint with its own checks, balances by the payment system.
Common mistakes
- Trusting the form. The form only shows some fields; the request can carry any.
- Blocklisting
roleinstead of allowlisting safe fields — the next sensitive field added to the model won't be on the list. - Protecting update but not create. Sign-up endpoints need the same allowlist.
- Leaking the full object in responses, which hands attackers the field names.
- Testing on real services. Labs only.
Check yourself
- What's the root cause of mass assignment in one sentence?
- Where would you look to discover a field like
is_adminthat the UI never shows? - Why is an allowlist better than a blocklist here?
Answers
- The API copies every client-supplied field onto a stored object without restricting which properties the client may set.
- API responses (especially GETs of the same object), API documentation/OpenAPI specs, responses from other endpoints, and sensible guesses at common names.
- An allowlist only permits known-safe fields, so new sensitive fields added later are protected by default. A blocklist must be updated for every new field — and someone will forget.
Your lab
- PortSwigger API testing (includes the mass assignment lab): https://portswigger.net/web-security/api-testing
- OWASP API Security Top 10, API3: https://owasp.org/API-Security/
Writeup: the endpoint, hidden field, discovery source, effect, and the allowlist fix.
Summary in your language
தமிழில் சுருக்கம்
Mass assignment என்பது ஒரு API, request-இல் அனுப்பப்படும் எல்லா fields-ஐயும் சேமிக்கப்பட்ட பொருளின் மீது நேரடியாக நகலெடுப்பது — அதனால் "role": "admin" போன்ற கூடுதல் field அனுப்பினால் உங்களுக்கு அனுமதியில்லாதவை மாறலாம். மறைந்த fields-ஐ API responses, ஆவணங்கள் மூலம் கண்டறியலாம். தீர்வு: ஒவ்வொரு endpoint-க்கும் அனுமதிக்கப்பட்ட fields-இன் allowlist; request body-ஐ database model-க்கு நேரடியாக map செய்யாதீர்கள்; responses-இல் தேவையானவை மட்டும்.
हिंदी में सारांश
Mass assignment तब होता है जब API, request में भेजे गए हर field को stored object पर सीधे copy कर देती है — इसलिए "role": "admin" जैसा अतिरिक्त field भेजने से वे चीज़ें बदल सकती हैं जिन पर आपका अधिकार नहीं। छिपे fields API responses और docs से पता चलते हैं। इलाज: हर endpoint के लिए मंज़ूर fields की allowlist, request body को सीधे database model पर map न करना, और responses में सिर्फ़ ज़रूरी data।
Want this summary in Malayalam, Telugu, Kannada or another language? Tell us — the most requested languages get added next.
What's next
Many APIs prove who you are with a token — here's how those tokens break: JWT: how tokens break