The scanner added "role": "admin" to the request body and the API returned 200. Was the field actually written? Mass assignment (OWASP API3:2023, CWE-915) as a DAST finding: echo versus persisted state versus granted authority, aliases, case and nesting, PATCH versus PUT versus create, form versus JSON, and which fixes held

DedSec Security Research ·

Here is a hypothetical. A dynamic scan of a JSON API returns three results about mass assignment.

The first is "Mass assignment: privileged field accepted", rated high, on PATCH /api/users/me. The scanner sent {"name": "test", "role": "admin"} and the 200 response contained "role": "admin". The second is a low, "Mass assignment (blocked)", on PUT /api/account. The scanner sent the same role and the response came back with "role": "user", which the team reads as the server ignoring the field. The third is not a finding. The scanner sent role to POST /api/users, got a 201 with a user object that had no role key at all, and recorded the create endpoint as clean.

The high gets escalated, the low gets closed, and the clean result goes in the report. As elsewhere in this series, each decision rests on what the first response looked like, not on what that response can prove. In our lab, built to reproduce the three shapes, the echoed "role": "admin" came from an endpoint that saved only allowed fields and then echoed the request body back; it wrote nothing privileged in any trial. The "blocked" endpoint dropped role and accepted Role, is_admin and a nested account.plan, every time. And the create endpoint that returned no role key stored "role": "admin" in every trial, and the new account could open the admin page.

This post is for whoever is holding a mass-assignment finding from a dynamic scan, or a clean result they are about to rely on. It covers:

It belongs to our series on confirming DAST findings; the series guide sets out the evidence classes the series uses. Two earlier posts touch this class and this one does not repeat them. The Arjun parameter-discovery post is about how a scanner finds a name such as role in the first place, and it found one in our lab only in JSON mode. The BOLA and IDOR post places property-level authorisation (API3:2023) next to object-level (API1) and function-level (API5) authorisation, and explains why a write needs a side-effect oracle. This post starts where those stop: the field name is known, the scanner sent it, and the question is what happened.

How we tested. Everything ran on 19 November 2026 on a virtual machine with two vCPUs, Ubuntu 24.04.4 and kernel 6.8.0. One origin was Node.js 22.22.2 with Express 5.3.0, and Mongoose 9.12.2 for four of its variants. The other was Python 3.12.3 with Flask 3.1.3, Werkzeug 3.1.9, SQLAlchemy 2.1.9 on SQLite, and Pydantic 2.14.4. Both are deliberately vulnerable applications we wrote. Each user record has a name, an email, a role ("user" or "admin"), an admin boolean (isAdmin on Express and is_admin on Flask, a naming choice we made for the lab), an account object holding plan and seats, and a profile holding bio. An admin page answers 200 if role is "admin" or the admin flag is truthy, and 403 otherwise. A premium page answers 200 if account.plan is "enterprise". The Mongoose variants use Mongoose's document binding (constructing, set(), overwrite() and toObject()) against an in-memory store. No MongoDB server ran. Everything listened on 127.0.0.1, and all packages were installed inside the lab directory.

The client was a Python harness on http.client, opening a new connection for every request. A cell is one binding implementation, one method and one payload shape, and each cell ran 20 trials. Every trial reset the store, logged in as the test user, confirmed that the admin and premium pages returned 403, sent the payload, read the record back with a separate GET as the same user, read the stored record through a lab-only endpoint the scanner would not have, and then requested the admin or premium page with the existing session and with a new one. For POST create, the new account logged in after creation. There were 20 implementations, 9 payload shapes and 3 methods: 540 cells, 10,800 trials and 111,600 requests. All 10,800 baselines were 403 on both pages, and in all 540 cells, the 20 trials agreed on every recorded outcome (status, echo, read-back, stored value, authorisation, seats and bio). One JSON line per trial is archived with the lab.

This lab measures our own handler code on those library versions. It is not a measurement of Rails, Django REST framework, Spring, ASP.NET, NestJS or any other framework, of a MongoDB server, or of any scanner, ours included.

How a request body reaches a field nobody exposed

Mass assignment is catalogued as CWE-915, Improperly Controlled Modification of Dynamically-Determined Object Attributes. In the OWASP API Security Top 10 2023, it is half of API3:2023, Broken Object Property Level Authorization; the 2019 list had it as a separate entry, API6:2019 Mass Assignment. The bug is not in any one line. It is the gap between the fields a form or client shows and the fields the binding code will accept.

Four binding styles produced every write in our tables.

Copy the whole body onto the record. Object.assign(user, req.body) for an update, {...defaults, ...req.body} for a create, {...req.body, id} for a replace. Every key the client sends becomes a property. Our assign variant wrote role, isAdmin and account.plan in 20 of 20 trials per cell, on all three methods and in both encodings.

Loop over the keys and set any attribute that exists. The Python version is for k, v in data.items(): if hasattr(User, k): setattr(user, k, v). The hasattr guard looks protective, and it is the opposite: it guarantees that every real column is writable. Sent as JSON, our setattr variant wrote role, is_admin and a nested account in 20 of 20 trials per cell. It did not write isAdmin or Role, because the model has no attribute with those names.

Validate the body against a schema that includes the field. A model or schema used for both reading and writing declares role because the read side needs it. Our pydantic-shared-forbid variant used one Pydantic model with extra="forbid", and it wrote role, is_admin and account.plan in 20 of 20 trials per cell. Mongoose's default strict mode wrote role, isAdmin and account.plan in 20 of 20, because all three are in the schema. Strictness about unknown keys says nothing about known keys the caller should not set.

Merge nested objects field by field. A deep merge applies {"account": {"plan": "enterprise"}} to the existing account, keeping seats. A shallow copy replaces account with the attacker's object. Both wrote the plan. The difference shows up later, as a side effect.

Three evidence classes, and how often each was wrong

A scanner sees the response to its own request. A tester can also read the record back with a separate request, and can check whether the privilege works. Our harness could see the stored record as well, which is the ground truth none of them has. Over all 10,800 trials:

ObservationTrialsOf those, privileged value actually stored
2xx response echoed the injected key with the injected value4,5003,180
Privileged value stored4,0804,080
Of the stored: the key as sent was not echoed900900
Of the stored: neither the key as sent nor the real field showed the value600600
Of the stored: a read-back GET did not show the value600600
Of the stored: the admin or premium page opened on a new session4,0804,080
Of the stored: it opened on the session that sent the payload3,9203,920

Three rows decide how to read a mass-assignment finding.

An echo is not a write. In 1,320 of the 4,500 echo trials, nothing privileged was stored. These came from two mechanisms: 540 from a handler that echoed the request, and 780 where the key was stored under the wrong name.

No echo is not no write. Our assign-public and setattr-public variants bound the whole body and then answered through a public serializer that lists id, username, name, email and profile and nothing else. The read-back GET used the same serializer. In 600 trials, 360 on Express and 240 on Flask, the privileged value was stored, the response did not show it, the GET did not show it, and the admin or premium page opened on a fresh session. A scanner that tests mass assignment by looking for its value in the response marks all 600 as clean. This is also why a read-back on its own is not enough. In our lab, a read-back that showed the value was never wrong (0 trials showed a privileged value that was not stored), but it missed every write a serializer hid.

The effect is the evidence, and it has to be checked on a new session. Our session-cached variant took the role into the session at login and read it from there. After a PATCH or PUT that stored role: "admin" or isAdmin: true, the admin page stayed 403 on the session that sent the payload in 160 of 160 trials, and opened on a new login in 160 of 160. The same pattern can appear with role claims inside a signed token, which stay as issued until the token is reissued; the JWT post covers how a server checks a token's claims, including expiry and logout. A tester who checks the privilege with the probing session can watch a real escalation fail. In the other direction, across all trials, nothing granted access without a stored value: 0 of 10,800.

Payload shapes: case, aliases and nesting

Each row is one implementation and each column one shape, sent as JSON on PATCH, with 20 trials per cell. "Stored" means the privileged value, under the field the authorisation check reads.

ImplementationroleRoleisAdminis_adminaccount.plan (nested)
Express Object.assignstored, 20/20stored as Role, inertstored, 20/20stored as is_admin, inertstored, 20/20
Flask setattr loopstored, 20/20not storednot storedstored, 20/20stored, 20/20
Mongoose, strict defaultstored, 20/20droppedstored, 20/20droppedstored, 20/20
Mongoose, strict: "throw"stored, 20/20400stored, 20/20400stored, 20/20
Express denylist of role, isAdmin, then key normalisationdroppedstored, 20/20droppedstored, 20/20stored, 20/20
Same denylist after normalisation, case-insensitive, every leveldroppeddroppeddroppeddroppedstored, 20/20
Flask denylist of role, is_admin, then snake_case normalisationdroppedstored, 20/20stored, 20/20droppedstored, 20/20

Two things follow.

Which alias works depends on the binder, so send all of them. is_admin was inert under Express binders that do not normalise keys and live on Flask, and isAdmin the reverse until a normalisation step mapped it. Role was inert everywhere until a normalisation step turned it into role. A probe list with one spelling per field tests one binder.

A denylist is only as good as the step it runs before. Our Express and Flask denylists checked the raw keys and then normalised them, Role to role, is_admin to isAdmin on Express and isAdmin to is_admin on Flask, which is one thing an API may do when it accepts both naming styles. The denylist saw a name it did not list, and the normaliser then produced one it did. Our Express denylist, moved after normalisation and applied case-insensitively at every level, closed both of those. It still let account.plan through in 20 of 20 trials per cell, because plan was never on the list. We did not test a Flask denylist after normalisation. A denylist protects the fields someone remembered. Billing plan, tenant or organisation ID, owner ID, email-verified flags, credit balances and feature flags are examples of fields a list can leave out.

PATCH, PUT and POST create can be different code

Our patch-only-fixed variant models a partial fix: someone fixed the update endpoint the finding named. PATCH used explicit field picking. PUT and POST create still copied the whole body.

MethodTrials where a privileged value was stored
PATCH0 of 180
PUT120 of 180
POST create120 of 180

The 120 are the six shapes that the copy accepts (role, isAdmin and the nested plan, as JSON and as a form) at 20 of 20 each. "Make yourself an admin" sounds like an update, but on create there is no existing record to protect, and a signup or invite endpoint that binds the body creates an account with whatever role the caller asked for. Retesting only the method in the original finding would have passed this fix, a version of the "ran on less than you think" failure the scan-passed post describes.

PUT has a second problem. In our assign variant, PUT replaced the record with the body plus id and username, so every field the client did not send disappeared. That is replace semantics. Every replace-style PUT variant in the lab lost unsent fields this way (see the side effects below), and it is a reason a scanner's PUT probe can damage the test record even when it fails as an attack.

Form encoding versus JSON

The same field names, sent as application/x-www-form-urlencoded:

Implementationrole=adminisAdmin=trueis_admin=trueaccount[plan]=enterprise
Express Object.assign, express.urlencoded({extended: true}) on the routestored, 20/20stored, 20/20 (string "true")inertstored, 20/20
Express Object.assign, JSON parser only on the routenot storednot storednot storednot stored
Flask setattr loop over request.formstored, 20/20not stored500, 20/20not stored
Flask, one Pydantic model for read and writestored, 20/20422stored, 20/20 (coerced to true)422

Four mechanisms are in that table.

Whether the form works depends on the route's parsers, not on the binder. With only a JSON parser mounted, our Express route never saw the form fields. With the extended parser, which builds nested objects from bracket syntax, account[plan]=enterprise became {account: {plan: "enterprise"}} and was stored. Flask's form dictionary keeps account[plan] as a literal key, which no column matched.

Strings reach typed fields differently. Each form leaf value arrives as a string. On Express, isAdmin was stored as the string "true", and the admin check, written as a truthiness test, opened the page in 20 of 20 trials per cell. On Flask, SQLAlchemy's Boolean column refused the string "true" and the request failed with a 500 in 60 of 60 trials across the three methods, with nothing stored. Across the three Flask variants that hit this (the two setattr loops and the denylist), all 180 500 bodies contained the SQL statement, and the 120 on PATCH and PUT also began listing the bound parameters, including the submitted value, because our toy error handler returned the exception text, which is a separate finding. Pydantic's default lax mode converted "true" to True before SQLAlchemy saw it, and the value was stored in 60 of 60. In that cell, the validation layer is what made the form attack work.

A 500 is not a write. A scanner that reports "server error on privileged field" as a probable mass assignment would have been wrong on all 180 of those 500s: none stored a privileged value.

Testing JSON only misses the form path, and the reverse. The Arjun post found role in JSON mode and not in form mode on an echo endpoint. Here the binder accepted both encodings on some routes and one on others.

What the probe changes

A mass-assignment probe that works is a write to a real record, and one that fails can still be a write. We saw five side effects, each in 20 of 20 trials per cell:

The general practice that follows: run mass-assignment probes only with dedicated test accounts that you can delete or restore, never with a real user's account, and record the record's state before the probe so it can be put back. A probe that escalates a test account in production has created a production administrator, and the harness has to log out and delete that account as part of the test. Before every PUT probe, snapshot the record and restore it afterwards, and send a full, valid body in an encoding the route actually parses. A full body is not enough on its own: in our lab, a form-encoded PUT to a route that only parsed JSON reached the handler with no body and wiped the record in 80 of 80 trials, and replace-style PUT handlers, including Mongoose overwrite(), lost the unsent profile.bio and account.seats in 180 of 180 trials per variant (120 of 180 where the other 60 were 400s).

Confirming a mass-assignment finding

  1. Get the field list from somewhere other than guessing. The read side of the API can name the fields the write side should not accept, as our GET responses did: the GET response, an OpenAPI schema, client JavaScript, admin UI requests. Add privileged names such as these (role, roles, isAdmin, is_admin, admin, permissions, plan, tier, org_id, tenant_id, owner_id, verified, email_verified, balance).
  2. Use two test identities that you control, and record a baseline. Before any probe, confirm what each one can and cannot do: an admin page, a premium feature, another tenant's record.
  3. Send each candidate in every spelling and position. Exact, camelCase, snake_case and leading capital; top level and nested under the object that holds it; as JSON and as a form; on PATCH, PUT and every create, signup or invite endpoint. For each PUT, snapshot the record first so it can be restored, and send a full, valid body in an encoding the route parses.
  4. Record the first response, and do not decide on it. In our lab, an echoed value was not stored in 1,320 of 4,500 trials, and a stored value was not echoed in 900 of 4,080.
  5. Read the record back with a separate request, ideally as the second identity or through an admin view that shows every field. Treat a read-back that shows the key as sent, but not the field the application uses, as inert until proven otherwise.
  6. Test the effect on a new session. Log out and back in, or obtain a new token, and try the action the field should grant. In our lab, that was the only check that agreed with the stored truth in every trial.
  7. Restore the test records, and delete any account the probe created.

What to record: the endpoint, method, encoding and exact key path that worked; the response; the read-back; the before-and-after authorisation results with the session used; and how the record was restored.

Fixes, and what they cost

Totals per implementation, over all 3 methods and 9 shapes (540 trials each).

ImplementationPrivileged value storedResponses
Express explicit field picking (allowlist)0 of 540200 or 201
Express schema rejecting unknown keys at every level0 of 540400 in 540 of 540
Flask, Pydantic write model without privileged fields, extra="ignore"0 of 540200 or 201
Flask, Pydantic write model without privileged fields, extra="forbid"0 of 540422 in 540 of 540
Flask, one Pydantic model for read and write, extra="forbid"300 of 540422 in 240, otherwise 2xx
Mongoose, strict default360 of 5402xx
Mongoose, strict: "throw"360 of 540400 in 180, otherwise 2xx
Mongoose, privileged paths immutable120 of 540, all on create2xx
Express denylist before normalisation300 of 5402xx
Express denylist after normalisation, every level120 of 540, all account.plan2xx
Flask denylist before normalisation180 of 5402xx, 500 in 60
Express, PATCH fixed only240 of 540, all PUT or POST2xx

Picking fields explicitly held, and it is the fix that does not depend on remembering the dangerous ones. Our allowlist copied name, email and profile.bio and nothing else. It is the same idea as Rails strong parameters, Django REST framework's declared serializer fields and read_only_fields, and Spring's WebDataBinder.setAllowedFields, which applies to form and model-attribute binding rather than to JSON bound with @RequestBody. These are general practice we did not test. The cost is one line per field, and a new field is not writable until someone adds it, which is the point.

A write model that does not contain the field held, and extra decides what the caller sees. With extra="ignore", which is Pydantic's default, unknown fields disappeared silently, and the client got a 2xx. That is safe, and when the response also omits the field, a scanner cannot tell it from a vulnerable endpoint that serializes the field away. Our toy returned "role": "user", which at least showed the value had not changed. With extra="forbid", every probe got a 422 naming the offending key. That breaks clients that send extra keys, and it gives a scanner, and a developer, an unambiguous answer.

Rejecting unknown keys only works if the privileged keys are unknown. Our hand-written Express schema and the forbidding Pydantic write model held because neither listed role. The same extra="forbid" on a model that declared role stored it in 300 of 540 trials, and Mongoose strict stored everything in its schema in 360 of 540. strict: "throw" turned unknown keys into a 400 and changed nothing about role. Separate the model you write from the model you read.

A read-only flag has to cover create as well. Mongoose immutable stopped every privileged write on update in our lab (0 of 360 on PATCH and PUT). Its PUT path still lost unsent fields, as every replace-style PUT in the lab did, which is the handler and not the flag. It allowed the field on create in 120 of 180 trials, which is consistent with our reading of the option: it allows setting the field while the document is new. It also erased the plan on a nested set, as described above. If a field must never come from a client, take it out of the input, not just out of updates.

Denylists were bypassed by whatever they did not list. Before normalisation, by a capital letter or the other naming convention. After normalisation, by the field nobody remembered.

Put privilege changes behind their own endpoint and check. Role changes, plan changes and ownership transfers belong in endpoints that only an administrator or the billing system can call, with their own authorisation check. That turns a property-level question into a function-level one, where the check sits in one place instead of in every binder.

Read authority from the stored record, or reissue the session when it changes. The session cache that hid our escalation is not a defence. The attacker logs in again. It is worth knowing about in the other direction too: a legitimate demotion that does not invalidate sessions leaves the old privilege live.

The static side

Mass-assignment sinks can be visible in code. In JavaScript, look for Object.assign(model, req.body), spreads of req.body into a create or update, Model.create(req.body), new Model(req.body), doc.set(req.body) and update calls that take the body whole. In Python, look for Model(request.json), setattr loops over request keys, update(data), and one schema used for both reading and writing. In Rails, permit! or a permit list that includes a privileged attribute. Then check what each endpoint's route mounts as body parsers, and whether create, update and replace share the same filter. Static analysis treats this as a taint question, with a request body as the source and a model write as the sink. Whether a given tool models a spread or a setattr loop as a sink is worth checking, and the SAST false-positives post covers how those results go wrong in mechanism.

A triage checklist for a mass-assignment finding

QuestionIf the answer is no or unknown
Is the finding based only on the field appearing in the response?An echoed value was not stored in 1,320 of 4,500 trials in our lab
Is a clean result based only on the field not appearing?A stored value was hidden by a serializer in 600 trials
Was the record read back with a separate request?Persistence is not established
Is the read-back value under the field the application uses, not just the key as sent?It may be stored but inert, as in 960 trials
Was the privilege tested on a new session or token?A cached role hid a real escalation in 160 of 160 trials
Were case variants, both naming conventions and nested positions sent?A denylist run before key normalisation accepted all three
Were PUT, POST create, signup and invite endpoints tested as well as PATCH?A PATCH-only fix left 120 of 180 trials each open on PUT and create
Were JSON and form bodies both sent?Which encoding works depends on the route's parsers
Were test records restored and created accounts deleted?The probe may have left an administrator or damaged a record
Does the fix remove the field from the input model on every method?Read-only flags and denylists left gaps in our lab

FAQ

Does a 200 that echoes "role": "admin" mean the API is vulnerable to mass assignment? No. In our lab, a handler that saved only allowed fields and returned the request body merged over the record echoed the value in 540 of 540 trials and stored it in none. Read the record back, and test the privilege on a new session.

Can an API be vulnerable to mass assignment if the field never appears in the response? Yes. A public serializer hid the stored value from the response and from a read-back GET in 600 trials, and every one of them granted the privilege on a new session.

Is a denylist of "role" and "isAdmin" enough? Not in our lab. Before key normalisation, Role and the other naming convention got through. After normalisation, a nested field that was not on the list got through.

Does Mongoose strict mode prevent mass assignment? It drops keys that are not in the schema. Fields in the schema, such as role, are written. In our lab, the default strict mode stored the privileged value in 360 of 540 trials, the same as a plain Object.assign on the canonical names.

Does Pydantic extra="forbid" prevent mass assignment? Only if the model does not declare the field. A write model without role rejected every probe with a 422. A shared read-and-write model with role declared stored it in 300 of 540 trials.

Does fixing the PATCH endpoint fix mass assignment? Only for PATCH. In our partial-fix variant, PUT and POST create still stored the value in 120 of 180 trials each.

Is mass assignment the same as BOLA? No. BOLA (API1:2023) is about which objects a caller can act on. Mass assignment is about which properties of an object the caller can set, and it sits under API3:2023. They combine when the writable property is an owner or tenant ID.

What this post did not measure

We measured our own handlers on Express 5.3.0, Mongoose 9.12.2 document binding without a database, Flask 3.1.3, SQLAlchemy 2.1.9 on SQLite and Pydantic 2.14.4. We did not test a MongoDB server or Mongoose update queries, Rails, Django or Django REST framework, Spring, ASP.NET, NestJS or class-validator, GraphQL mutations, JSON Patch or JSON Merge Patch content types, arrays and batch endpoints, multipart bodies, multiple processes or caches between client and store, ownership fields that cross tenants, or the read half of API3 (returning properties the caller should not see). Nothing here measures any scanner, ours included.

The hypothetical findings, resolved

Where AppSecD fits

AppSecD's dynamic and API testing runs Nuclei, Dalfox, SQLMap, Commix, Katana, Arjun, FFuf and Interactsh for out-of-band detection, plus 150+ native checks and API discovery across 50+ web frameworks. Its policy-driven gating blocks a pull request or commit when it introduces a violation. Findings are deduplicated across scans, move through new, reopened and fixed states, and can require maker-checker approval before they are closed.

That is the whole claim. data/products.ts is the single source of truth for what these products do, and it does not mention mass assignment, CWE-915, OWASP API3:2023 or property-level authorisation. Arjun appears in that list as a tool, and the Arjun post explains why a discovered parameter is not a finding on its own. So this post makes no claim that AppSecD detects mass assignment. Nor does it claim anything about:

The mechanisms, measurements, confirmation procedure, fixes and checklist above are general practice that applies to any scanner's output, ours included. The scenario in this post is hypothetical and does not describe any deployment, user or finding.

More about AppSecD · All posts