Prototype Pollution is a dangerous and commonly seen vulnerability in Javascript application. This post introduce the basic concept and cause of the vulnerability. Before dig deep into the vulnerability, let’s take a look what prototype is.
What is Prototype
Prototype defines structure and property of an object in Javascript. So, what is object? In Javascript, you can think of object as a collection of key pair. Each key pairs are called property. For example, if we want to create an object called User with 2 properties namely username and password, we can write a simple code as below:
function User(username, password){
this.username=username;
this.password=password;
}
Then, to create a new user, it can simply done by following code:
var userA = new User(“John”, “12345678”);console.log(“User “+userA.username + “ is created”); //output: User John is created
So, an object userA is created with username set as John and password set as 12345678. These properties are inherited from User’s prototype.
Prototype Property
A prototype property is a property that allows user to change the structure/property of the prototype. For example, if we want to create a function for User to change user password, we can make a function like below:
User.prototype.change_password = function(var new_pw){…