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.
Super lightweight, fast, and optimized evaluate-able and compilable expressions in JSON written in TypeScript
Super lightweight, fast, and optimized evaluate-able and compilable expressions in JSON written in TypeScript
npm install -D expjson
or
yarn add -D expjson
compileExpression
and running it later is much faster if compiled expression is evaluated multiple times on many execution contexts.
evaluateExpression
is faster if the expression is evaluated only once.
functionalities are exactly same for both.
import {
compileExpression,
evaluateExpression,
// operators
Add,
And,
Divide,
Equal,
GreaterThan,
GreaterThanOrEqual,
IfThenElse,
In,
LessThan,
LessThanOrEqual,
Modulo,
Multiply,
Not,
NotEqual,
NotIn,
Or,
Subtract,
Var,
} from 'expjson';
// evaluateExpression: evaluate without compile
expect(
evaluateExpression(
[
IfThenElse, // same as '?:'
[In, 'admin', [Var, 'roles']], // test if "admin" is in "roles" context variable
[Not, [Var, 'postDeleted']], // true if context variable "postDeleted" is false
[Var, 'unauthorized'], // context variable "unauthorized"
],
{
postDeleted: false,
roles: ['user', 'admin'],
unauthorized: 'Unauthorized Error',
}
)
).toBe(true);
expect(
evaluateExpression(
[
'?:', // same as IfThenElse
['In', 'admin', [Var, 'roles']], // test if "admin" is in "roles" context variable
['!', [Var, 'postDeleted']], // true if context variable "postDeleted" is false
[Var, 'unauthorized'], // context variable "unauthorized"
],
{
postDeleted: true,
roles: ['user', 'admin'],
unauthorized: 'Unauthorized Error',
}
)
).toBe(false);
expect(
evaluateExpression(
[
IfThenElse, // same as '?:'
[In, 'admin', [Var, 'roles']], // test if "admin" is in "roles" context variable
[Not, [Var, 'postDeleted']], // true if context variable "postDeleted" is false
[Var, 'unauthorized'], // context variable "unauthorized"
],
{
postDeleted: false,
roles: ['user', 'guest'],
unauthorized: 'Unauthorized Error',
}
)
).toBe('Unauthorized Error');
// compileExpression: compile then evaluate
const compiled1 = compileExpression([
IfThenElse, // same as '?:'
[In, 'admin', [Var, 'roles']], // test if "admin" is in "roles" context variable
[Not, [Var, 'postDeleted']], // true if context variable "postDeleted" is false
[Var, 'unauthorized'], // context variable "unauthorized"
]);
expect(
compiled1({
postDeleted: false,
roles: ['user', 'admin'],
unauthorized: 'Unauthorized Error',
})
).toBe(true);
const compiled2 = compileExpression([
'?:', // same as IfThenElse
['In', 'admin', [Var, 'roles']], // test if "admin" is in "roles" context variable
['!', [Var, 'postDeleted']], // true if context variable "postDeleted" is false
[Var, 'unauthorized'], // context variable "unauthorized"
]);
expect(
compiled2({
postDeleted: true,
roles: ['user', 'admin'],
unauthorized: 'Unauthorized Error',
})
).toBe(false);
const compiled3 = compileExpression([
IfThenElse, // same as '?:'
[In, 'admin', [Var, 'roles']], // test if "admin" is in "roles" context variable
[Not, [Var, 'postDeleted']], // true if context variable "postDeleted" is false
[Var, 'unauthorized'], // context variable "unauthorized"
]);
expect(
compiled3({
postDeleted: false,
roles: ['user', 'guest'],
unauthorized: 'Unauthorized Error',
})
).toBe('Unauthorized Error');
FAQs
Super lightweight, fast, and optimized evaluate-able and compilable expressions in JSON written in TypeScript
The npm package expjson receives a total of 0 weekly downloads. As such, expjson popularity was classified as not popular.
We found that expjson 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.