Mass assignment: when an API binds fields the client should not set
Mass assignment happens when a framework copies request parameters straight into an object, and the client sends fields the developer never meant to expose, such as a role or a price. The OWASP API Security Top 10 2023 files it under API3, Broken Object Property Level Authorization, in the OWASP API Security Top 10 2023 list. It is a close cousin of BOLA: BOLA asks whether you may touch this object, and this flaw asks whether you may change this field. The guide belongs to API security.
Quick facts
- OWASP category
- API3:2023 Broken Object Property Level Authorization, which merges the 2019 entries Excessive Data Exposure and Mass Assignment
- Weakness ID
- CWE-915, Improperly Controlled Modification of Dynamically-Determined Object Attributes
- Other names
- Autobinding in Spring MVC and ASP.NET MVC, object injection in PHP, mass assignment in Ruby on Rails and Node.js, per the OWASP Mass Assignment Cheat Sheet
- Root cause
- Input is bound to an object without saying which fields the caller may set
- Main fix
- Allow-list the writable fields, or bind to a separate object that holds only those fields
- Does a WAF fix it?
- No. A request that adds one extra field is ordinary JSON. Which fields a caller may set is a rule of your application
Sources: the OWASP API3:2023 page, the OWASP Mass Assignment Cheat Sheet and CWE-915 at MITRE.
What mass assignment is
Web frameworks save time by binding request parameters to program objects automatically. A form posts a name and an email, and the framework fills a User object. The shortcut turns into a flaw when the object has more fields than the form does. According to the OWASP cheat sheet, attackers can use this to create parameters the developer never intended, and they can guess or discover field names without access to the source code. Forgotten API versions are another source of exposed fields: shadow APIs.
The cheat sheet's own example is a user-edit form bound to a class with userid, password, email and an isAdmin flag. The form never submits isAdmin. An attacker adds it to the request body anyway, and the framework sets the privileged field. Nothing was broken into; the server did what the binding code told it to do.
PATCH /api/profile
{"displayName": "Sam"} what the app sends
{"displayName": "Sam", "role": "admin"} what a client can send instead
handler: user.update(request.body) every key in the body is applied
The weakness has a formal name, CWE-915. MITRE describes it as a product that receives input naming multiple attributes to initialise or update in an object, but does not properly control which of those attributes may be modified. The platform vocabulary differs, as the table shows, but the flaw is the same one.
| Name | Where it is used |
|---|---|
| Mass assignment | Ruby on Rails and Node.js |
| Autobinding | Spring MVC and ASP.NET MVC |
| Object injection | PHP |
Why it is an authorization flaw
OWASP moved mass assignment out of its own slot in the 2023 edition. API3:2023 now covers any failure to check whether a caller may read or write a specific property of an object, and the page says the earlier risks, Excessive Data Exposure and Mass Assignment, are its two halves. The first half is a response that returns properties the caller should not see. The second is a request that changes properties the caller should not control. The impact OWASP lists runs from data disclosure, loss and corruption to privilege escalation and account takeover in some cases.
The three attack scenarios on the OWASP page show the range, and none of them needs more than an ordinary request:
- A booking marketplace. A host adds a
total_stay_pricefield to an approval request, and the guest is charged the inflated amount. The endpoint never asked whether a host may set that field. - A video platform. A user adds
blocked: falseto an update request and unblocks their own video. The endpoint did not check who may change that property. - A dating app (the read half). A GraphQL mutation returns the reported user's full name and recent location to people who should never see them.
How it differs from BOLA and IDOR
In BOLA, the caller reaches another user's object by changing an identifier; the older name for the same bug class is IDOR. In mass assignment the caller may be entitled to the object, because it is their own profile, and still overreach on a field inside it. The checks sit at different levels. An API can pass the object-level test on every route and still fail at property level. Both flaws are about what a valid, signed-in caller is allowed to do, so neither shows up in a login check; the API authentication page covers who the caller is, and this page covers what that caller may change.
Where it hides
Any route that creates or updates an object from a request body is a candidate. The risk grows with how much of the stored object the body can reach.
- Write methods. RFC 9110 defines PUT as replacing the state of the target resource with the enclosed representation, and RFC 5789 adds PATCH for partial changes. Each of these, plus POST, can feed an object binder. The HTTP methods guide lists which methods a route should accept at all.
- Models that carry privileged state. A single class used for storage, for input and for output is where trouble starts. Fields such as an admin flag, an owner, a price or a blocked status sit next to harmless ones, and the binder treats them alike.
- Generic serialization on the way out. OWASP warns against generic serialization methods and says to select the specific properties to return. The same convenience that binds every input field often returns every stored field.
- Routes nobody listed. Old versions and undocumented routes keep their binders too. Keeping an inventory of routes is part of the API endpoint security checklist.
How to prevent it
All sources agree on the core idea: state what may be written, and refuse the rest. The options below come from the OWASP cheat sheet, the API3 prevention list and the mitigations on CWE-915.
| Defence | What it does | Caveat |
|---|---|---|
| Allow-list of fields | Binding accepts only the fields named. The cheat sheet's examples are Spring setAllowedFields, Mongoose field picking and Laravel $fillable | Each new writable field must be added on purpose, which is the point |
| Separate input object (DTO) | Input binds to an object that holds only user-editable fields, so sensitive properties never receive input | The copy from that object to the stored one must also be explicit |
| Block-list of fields | Excludes named fields, such as Spring setDisallowedFields or Laravel $guarded | The cheat sheet says not to rely on it alone: a new or overlooked field stays bindable. CWE-915 prefers allow-lists |
| Schema validation | OWASP recommends validating responses against a schema and returning the minimum each endpoint needs | A schema that lists a field as optional still allows it, so write only the fields a role may set |
| No dynamic attribute names | CWE-915 suggests refactoring so object fields are not identified dynamically, exposing setters only for the intended ones | Larger change in code that already relies on a binder |
Allow-lists limit which fields are writable. They do not decide who may write them. The cheat sheet says DTOs and allow-lists do not replace authorization checks on the requested object and operation. A field such as a price may be writable for a seller and read-only for a buyer, and that rule needs code of its own. The API3 page puts the test plainly: validate that the user has access to the specific object properties they are trying to read or write.
How to check your own API
Run these checks on a staging copy of your own service, never on someone else's. The goal is to learn what each write route really accepts.
- List every write route and the model behind it. Note which stored fields the route is meant to change and which it must never change.
- Compare the documented body with the binder. If the handler passes the whole body to an update call, every stored field is writable, whatever the documentation says.
- Send one extra property per role. As a normal user, add a field you know is privileged, and check that the stored value did not change. Repeat for each role. The expected result is that the field is ignored or the request is rejected.
- Read the responses too. If a response returns more properties than the screen shows, the read half of API3 is open.
- Make it a regression test. A test that fails when a privileged field becomes writable catches the change the day someone adds a field to the model.
More on how to organise this work is on API security testing. Mass assignment also overlaps with business logic flaws, because a writable price or status field is a logic gap before it is anything else.
Where a WAF helps and where it does not
A WAF filters requests before they reach your application. It does not read your data model, and it does not know that role is writable on one route for one kind of user and not on another. A JSON body with an extra key is valid JSON, sent by a valid client to a valid route. Nothing in its shape is an attack signature, so the fix cannot live at the edge. The allow-list belongs in your code, and a filter does not replace it.
What a filter can add is limited. Bridge WAF is documented for matching named attack categories and for rate limiting per domain, so do not expect it to enforce a field-level rule on your API. Rate limits still have a use here, since the cheat sheet notes that attackers can guess field names without source code, and guessing takes repeated requests. Capping write requests per client slows that down, and a client over the cap gets a 429 response. What counts as one client is covered on per-IP vs per-user limits.
Start in monitor mode. Matches are logged while every request is still served, so you can read the monitor-mode log and see what a filter would flag before turning on block. Expect it to say nothing about a well-formed request that sets the wrong field. The three modes are in the box below.
Questions
What is mass assignment?
Mass assignment is a flaw where a framework binds request parameters straight to an object and the client sets fields the developer never meant to expose, such as an admin flag. OWASP now lists it as part of API3:2023, and MITRE tracks it as CWE-915.
How do you prevent mass assignment?
Allow-list the fields a request may set, or bind input to a separate object that holds only editable fields. Do not rely on a block-list alone, because a new field stays bindable. Keep a separate authorization check on who may change each property.
Is mass assignment the same as BOLA?
No. BOLA lets a caller reach another user's object by changing an identifier. Mass assignment lets a caller change a field they should not control, even on an object they own. OWASP lists them as separate entries, API1 and API3.
Why is mass assignment called autobinding or object injection?
The name depends on the platform. The OWASP cheat sheet says autobinding is used in Spring MVC and ASP.NET MVC, object injection in PHP, and mass assignment in Ruby on Rails and Node.js. The weakness underneath is the same.
Can a WAF stop mass assignment?
Not reliably. A request with one extra field is ordinary JSON, and a WAF does not know which fields your users may set. It can rate-limit write endpoints and log flagged requests, while the allow-list stays in the application.