
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
expression-sandbox
Advanced tools
A small tool for evaluating JavaScript code in a secure sandbox, for Node.js or the modern browser.
This lets you compile and run someone else's arbitrary JavaScript safely within your own JavaScript program.
UPDATE:
This was more of a fun/experimental project. If anyone would like to take over the repo, just ask. Otherwise, it will remain archived.
npm install --save expression-sandbox
var compiler = require('expression-sandbox');
var code = compiler('Math.round(a + b / 3)');
var result = code({a: 7, b: 5, Math});
console.log(result); // => 9
If you don't pass anything into the sandbox context, then you're protected EVERYWHERE!
From inside the sandbox...
Function
or eval
._
on objects that are passed into the sandbox.Any sensitive information that is passed into the sandbox can be accessed by the unsecure code (unless that information is behind a property that starts with _
)
If you think there are vulnerabilities in the sandbox that I didn't think of, please create a Github issue to bring them to my attention.
This package replaces some built-in objects with Proxies. In rare cases, this can cause odd behvaior with with ===
operator, if you cache one of these objects before this package is loaded. For this reason, it is recommended that this package is loaded before any other JavaScript code runs.
There's one more caveat.
If you pass an object into a sandbox, and then you pass that object into a function that was created outside the sandbox, the function will receive a proxy of the original object. To test if that proxy represents a specific non-proxy object, you can use compiler.equals()
, as shown below.
var compiler = require('expression-sandbox');
var obj = {};
function badTest(a) {
return a === obj;
}
function goodTest(a) {
return compiler.equals(a, obj);
}
var context = {obj, badTest, goodTest};
compiler('badTest(obj)')(context); // Returns false
compiler('goodTest(obj)')(context); // Returns true
But don't worry, 99% of the time this issue will never come up.
The opinions behind nx-compile differ from the opinions behind expression-sandbox. For example, expression-sandbox
is not interested in providing a non-secure version of itself. The "small modules" rule suggests that such functionality should be in its own module. Additionally, expression-sandbox
aims to secure anything you put into the sandbox—not just globals and native prototypes. Finally, expression-sandbox
keeps its independence from nx-framework, to be as generic as possible.
FAQs
A small tool for evaluating JavaScript code in a secure sandbox, for Node.js or the modern browser.
The npm package expression-sandbox receives a total of 3 weekly downloads. As such, expression-sandbox popularity was classified as not popular.
We found that expression-sandbox demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.