liriliri / licia

Useful utility collection with zero dependencies
https://licia.liriliri.io
MIT License
2.29k stars 158 forks source link

Security Fix for Prototype Pollution - huntr.dev #22

Closed huntr-helper closed 4 years ago

huntr-helper commented 4 years ago

https://huntr.dev/users/alromh87 has fixed the Prototype Pollution vulnerability 🔨. alromh87 has been awarded $25 for fixing the vulnerability through the huntr bug bounty program 💵. Think you could fix a vulnerability like this?

Get involved at https://huntr.dev/

Q | A Version Affected | ALL Bug Fix | YES Original Pull Request | https://github.com/418sec/licia/pull/1 Vulnerability README | https://github.com/418sec/huntr/blob/master/bounties/npm/licia/1/README.md

User Comments:

📊 Metadata *

licia is a useful utility collection with zero dependencies used in nodejs. safeSet in this package is vulnerable to prototype pollution.

Bounty URL: https://www.huntr.dev/bounties/1-npm-licia

⚙️ Description *

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.

💻 Technical Description *

Fixed by avoiding setting magical attributes.

🐛 Proof of Concept (PoC) *

  1. Install the package(npm i licia), run the below code:

safeSet

var licia = require('licia');
var src = {};
licia.safeSet(src, "__proto__.polluted", "pwned!");
console.log(polluted);

Outputs pwned!.

liciaPOC

extendDeep

var utils = require('licia');
var src = {};
let object = utils.extendDeep({}, JSON.parse('{ "myProperty": "a", "prototype" : { "isAdmin" : true } }'));
console.log(object.prototype.isAdmin);

Outputs true

licia2POC

🔥 Proof of Fix (PoF) *

After fix polluted is not defined and prototype is unafected

Captura de pantalla de 2020-09-24 00-11-22

Captura de pantalla de 2020-09-24 15-29-06

👍 User Acceptance Testing (UAT)

After fix functionality is unafected

JamieSlome commented 4 years ago

@surunzi - happy to answer your questions if you have any! 👍