Mass assignment: the field that was not in the form
Mass assignment is when the server copies all request fields into the model and the client adds extras, such as role or credit. In the OWASP API Top 10 2023 it falls under BOPLA. The fix is an explicit allowlist of fields at request-schema level plus a separate response object; a blocklist misses a forgotten field. QA adds fields from a GET response to a POST or PATCH and re-reads the object.
Pentest · Access control
The profile form has three fields, the JSON response has nine. What if you send a tenth?
The profile form has the fields "Name", "Phone" and "City". The API response to GET /api/profile also shows role, verified, credit and others. A developer wrote one line that saves the whole request body into the model. So a request with an extra role field changes the role. The lesson explains the mechanism, how QA finds such fields and what fixes them.
Mechanism. Many frameworks can automatically copy request fields into an object or a database record: Rails, Django ModelForm, Spring (binding a body to an entity), Mongoose Model.create(req.body), Sequelize update(req.body). It is convenient, but the list of fields is decided by the client, not by the server. In the OWASP API Security Top 10:2023 this flaw, together with showing too many fields in a response, is called BOPLA (Broken Object Property Level Authorization, API3): a question about rights to individual properties of an object, not to the object as a whole.
What is sent and what should reach the model
Worked example. An authorized environment, an ordinary user’s account. The tester takes the fields from the GET response and adds them to a profile update:
PATCH /api/profile HTTP/1.1
Authorization: Bearer <token-user>
Content-Type: application/json
{"name": "Alice", "role": "admin"}
HTTP/1.1 200 OK
{"id": 5, "name": "Alice", "role": "admin"}
The response could lie too (return just what was sent), so the next step is to read the profile with a separate request and compare. If role really changed, this is a high-severity finding: an ordinary user became an admin.
A typical cause and the fix on the server:
// before: the client chooses the fields
await User.findByIdAndUpdate(req.user.id, req.body);
// after: an explicit allowlist, unknown keys are rejected
const Body = z.strictObject({ name: z.string().optional(), phone: z.string().optional() });
await User.findByIdAndUpdate(req.user.id, Body.parse(req.body));
z.strictObject in zod rejects unknown keys: parse throws and the handler answers 400. Silent ignoring is also safe as long as the field does not reach the database, but an error is more useful: it shows up in tests. A closed list (allowlist) is more important than a "blacklist" (remove role and isAdmin): a blacklist always misses a field somebody forgot about.
A real case. On 4 March 2012 a GitHub user used the public key update form, added his own key to the rails organization and pushed a test file to the repository to prove the problem. According to GitHub’s own description, the cause was mass assignment: the server did not check which form parameters it accepted. A fix shipped in about an hour, and after the incident the team audited the whole codebase for similar cases. The lesson for the whole ecosystem: frameworks had to move to explicit lists of permitted parameters (in Rails this became strong parameters).
What else to check.
- Creation. Add
id,ownerId,price,statustoPOST. An order with"price": 0.01or someone else’sownerIdis already a business-logic violation and IDOR; - Reading. The other side of the same flaw: the response has extra fields (a password hash, internal flags). A separate response object hides them;
- Roles. Some fields may be changed by an admin but not by a user: the permitted set depends on the role.
Common mistakes. Hiding a field only in the form (the client sends anything); closing only known "dangerous" names; verifying a change by the response alone instead of reading again; treating only escalation to admin as the flaw, although changing emailVerified or credit is no less serious.
Check yourself
A developer removed role and isAdmin from the accepted body, but the model also has credit. Why is the approach unreliable?
Answer
That is a blacklist: it closes only known names. Every new model field is open until someone remembers it. The reliable approach is an explicit allowlist of the fields the client may really change.
The response to a PATCH with an extra field returns 200 without that field. Does this prove the field was ignored?
Answer
No. The response may show only permitted fields while the value has already reached the database. Read the object with a separate request (or as an admin) and compare.