HackerMe Security — practical guidance for protecting your website

Mass Assignment for Website Owners: How Extra Form Fields Can Change Roles, Prices and Hidden Data

Conceptual illustration for the article “Mass Assignment for Website Owners: How Extra Form Fields Can Change Roles, Prices and Hidden Data”

Mass assignment is a flaw where a website takes the fields sent in a request and copies them into its internal records automatically, so an attacker can add a field the developer never meant to accept and overwrite something important. OWASP describes the root of the problem plainly: many frameworks can bind incoming HTTP request parameters straight into program variables or objects, which saves developers effort, and that convenience can sometimes cause harm.

What mass assignment is and why it matters to a business website

The danger is in the word "automatically". A sign-up form or a profile page shows a visitor only a few boxes, such as a username, a password and an email address. The record behind that form may hold far more: whether the account is an administrator, who owns it, what plan it is on. If the code hands everything in the request to that record without filtering, an attacker can send extra parameters the form never displayed, and those values can create or overwrite fields in the program that nobody intended to expose.

You may hear the same weakness under different names depending on what your site is built with. OWASP lists mass assignment for Ruby on Rails and NodeJS, autobinding for Spring MVC and ASP NET MVC, and object injection for PHP. If a developer, a penetration tester or a scanner report uses any of these terms, they are talking about the same family of problem.

What makes it exploitable is simple to state: the attacker controls input that can set or update a field they are not authorized to change, such as a role or the account owner. OWASP stresses that the attacker does not need to see your source code, because field names can be guessed or discovered. That is why this is a business risk and not only a developer curiosity: the target fields are usually exactly the ones that control who is in charge of an account or what someone pays.

Sources: cheatsheetseries.owasp.org [1]

What it looks like in practice: an admin flag, a price and a blocked post

OWASP's own example is a form for editing account details that offers a user ID, a password and an email address, while the record behind it also carries an isAdmin field. A normal request sends the three visible fields. The attack sends the same request with isAdmin=true added on the end. If the code binds everything it receives, the attacker has just made themselves an administrator without any visible admin screen ever being involved.

This is not a theoretical concern. OWASP records that GitHub was hacked using mass assignment in 2012: a user was able to upload his public key to any organization and could then make further changes in their repositories. A field that should only have been settable for one's own account became settable for other people's.

The OWASP API Security Top 10 gives two further scenarios that map closely to small business sites. In a booking marketplace, a host approves a guest's booking with a legitimate request containing an approval flag and a comment, then replays it with an added total_stay_price of $1,000,000. Because nothing checks whether the host may touch that internal property, the guest is charged more than she should be. For an online shop, the equivalent worry is any order, cart or invoice record where price, discount or status sits beside fields the customer is allowed to edit.

In the second scenario, a video platform blocks a user's upload but still lets them edit its description. The user replays the description update and adds "blocked": false, and because there is no check on that internal property, they unlock their own blocked content. Any site with moderation, approval or publish flags, such as reviews awaiting approval or listings awaiting payment, has the same shape of risk.

Sources: cheatsheetseries.owasp.org [1] · api-security.owasp.org [2]

Two sides of one problem: fields users can write and fields users can read

OWASP's API Security Top 10 (2023) groups mass assignment with a closely related flaw under one heading, Broken Object Property Level Authorization. The idea is that it is not enough to check whether someone may access a record; the site must also check whether they may access each property of that record.

OWASP says an endpoint is vulnerable in either of two ways. The first is that it exposes properties of an object that are sensitive and should not be read by the user; this used to be called Excessive Data Exposure. The second is that it lets a user change, add or delete the value of a sensitive property they should not be able to access; this is the old Mass Assignment name. For a site owner, that means the same review should ask two questions about every form and every API your site or app uses: what can a visitor change here, and what does the response quietly send back?

The reading side is easy to overlook because nothing appears on screen. OWASP notes that APIs tend to expose endpoints that return all of an object's properties, especially REST APIs. The page may display a name, while the data behind it carries much more. OWASP's dating-app example shows a report button whose response included the reported person's full name and recent location, details other users were never supposed to see.

The consequences OWASP lists are serious: unauthorized access to sensitive properties can mean data disclosure, data loss or data corruption, and in some circumstances privilege escalation or partial or full account takeover. That range runs from a privacy incident to a stranger controlling an admin account, which is why this belongs on your list of things to ask about, alongside better-known issues.

Sources: api-security.owasp.org [2]

How attackers find the hidden fields, and what that means for testing

A common assumption is that a field nobody can see is a field nobody can set. OWASP's guidance contradicts that directly. Field names may be guessed or discovered, and the attacker does not need your source code. The read side of the problem often helps the write side: if a response reveals a property such as a role or a status, the attacker now knows its name.

OWASP describes the discovery process in the API Top 10. Inspecting API responses is enough to find sensitive information in what the server returns, and fuzzing, meaning sending many guessed parameter names, is usually used to find additional hidden properties. Whether a property can actually be changed is then a matter of crafting a request and reading the response. Where the changed property is not echoed back, OWASP notes that side-effect analysis may be needed, which means looking for the consequence elsewhere, such as a new menu appearing or a price changing.

This has a practical meaning when you commission or review a security test. A scan that only fills in the visible boxes on your forms will not exercise this flaw, because the attack lives in the fields that are not shown. When you scope a penetration test, it is reasonable to ask whether the tester will check for added or hidden properties on account, order and admin-related requests, and whether they will look at what data the responses return, not only at what the page displays.

OWASP also gives developers a specific review instruction: look at which inputs the binding mechanism exposes, including nested objects. Nested data, such as an address inside a customer record or line items inside an order, can carry its own sensitive fields, so a review that checks only the top level of a form can miss them.

Sources: api-security.owasp.org [2] · cheatsheetseries.owasp.org [1]

The fixes to ask your developer about on the input side

You do not need to write the code yourself, but you can ask whether your site follows the design OWASP recommends. The preferred approach is dedicated input objects, often called Data Transfer Objects (DTOs), that contain only the fields the user is allowed to edit. In OWASP's example the registration input object simply has no isAdmin field, so there is nothing for an attacker to set, however they shape the request.

Where a full record must be bound, OWASP says to explicitly allow-list the permitted fields. The opposite approach, a block-list of forbidden fields, should not be the only protection, because a new or overlooked sensitive field stays bindable. OWASP adds that Spring itself calls its block-list setting fragile because fields can be missed or added later. That is a useful point for owners: sites grow. A loyalty tier, a discount code or a trial-expiry date added next year will be safe by default under an allow-list and exposed by default under a block-list.

The API Top 10 says the same from a different angle: if possible, avoid functions that automatically bind a client's input into internal objects, and allow changes only to the properties the client should update. A useful question for your developer is therefore: for each form that saves to the database, which named fields are accepted, and where is that list written down?

One caution matters a great deal. OWASP states that DTOs and allow-lists restrict which properties can be written, but they do not replace authorization for the requested object and operation. In other words, stopping a user from setting isAdmin does not by itself stop that user from editing somebody else's account. Field filtering and access control are separate checks, and you need both.

Sources: cheatsheetseries.owasp.org [1] · api-security.owasp.org [2]

The fixes on the output side: send back only what the page needs

Because the reading side and the writing side are the same weakness in OWASP's model, the output deserves the same discipline as the input. OWASP's first instruction is that whenever an object is exposed through an endpoint, the developer must make sure the user should have access to the properties being exposed.

In practice OWASP advises against generic methods that turn a whole record into a response, naming to_json() and to_string() as examples, and recommends cherry-picking the specific properties you want to return. For an owner, the plain-language version is: the data your customer page receives should be chosen on purpose, field by field, and not be a dump of the whole database row.

OWASP also suggests a schema-based response validation mechanism as an extra layer: define and enforce the data each API method returns, and keep returned data structures to the bare minimum the business purpose requires. This gives you something checkable. If your developer can show you the defined shape of what each endpoint returns, you can compare it against what that screen actually needs and ask why any extra fields are there.

Trimming responses also makes the input side harder to attack. As covered earlier, attackers learn field names from responses; a response that never mentions a role or status field gives them less to guess with.

Sources: api-security.owasp.org [2] · cheatsheetseries.owasp.org [1]

What this article does not cover

This article explains the concept and the design questions to raise; it is not a testing procedure. Sending modified requests to a live site can change real accounts, orders or prices, so hands-on testing belongs with a developer or a tester working on a copy of the site with permission, not with a site owner on production.

It also does not give framework-by-framework code. Your developer should follow the official documentation for whatever your site is built on.

Finally, it does not cover object-level access control, the separate question of whether one user can open or edit another user's record at all. As noted above, field filtering does not replace that check, and it deserves its own review.

Sources: api-security.owasp.org [2] · cheatsheetseries.owasp.org [1]

Questions and answers

What is a mass assignment vulnerability?

Mass assignment is a flaw where a website takes the fields sent in a request and copies them into its internal records automatically, so an attacker can add a field the developer never meant to accept and overwrite something important.

Does an attacker need my source code to exploit mass assignment?

OWASP stresses that the attacker does not need to see your source code, because field names can be guessed or discovered.

Has mass assignment been used in a real attack?

OWASP records that GitHub was hacked using mass assignment in 2012.

Is a block-list of forbidden fields enough to prevent mass assignment?

The opposite approach, a block-list of forbidden fields, should not be the only protection, because a new or overlooked sensitive field stays bindable.

Do allow-lists replace access control checks?

Field filtering and access control are separate checks, and you need both.

What should my site's API responses contain?

the data your customer page receives should be chosen on purpose, field by field, and not be a dump of the whole database row.

Mass assignment is one case of trusting input too much. For the wider picture of what to check and what to ask your developer, read our guide to input validation for website owners.

Take these questions to your developer or tester and ask them to walk you through how your forms and responses handle fields that users are not meant to change.

Sources

  1. cheatsheetseries.owasp.org — cheatsheets Mass Assignment Cheat Sheet.html
  2. api-security.owasp.org — editions 2023 en 0xa3 broken object property level authorization