Security fix for Arbitrary Code Execution in telejson#2
Security fix for Arbitrary Code Execution in telejson#2huntr-helper merged 5 commits into418sec:masterfrom
Conversation
|
👋 Hello, @ndelangen. @zpbrent has opened a PR to us with a fix for a potential vulnerability in your repository. To view the vulnerability, please refer to the bounty URL in the first comment, above. If you want this fix in your repository, a PR will automatically open once you comment:
|
|
@zpbrent Do you want to re-create the PR, or should I merge this duplicated one? |
|
@ndelangen - if we can merge this one, we can make sure that @zpbrent gets the bounty rewards automatically. Cheers! 🍰 |
|
@ndelangen - you just need to write the |
|
LGTM |
|
@huntr-helper - LGTM |
📊 Metadata *
The
telejson.reviver()which is used to parse string data back to json structure can be abused to execute arbitrary code when thelazyEvaloption is set tofalse(i.e., disabled). The root cause is the attackers can purposely inject a bracket at the end of the function property (invoking IIFE), that may be stringified bytelejson.replacer()ortelejson.stringify(). Even worse, despite the default value oflazyEvaloption is set totruefortelejson.parse(), thetelejson.reviver()have that vaule asfalseby default.Bounty URL: https://www.huntr.dev/bounties/1-npm-telejson/
⚙️ Description *
Sanitize the brackets at the end of the function property for the input string to
telejson.reviver(), since the normal use oftelejson.replacer()andtelejson.stringify()cannot make brackets at the end of the function property for the json objects.💻 Technical Description *
const sourceSanitized = source.replace(/[(\(\))|\\| |\]]*$/,'');This fix has considered the bypass possibility such as multiple
( ) \ ] `and spaces, in case they apper at the end. Any more?🐛 Proof of Concept (PoC) *
After running
node PoC.js, the file HACKED can be illegally created.🔥 Proof of Fix (PoF) *
After running
node PoC.js, the file HACKED cannot be created.👍 User Acceptance Testing (UAT)