Mass assignment
| Class | Access control |
|---|---|
| Also known as | Autobinding (Spring MVC, ASP.NET MVC), object injection (PHP) |
| CWE | CWE-915: Improperly Controlled Modification of Dynamically-Determined Object Attributes |
| OWASP Top 10 | A08:2025 Software or Data Integrity Failures |
| OWASP API Top 10 | API3:2023 Broken Object Property Level Authorization |
| Typical severity | High when a role, owner or price field is writable |
| Affects | Routes that pass a whole request body to a create or update call; database tables whose update rules cover every column |
A profile form sends two fields, a display name and a short bio. The route that receives it hands the whole request body to the database library, which writes every key it finds into the user's row. A visitor who opens the browser's developer tools and adds "role": "admin" to the same request gets that column written too. The flaw is called mass assignment, a vulnerability in which the server lets a request choose which fields of a record it sets, and never limits that choice to the fields the user is allowed to change.1
How binding creates the flaw
Many web frameworks copy request parameters into an object for the developer, matching each parameter name to a property of the same name. The feature saves code. It also hands the choice of which properties change to whoever writes the request, since a parameter the form never showed is bound as readily as one it did.2
The vulnerable form in a Node.js route with the Mongoose library is one line:
// Every key in the body becomes a field on the new user
const user = new User(req.body);If the User schema has an isAdmin field that the form leaves out, a request that posts the form's fields plus isAdmin=true creates the user with that flag set.2
The attacker does not need the source code.2 The API's own responses show most field names, and hidden ones turn up by Fuzzing: sending many candidate names and checking which ones change the record. When a field is never returned, its effect has to be read from what the app does afterwards.3 Nested objects in the body are bound the same way and need the same review.2
What a writable field gives away
The damage depends on which column the request can reach. A writable role or isAdmin column makes a normal account an administrator, and a writable account owner can lead to partial or full account takeover.23 In one documented scenario a host approving a booking adds "total_stay_price": "$1,000,000" to the approval request, and the guest is charged that amount. In another, a user whose video was blocked adds "blocked": false to a description edit and unblocks it.3 Each body was a valid request to an existing route with one extra key. Price and status fields of this kind overlap with Business logic flaws.
GitHub, March 2012
At 8:49am Pacific time on 4 March 2012 a GitHub user used the public key update form to add his own key to the rails organization, then pushed a new file to the Rails repository to show that it worked. GitHub removed the key, suspended the user and rolled out a fix at 9:53am. Database and log analysis found three compromised accounts: rails and two that appeared to be proofs of concept. GitHub gave the root cause as a failure to check incoming form parameters and started a full audit of its codebase.4
The flaw came from a Rails default. The framework let a request update any attribute, and its allowlist macro attr_accessible and denylist macro attr_protected were both off unless a developer turned them on. On 1 March the same user, Egor Homakov, had opened an issue against Rails about the default. On 2 March he used GitHub's own flaw to file a second issue dated in the year 3012, and the first issue was then closed with the comment that the pros of the default configuration outweighed those of the alternative. Soon after the key incident, a fix was committed to Rails that required developers to allowlist every attribute with attr_accessible.5
Fields and records
The 2023 edition of the API Security Top 10 merged its 2019 items Mass Assignment and Excessive Data Exposure into one. An endpoint now fails that item when it returns a sensitive property the user should not read, or accepts a change to one the user should not touch: both are a missing check on single fields.3 Insecure direct object reference is the same missing check one level up, on a whole record. A field allowlist does not replace the Authorization check on the record and the action, and a route needs both.2
Prevention
The fix is a list of the fields each route may write. A denylist of dangerous fields fails the day someone adds a new sensitive column and forgets to add it to the list.21 A separate input object (often called a DTO, data transfer object) that holds only the editable fields does the same job by design.2
| Stack | Allowlist | Opens every field |
|---|---|---|
| Node.js, Mongoose | new User(_.pick(req.body, ["userid", "password", "email"])) | new User(req.body) |
| Zod schema | z.object({ name: z.string() }) drops other keys; z.strictObject() rejects them | z.looseObject() |
| Rails | params.expect(user: [:username, :password]) | permit!, expect(user: {}) |
| Laravel | protected $fillable = ['name']; | protected $guarded = []; |
| Supabase, Postgres | grant update (title, content) on table public.posts to authenticated; | The default table-wide UPDATE grant |
Zod strips unknown keys from the parsed result by default, so a route that writes the parsed value instead of the raw body is already filtered, and z.strictObject() turns the extra key into an error (see Input validation).6 Rails refuses to mass-assign parameters that were not permitted and raises ActiveModel::ForbiddenAttributesError, while permit! and an empty hash in expect allow every present and future attribute.7 Laravel models refuse mass assignment until $fillable or $guarded is set, and Model::preventSilentlyDiscardingAttributes() throws when code tries to fill a field outside the list, which shows mistakes during development.8
Supabase apps where the browser writes to the database directly have the same flaw one layer down. A row level security update policy such as auth.uid() = user_id decides which rows a user may update, but on every column of those rows, and the authenticated role starts with a table-wide UPDATE privilege. Revoking that privilege and granting update on named columns closes it.9 A restricted role can then no longer run select * on the table and has to name each column. Supabase calls column privileges an advanced feature and, for most apps, recommends row level policies together with a dedicated roles table instead (see Row level security).9
Prompt for a coding agent
Find every route, server action and database function in this project that creates or updates a record from request data. Flag each place where the whole request body, form data object or parsed JSON is passed to a create, update, insert or upsert call, or spread into one. For each, write an explicit list of the fields that this route lets the user change, and pass only those. Fields such as role, is_admin, owner or user_id, price, balance, status and created_at must never come from the request. Where a schema library is used, make sure the parsed value is what gets written, not the raw body. List each file and line you changed and the fields you allowed.
In SecFlash
SecFlash reports code that copies a whole request into a database record as SF-SEC-740 on the Security page, with the file and line.
See also
- Input validation
- Authorization
- Insecure direct object reference
- Row level security
- Business logic flaws
- OWASP API Security Top 10
- Category: Access control
References
- a b "CWE-915: Improperly Controlled Modification of Dynamically-Determined Object Attributes". Common Weakness Enumeration. MITRE (version 4.19, 11 December 2025).
- a b c d e f g h "Mass Assignment Cheat Sheet". OWASP Cheat Sheet Series.
- a b c d "API3:2023 Broken Object Property Level Authorization". OWASP API Security Top 10. OWASP Foundation.
- back Preston-Werner, Tom (4 March 2012). "Public Key Security Vulnerability and Mitigation". The GitHub Blog.
- back Willis, Nathan (7 March 2012). "GitHub incidents spawns Rails security debate". LWN.net.
- back "Defining schemas". Zod documentation.
- back "Action Controller Overview", section 4: Strong Parameters. Ruby on Rails Guides.
- back "Eloquent: Getting Started". Laravel 12.x documentation.
- a b "Column Level Security". Supabase Docs. Supabase (updated 23 October 2026).
External links
- Mass Assignment Cheat Sheet, OWASP Cheat Sheet Series