How it works
Mass assignment comes from a convenience feature. Many frameworks can take a request body and bind it to an object in one line, matching each incoming field name to a property with the same name. That saves a lot of repetitive code.
The trouble is that the object usually has more properties than the form shows. A user record has a display name, and it also has a role, a verification status and a billing tier. If the binding step accepts whatever the client sends, a user can set those internal properties just by adding them to the request. The server never decided to allow it. It simply did not say no.
Attackers find the property names easily. They appear in API responses, in documentation and in the front-end code.
What it looks like
A marketplace lets sellers edit their shop profile. The page has two fields: shop name and description. A seller sends this instead:
PATCH /api/sellers/me HTTP/1.1
Host: api.acme.test
Authorization: Bearer <seller_a token>
Content-Type: application/json
{"shop_name": "Seller A Outlet", "commission_rate": 0, "kyc_status": "approved"}HTTP/1.1 200 OK
Content-Type: application/json
{"id": "seller_a", "shop_name": "Seller A Outlet", "commission_rate": 0, "kyc_status": "approved"}The seller has removed the marketplace's commission and marked their own identity check as passed. Both fields exist on the seller object for staff tools to manage. The public endpoint wrote them because nothing limited which fields it accepts.
The code behind it, and the fix:
// Vulnerable: every key in the body is written to the record.
await Seller.update(req.body, { where: { id: req.user.sellerId } });
// Fixed: only the fields a seller may edit are copied.
const { shop_name, description } = req.body;
await Seller.update({ shop_name, description }, { where: { id: req.user.sellerId } });How to test for it
- Collect property names. Read the full response of every
GETendpoint and note fields that the edit forms do not expose. Check API specifications and client code for more. - Add those fields to write requests. Try create and update endpoints, including registration.
- Read the object back. A
200response alone proves nothing, since many servers ignore unknown fields silently. Fetch the record again and see whether the value changed. - Try other shapes. A field refused at the top level may be accepted inside a nested object, or under a different naming style such as
kycStatus. - Focus on fields with consequences. Roles, ownership, tenant IDs, balances, prices and verification flags.
How to fix it
Decide on the server which fields each endpoint accepts, and ignore or reject everything else.
- Use an allowlist. Name the editable fields explicitly, as shown in the fixed code. A blocklist of forbidden fields fails as soon as someone adds a new sensitive property and forgets to update it.
- Separate input types from data models. Define a small request object for each endpoint, often called a data transfer object (DTO), and map it to the stored model by hand.
- Use the framework's guard. Rails has strong parameters. Django REST Framework serializers list their fields and can mark some as read-only.
- Reject unknown properties. In JSON Schema, that is
additionalProperties: false. - Add a regression test. Send a privileged field as an ordinary user and assert that the stored value is unchanged.
How it relates to other API flaws
In the 2023 OWASP list of API risks, mass assignment belongs to API3, which covers access to individual properties of an object. That entry has two directions: a client writing properties it should not write, which is mass assignment, and a client reading properties it should not see.
It differs from broken object level authorization, where the user reaches a whole record that is not theirs. Here the record is their own, and the problem is which parts of it they can change. It also differs from broken function level authorization, where the user calls an operation meant for another role. Mass assignment often produces the same outcome, privilege escalation, through an endpoint the user is fully entitled to call.