# Mass Assignment
> Mass assignment (autobinding, object injection, over-posting) happens when a framework binds client-supplied keys straight onto an internal object, so a caller can set properties such as `role`, `isAdmin`, `credit`, `price` or internal IDs that the UI never sends. It is the write side of OWASP API3:2023 BOPLA.
## How it works
- The naming depends on the framework: *mass assignment* in Rails and Node, *autobinding* in Spring MVC and ASP.NET MVC, *object injection* in PHP.
- The root pattern is `user.update(request.json)`, or `setAttributes($params, false)` in Yii/Craft (where `false` disables the safe-attribute filter), or `data.pid || nextPid()`. The same model is reused for read and write, and there's no allowlist of writable fields.
- It creates **hidden parameters**. Any field that exists on the model is accepted even though no client ever sends it. That makes the response body, the spec and GraphQL introspection the best sources of candidate keys.
- It's invisible to tooling: no payload, no error, a single request, `200 OK`. WAFs, rate limits and scanners don't fire.
## Techniques / payloads
**Find candidate fields**
- **Read-back diffing.** Compare `GET` and `POST`/`PATCH` bodies for the same object. In the PortSwigger lab, `GET /api/checkout` returned `chosen_discount`, which the `POST` lacked.
- **Response leakage.** Fields such as `role`, `is_verified`, `Profiles`, `credit` and `status` in a create or update response hint that the model will bind them.
- **Specs and introspection.** OpenAPI schemas list every property. GraphQL introspection exposed a `role` field on `User` that a profile mutation then accepted. See [[GraphQL Introspection]].
- **Client code.** Wiz's Red Agent pulled request schemas out of 130 MB of JS bundles and found an `unmaskContactData` boolean the free-tier UI never sent. See [[JavaScript Analysis]].
- **Blind guessing.** Fuzz common names with Burp Intruder: `role`, `admin`, `is_admin`, `is_staff`, `permissions`, `status`, `price`, `approved`.
**Confirm binding.** Send a wrong type first. `"chosen_discount":{"percentage":"x"}` returned a type error, which proves the key is parsed. Then set the real value.
```http
PATCH /api/users/
{"username":"wiener","email":"
[email protected]","isAdmin":true}
POST /api/checkout
{"chosen_discount":{"percentage":100},"chosen_products":[{"product_id":"1","quantity":1}]}
POST /vapi/api6/user # credit field never documented
{"name":"x","username":"x","password":"123456","credit":"1000"}
PUT /api/user/update
{"name":"Normal User","phone":"9XXXXXXXXX","role":"admin"}
{"is_admin":true,"is_staff":true,"permissions":["*"]}
```
**Where it lives:** profile update, registration, admin edit-user, bulk-update endpoints, GraphQL mutations and mobile backends. In practice that's anywhere that accepts JSON via `PUT`/`PATCH`/`POST`.
**What it can change:**
- Privilege: `role`, `Profiles:[{id:1}]`, `isAdmin`.
- Money: `discount_percentage:100`, `price:0.01`, `commission_rate`, `credit`.
- Workflow state: crAPI `PUT /orders/{id}` with `"status":"returned"` refunded a delivered order. Other examples are `approved`, `content_status:"approved"` and `blocked:false`.
- Ownership and identity: internal IDs.
- Feature gates: `unmaskContactData:true`.
## Notable cases
- **GitHub (2012).** Mass assignment let users attach their SSH public key to any organisation.
- **NodeBB `POST /api/v3/topics`.** `req.body` flowed into `Posts.create`, which used `data.pid || incrObjectField('nextPid')`. Sending `"pid":1` re-created the admin's welcome post under the attacker's ownership, who could then edit it in place. Fixed in commit 7f08fb9 by deleting `pid` from the body.
- **Formie (Craft CMS, GHSA-wm3q-jh2w-mm72).** `EmailController` ran `$notification->setAttributes($notificationParams, false)`. Every notification field (`subject`, `to`, `content`…) was attacker-controlled and rendered through Twig, so a front-end user got [[Server-Side Template Injection]]. Combined with missing authorization.
- **B2B contact-data platform (Wiz Red Agent).** Adding `"unmaskContactData": true` to a free-tier search returned unmasked emails and phone numbers across 600M+ contacts and 135M+ verified phones. The server never checked credit balance or tier. It was fixed in under 2 hours.
- **Vaadata grey-box test.** A user-create response exposed `"Profiles":[{"id":5,...}]` (customer). Replaying the create with `Profiles` id `1` produced an administrator.
- **vAPI api6.** Registering with `"credit":"1000"` stuck, and `GET /user/me` confirmed it.
## Defenses
- **Allowlist writable fields per operation**, for example `{k:v for k,v in body.items() if k in ["name","phone"]}`. Use separate request DTOs (`ProfileUpdateRequest`) decoupled from persistence entities. Don't reuse read models for writes.
- **Reject undeclared properties** rather than silently ignoring them. Validate inbound bodies against JSON Schema and enforce `readOnly`/`writeOnly`.
- **Configure the framework's binding controls.** Rails strong parameters, Laravel's mass-assignment protection and Spring's `@ModelAttribute` binding are all permissive until configured. Keep Yii/Craft safe-attribute filtering on: never call `setAttributes(..., false)` on request input.
- **Authorize per field.** Changing `price`, `role` or `status` should need a separate permission check, not just object ownership. Entitlement and pricing flags must be decided server-side.
- Strip internal IDs (`pid`, `user_id`, `created_at`) from bodies before binding.
## Related
- [[API Security]]
- [[OWASP API Security Top 10]]
- [[Excessive Data Exposure]]
- [[API Discovery]]
- [[BOLA in APIs]]
- [[Function Level Authorization]]
- [[Broken Access Control]]
- [[GraphQL Authorization Flaws]]
- [[Server-Side Parameter Pollution]]
See also: [[Business Logic Vulnerabilities]]
## Sources
- [[raw/cobalt.io/api-security-101-mass-assignment-and-exploitation-in-the-wild-3999|API Security 101: Mass Assignment and Exploitation in the Wild]]
- [[raw/vaadata.com/what-is-mass-assignment-attacks-and-security-tips-3998|What is Mass Assignment? Attacks and Security Tips]]
- [[raw/portswigger.net/portswigger-lab-exploiting-a-mass-assignment-vulnerability-4915|PortSwigger Lab: Exploiting a Mass Assignment Vulnerability]]
- [[raw/portswigger.net/api-testing-web-security-academy-2746|API Testing - Web Security Academy]]
- [[raw/spyboy.blog/this-is-how-i-hacked-an-api-using-mass-assignment-vulnerability-4909|This Is How I Hacked an API Using Mass Assignment Vulnerability]]
- [[raw/paloaltonetworks.com/what-is-broken-object-property-level-authorization-4907|What Is Broken Object Property Level Authorization?]]
- [[raw/aikido.dev/finding-eight-high-severity-vulnerabilities-in-nodebb-in-six-hours-10690|Finding eight high-severity vulnerabilities in NodeBB in six hours]]
- [[raw/github.com/formie-missing-authorization-leads-to-ssti-14840|Formie missing authorization leads to SSTI]]
- [[raw/wiz.io/the-red-agent-pov-the-one-boolean-that-broke-a-b2b-platform-s-credit-s-10448|The Red Agent POV: The One Boolean That Broke a B2B Platform’s Credit System]]
- [[raw/medium.com/exploiting-all-10-owasp-api-security-risks-in-vapi-bonus-arena-challen-14687|Exploiting All 10 OWASP API Security Risks in vAPI (+ Bonus Arena Challenges)]]
- [[raw/medium.com/api-security-testing-a-complete-guide-to-reconnaissance-hidden-endpoin-12806|API Security Testing: A Complete Guide to Reconnaissance, Hidden Endpoints, Mass Assignment, and…]]
- [[raw/wiz.io/owasp-api-security-top-10-risks-3712|OWASP API Security Top 10 Risks]]