Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions files/en-us/web/security/attacks/supply_chain_attacks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,37 +209,3 @@ See [Subresource Integrity](/en-US/docs/Web/Security/Subresource_Integrity) for
## See also

- [Software Supply Chain Security](https://cheatsheetseries.owasp.org/cheatsheets/Software_Supply_Chain_Security_Cheat_Sheet.html) at [owasp.org](https://owasp.org/)

JavaScript implements {{glossary("inheritance")}} using _prototypes_. Each object has a prototype, which it itself an object, and which itself has a prototype, and so on, until we get to the fundamental prototype, which is called `Object.prototype`, whose own prototype is `null`.

If you try to access a property or call a method on an object, and that property or method isn't defined on the object, then the JavaScript runtime looks in the object's prototype for the property or method, and then in the object's prototype's prototype, and so on, until it finds the method of property or reaches an object whose prototype is `null`.

That's why you can do this:

```js
const myArray = new Array(1, 2, 3);
// prototype chain:
// myArray -> Array -> Object -> null

myArray.length;
// 3
// length is defined on the prototype of `myArray`, which is `Array.prototype`

myArray.toString();
// "1,2,3"
// toString() is defined on the prototype of `Array.prototype`, which is `Object`
```

Unlike many other languages, JavaScript allows you to add inherited properties and methods at runtime by modifying an object's prototypes:

```js
const myArray = new Array(1, 2, 3);

// modify the Object prototype at runtime
Object.prototype.extra = "new property!";

myArray.extra;
// "new property!"
```

In a prototype pollution attack, the attacker is able to change the object's prototype to make the object behave in unexpected or dangerous ways.