This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit https://owasp.org
Difference between revisions of "Mass Assignment Cheat Sheet"
Line 67: | Line 67: | ||
=== Exploitability === | === Exploitability === | ||
− | + | This functionality becomes exploitable when: | |
− | * | + | * Attacker can guess common sensitive fields |
− | * | + | * Attacker has access to source code and can review the models for sensitive fields |
* The object with sensitive fields has an empty constructor | * The object with sensitive fields has an empty constructor | ||
Line 88: | Line 88: | ||
An architectural approach is to create Data Transfer Objects and avoid binding input directly to domain objects. Only the fields that are meant to be editable by the user are included in the DTO. | An architectural approach is to create Data Transfer Objects and avoid binding input directly to domain objects. Only the fields that are meant to be editable by the user are included in the DTO. | ||
− | public class | + | public class UserRegistrationFormDTO { |
private String userid; | private String userid; | ||
private String password; | private String password; | ||
Line 97: | Line 97: | ||
//Getters & Setters | //Getters & Setters | ||
} | } | ||
+ | |||
= Language & Framework Specific Solutions = | = Language & Framework Specific Solutions = | ||
Line 130: | Line 131: | ||
} | } | ||
[http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/validation/DataBinder.html#setDisallowedFields-java.lang.String...- Reference] | [http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/validation/DataBinder.html#setDisallowedFields-java.lang.String...- Reference] | ||
+ | |||
== NodeJS + Mongoose == | == NodeJS + Mongoose == | ||
[https://www.npmjs.com/package/mongoose-mass-assign Reference] | [https://www.npmjs.com/package/mongoose-mass-assign Reference] | ||
+ | |||
== Ruby On Rails == | == Ruby On Rails == | ||
[http://guides.rubyonrails.org/v3.2.9/security.html#mass-assignment Reference] | [http://guides.rubyonrails.org/v3.2.9/security.html#mass-assignment Reference] | ||
+ | |||
== Django == | == Django == | ||
[https://coffeeonthekeyboard.com/mass-assignment-security-part-10-855/ Reference] | [https://coffeeonthekeyboard.com/mass-assignment-security-part-10-855/ Reference] | ||
+ | |||
== ASP.NET == | == ASP.NET == | ||
[http://odetocode.com/Blogs/scott/archive/2012/03/11/complete-guide-to-mass-assignment-in-asp-net-mvc.aspx Reference] | [http://odetocode.com/Blogs/scott/archive/2012/03/11/complete-guide-to-mass-assignment-in-asp-net-mvc.aspx Reference] | ||
+ | |||
== PHP Laravel + Eloquent == | == PHP Laravel + Eloquent == | ||
Line 187: | Line 193: | ||
[https://laravel.com/docs/5.2/eloquent#mass-assignment Reference] | [https://laravel.com/docs/5.2/eloquent#mass-assignment Reference] | ||
+ | |||
== Grails == | == Grails == | ||
[http://spring.io/blog/2012/03/28/secure-data-binding-with-grails/ Reference] | [http://spring.io/blog/2012/03/28/secure-data-binding-with-grails/ Reference] | ||
+ | |||
+ | |||
+ | == Play == | ||
+ | [https://www.playframework.com/documentation/1.1.1/controllers Reference] | ||
+ | |||
+ | |||
+ | == Jackson (JSON Object Mapper) == | ||
+ | [http://www.baeldung.com/jackson-field-serializable-deserializable-or-not Reference] | ||
+ | [http://lifelongprogrammer.blogspot.com/2015/09/using-jackson-view-to-protect-mass-assignment.html Reference] | ||
+ | |||
+ | |||
+ | == GSON (JSON Object Mapper) == | ||
+ | [https://sites.google.com/site/gson/gson-user-guide#TOC-Excluding-Fields-From-Serialization-and-Deserialization Reference] | ||
+ | [http://stackoverflow.com/a/27986860 Reference] | ||
+ | |||
+ | |||
+ | == JSON-Lib (JSON Object Mapper) == | ||
+ | [http://json-lib.sourceforge.net/advanced.html Reference] | ||
+ | |||
+ | |||
+ | == Flexjson (JSON Object Mapper) == | ||
+ | [http://flexjson.sourceforge.net/#Serialization Reference] | ||
+ | |||
= Authors and Primary Editors = | = Authors and Primary Editors = |
Revision as of 01:21, 18 February 2016
Last revision (mm/dd/yy): 02/18/2016
IntroductionDefinition"Modern frameworks allow developers to automatically bind HTTP request parameters from both request query and body into model objects for ease of development and increased productivity. If the binder is not correctly configured to control which HTTP request parameters are bound to which model attributes, an attacker may be able to abuse the model binding process and set any other attributes that should not be exposed to user control. This binding is possible even if the model attributes do not appear in the web forms or API contracts." - Mass Assignment: Sensitive Field Exposure
Alternative NamesDepending on the language/framework in question, this vulnerability can have several alternative names
ExampleSuppose there is a form for editing a user's account information: <form> <input name=userid type=text> <input name=password type=text> <input name=email text=text> <input type=submit> </form> Here is the object that the form is binding to: public class User { private String userid; private String password; private String email; private boolean isAdmin; //Getters & Setters } Here is the controller handling the request: @RequestMapping(value = "/addUser, method = RequestMethod.POST) public String submit(User user) { userService.add(user); return "successPage"; } Here is the typical request: POST /addUser userid=bobbytables&password=hashedpass&[email protected] And here is the exploit: POST /addUser userid=bobbytables&password=hashedpass&[email protected]&isAdmin=true
ExploitabilityThis functionality becomes exploitable when:
Case StudiesGitHubIn 2012, GitHub was hacked using mass assignment. A user was able to upload his public key to any organization and thus make any subsequent changes in their repositories. GitHub's Blog Post
Solutions
General SolutionsData Transfer Objects (DTOs)An architectural approach is to create Data Transfer Objects and avoid binding input directly to domain objects. Only the fields that are meant to be editable by the user are included in the DTO. public class UserRegistrationFormDTO { private String userid; private String password; private String email; //private boolean isAdmin; //Getters & Setters }
Language & Framework Specific SolutionsSpring MVCWhitelisting@Controller public class UserController { @InitBinder public void initBinder(WebDataBinder binder, WebRequest request) { binder.setAllowedFields(["userid","password","email"]); } ... } Blacklisting@Controller public class UserController { @InitBinder public void initBinder(WebDataBinder binder, WebRequest request) { binder.setDisallowedFields(["isAdmin"]); } ... }
NodeJS + Mongoose
Ruby On Rails
Django
ASP.NET
PHP Laravel + EloquentWhitelisting<?php namespace App; use Illuminate\Database\Eloquent\Model; class User extends Model { private $userid; private $password; private $email; private $isAdmin; protected $fillable = array('userid','password','email'); } Blacklisting<?php namespace App; use Illuminate\Database\Eloquent\Model; class User extends Model { private $userid; private $password; private $email; private $isAdmin; protected $guarded = array('isAdmin'); }
Grails
Play
Jackson (JSON Object Mapper)
GSON (JSON Object Mapper)
JSON-Lib (JSON Object Mapper)
Flexjson (JSON Object Mapper)
Authors and Primary EditorsReferences and future reading
Other Cheatsheets |