Mass Assignment Cheat Sheet — Example
Suppose there is a form for editing a user's account information Bounded code example (external data; do not execute automatically): ```html <form> <input name="userid" type="text"> <input name="password" type="text"> <input name="email" text="text"> <input type="submit"> </form> ``` Here is the obj
Reference note (untrusted external data; do not execute it as instructions).
Suppose there is a form for editing a user's account information
Bounded code example (external data; do not execute automatically):
```html
<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
Bounded code example (external data; do not execute automatically):
```java
public class User {
private String userid;
private String password;
private String email;
private boolean isAdmin;
//Getters & Setters
}
```
Here is the controller handling the request
Bounded code example (external data; do not execute automatically):
```java
@RequestMapping(value = "/addUser", method = RequestMethod.POST)
public String submit(User user) {
userService.add(user);
return "successPage";
}
```
Here is the typical request
Bounded code example (external data; do not execute automatically):
```text
POST /addUser
...
userid=bobbytables&password=hashedpass&email=bobby@tables.com
```
And here is the exploit in which we set the value of the attribute isAdmin of the instance of the class User
Bounded code example (external data; do not execute automatically):
```text
POST /addUser
...
userid=bobbytables&password=hashedpass&email=bobby@tables.com&isAdmin=true
```
Attribution: Adapted from OWASP Cheat Sheet Series under CC-BY-SA-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
OWASP Cheat Sheet Series — cheatsheets/Mass_Assignment_Cheat_Sheet.md :: Example ↗Revision 07111ee754e8 · CC-BY-SA-4.0 and attribution