
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
json-expression-eval
Advanced tools
evaluate a json described boolean expression using dynamic functions
A Node.js module that evaluates a json described boolean expressions using dynamic functions and a given context.
The module is strictly typed, ensuring that passed expressions are 100% valid at compile time.
This module is especially useful if you need to serialize complex expressions (to be saved in DB for example)
npm install json-expression-eval
Or
yarn add json-expression-eval
Please see tests and examples dir for more usages and example (under /src)
import { Expression, evaluate } from 'json-expression-eval';
interface IExampleContext {
userId: string;
times: number;
}
const exampleContext: IExampleContext = {
userId: 'a2@b.com',
times: 5,
};
const functionsTable = {
countRange: ([min, max]: [number, number], context: IExampleContext): boolean => {
return context.times >= min && context.times < max;
},
};
const expression: Expression<IExampleContext, typeof functionsTable> = {
or: [
{
userId: 'a@b.com',
},
{
and: [
{
countRange: [2, 6],
},
{
userId: 'a2@b.com',
},
],
},
],
};
console.log(evaluate(expression, exampleContext, functionsTable)); // true
There are 4 types of operators you can use (evaluated in that order of precedence):
and
- accepts a non empty list of operatorsor
- accepts a non empty list of operatorsnot
- accepts another operator<user defined funcs>
- accepts any type of argument and evaluated by the user defined functions and given context.<compare funcs>
- operates on one of the context properties and compare it to a given value.
{property: {op: value}}
gt
- >gte
- >=lt
- <lte
- <=eq
- ===neq
- !=={property: value}
eq
op)Example expressions, assuming we have the user
and maxCount
user defined functions in place can be:
{
"or":[
{
"not":{
"user":"a@b.com"
}
},
{
"maxCount":1
},
{
"times": { "eq" : 5}
},
{
"country": "USA"
}
]
}
FAQs
json serializable rule engine / boolean expression evaluator
The npm package json-expression-eval receives a total of 292 weekly downloads. As such, json-expression-eval popularity was classified as not popular.
We found that json-expression-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.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.