In the computing world, where software frameworks make life of developer easier, there are problems associated with it which the developer does not intend. Software frameworks use Object Relational Mapping (ORM) tool or Active Record Pattern for converting data of different types and if the software framework does not have a strong mechanism to protect the fields of a class (the types of data), then it becomes easily exploitable by the attackers. These frameworks allow developers to bind parameters with HTTP and manipulate the data externally. The HTTP request that is generated carries the parameters that is used to create or manipulate objects in the application program.
The phrase mass assignment refers to assigning values to multiple attributes in a single go. It is a feature available in frameworks like Ruby on Rails that allows the modifications of multiple object attributes at once using modified URL. For example,
This Mass Assignment saves substantial amount of work for developers as they need not set each value individually.
In Mass Assignment, a malicious agent can attack and manipulate the data in various ways. It can send the tags which can make him assign various permissions which would otherwise be forbidden. For example, a database schema has a table "users" having field "admin" which specifies if corresponding user is admin or not. Malicious agent can easily send the value for this field to the server through HTTP request and mark himself as an admin. This is called Mass assignment vulnerability. It explores the security breaches that can be done using mass assignment.
Github got hacked in 2012 by exploiting mass assignment feature. Homakov who attacked the Github gained private access to Rails by replacing his SSH with SSH key of one of the members of Rails github.
We can perform some changes in the active record models to ensure the protection of our data.
- To use : We specify the attributes which need to be protected. If the user tries mass assignment, then the user will get an error page which says Mass Assignment Security error and the attribute value will not be changed. This is also called blacklisting  In this method, sometimes keeping track of all the attributes we want to protect is difficult. For example, in the code below, assign_project attribute is protected. ClassPerson<ActiveRecord::Basehas_many:projectsattr_protected:assign_projectendThis method optionally takes a role option using :as which enables to define multiple mass-assignment groupings. These attributes will have the :default role in case no role role is assigned. Here is an example which illustrates that assign_project will only be visible to admin.attr_protected:assign_project,:as=>:admin
- To use : We add attributes that are accessible to everyone and need not be protected. This is easier to manage as the attributes that can be mass-assigned can be explicitly selected. All others are considered as protected. This is sometimes referred to as whitelisting.attr_accessible:name,:email,:contact
- To use Sanitize method: Another configuration which we can do to avoid mass assignment problems is called mass assignment sanitizer. This is a method called sanitize. This method filters the incoming requests and takes care that there should be no malicious tags. It only allows those tags that are whitelisted by the user. If the config is set to strict, it will raise when mass assignment is not as intended.
- To use Require and Permit: These methods are used in Rails 4. These provide functionalities that check the incoming requests and parameters. Require method checks whether all the required parameters are present. If not, it throws error. Permit method checks whether a particular parameter is permitted to be passed in mass assignment. It returns the list of the permitted parameters. This is also referred to as strong parameters.
Sometimes developer might forget adding attributes as accessible. So as to avoid this, recent versions of Rail has config setting " which creates blank white list of attributes and protects from Mass Assignment Vulnerability. Models still need to explicitly whitelist or blacklist accessible parameters.
GitHub was recently compromised by a vulnerability in Ruby on Rails know as mass assignment. This vulnerability is thought to not only affect a large number of Ruby-based websites, but also those using ASP.NET MVC and other ORM-backed web frameworks.
Mass assignment by itself is a safe and effective technique for mapping form data to objects. The equivalent in ASP.NET MVC, known as data binding, is likewise safe when used on its own. The actual vulnerability comes from the reckless mixing of mass assignment with an ORM.
Consider this scenario: a database contains a “user” table with a mixture of sensitive and non-sensitive data. Perhaps it has some columns for a user’s display name, email address, and whether or not they are an administrator. A developer wishes to build a screen that allows for editing the display name and email address. To do so they use Rails or MVC scaffolding to automatically generate the domain objects and possibly the view itself. Then they remove from the view any non-user editable fields like the “Is Administrator” checkbox.
A security hole is created if the developer forgets to also remove the IsAdministator property from the domain object. If they don’t do so, the mass assignment/data binder can be tricked into updating that property along with legitimate changes. When the record is then saved, the ORM libraries silently store the new values.
There are three tenable solutions to this problem:
- Flag the non-updatable properties so that the mass assignment/data binder will ignore them.
- Completely remove any properties on the business object that are not actually needed.
- Create models specifically for receiving update requests and manually map them to the ORM object or stored procedure call.
It should be noted that this isn’t a new vulnerability. It is easy to find warnings about mass assignment from four or five more years ago with titles such as “Hackers Love Mass Assignment” and “Use attr_protected or we will hack you”. The only difference this time around is the high-profile nature of the victim.6 Discuss