Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Execute arbitrary JS with callbacks in node.js
Note: This library actually uses vm.runInNewContext()
instead of eval()
for a bit more added security, though it doesn't fork a process, so it's best used with trusted code.
npm install async-eval
npm test
or
git clone https://github.com/dallonf/async-eval
npm install
npm test
var asyncEval = require('async-eval');
var someObject = {x: 5, y: 10};
function waitOneSecond(callback) {
setTimeout(callback, 1000);
}
var options = {
this: someObject,
asyncFunctions: {
waitOneSecond: waitOneSecond
}
}
asyncEval('waitOneSecond(function() { this.x += 2; });', options, function() {
console.log(someObject.x); // 7
});
asyncEval(code, [options], [callback])
asyncEval() will interpret and execute code
and run callback
when the code and every asynchronous function it calls has finished running.
this
Default: {}
Sets the object that will be used as this
in the executed code and any nested callbacks.
context
Default: {}
Sets the global context in the executed code. Put any synchronous DSL functions and global variables here.
asyncFunctions
Default: {}
Registers asynchronous functions into the context
. Asynchronous functions must be listed in the asyncFunctions
property so that asyncEval can count pending callbacks.
The functions registered in asyncFunctions
must take a callback as the last argument.
These functions can be namespaced with objects, for example:
asyncFunctions: {
users: {
get: function(callback) { /* ... */ },
create: function(user, callback) { /* ... */ },
},
posts: {
get: function(callback) { /* ... */ },
create: function(post, callback) { /* ... */ },
}
}
FAQs
Execute arbitrary JS with callbacks
The npm package async-eval receives a total of 139 weekly downloads. As such, async-eval popularity was classified as not popular.
We found that async-eval 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.