Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
jailed-function
Advanced tools
Jailed Function is a Node.js library that safely runs untrusted code. It can be used in cloud services or low-code platforms that need to execute user-provided JavaScript.
Basic usage:
const jailedFunc = createJailedFunction({
source: `async (num1, num2) => {
return num1 + num2
}`
})
await jailedFunc([2, 3]) // returns 5
Injecting global variables into the execution context:
const finUserById = createJailedFunction({
// declaring global vars
globalNames: ['userService']
source: `async (id) => {
return userService.byId(id)
}`
})
// execute the function providing global vars
await finUserById([1], { userService })
globalNames
List of global variable names allowed to use inside the jailed function.timeout (ms)
Maximum execution time for the function. Default 1min.syncTimeout (ms)
Maximum execution time for the function running synchronous code. Default 100ms.memoryLimit (bytes)
Maximum amount of memory that the function is allowed to allocate.source
The function source code. This function must be async
.filename
The filename to display in the stack trace.readOnlyResult
Whether to make read-only jailed function return value. Default true
.readOnlyGlobals
Whether to make read-only jailed function globals. Default true
.readOnlyArguments
Whether to make read-only jailed function arguments. Default true
.Jailed Function provides access to several convenient built-in globals.
console [log, error, warn]
muted in productionObject [keys, values, hasOwnProperty, fromEntries, assign, create]
Promise [all, race, resolve, reject, allSettled]
Date [now, parse, UTC]
Array [isArray, from, of]
Number [isFinite, isInteger, isNaN, isSafeInteger, parseFloat, parseInt, MAX_VALUE, MIN_VALUE, NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER, EPSILON]
String [romCharCode, fromCodePoint, raw]
readOnly(target: any, traps: {})
Prevents object modification.createGetTrap(propNames: string[])
Create Proxy get traps that allow access only to the properties passed in arguments.Inject Math
object allowing only max
property access.
const max = createJailedFunction({
// declare injected global
globalNames: ['Math']
source: `async (a, b) => Math.max(a, b)`
})
// execute the function providing global vars
await max([1], { Math: readOnly(Math, createGetTrap(['max'])) })
(c) 2023-present Yosbel Marín, MIT License
FAQs
Safely run untrusted code
The npm package jailed-function receives a total of 20 weekly downloads. As such, jailed-function popularity was classified as not popular.
We found that jailed-function 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.