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.
ejson-shell-parser
Advanced tools
Parses valid MongoDB EJSON Shell queries. This library does not validate that these queries are correct. It's focus is on parsing untrusted input. You may wish to use something like https://github.com/mongodb-js/mongodb-language-model to achieve this.
Parses valid MongoDB EJSON Shell queries. This library does not validate that these queries are correct. It's focus is on parsing untrusted input. You may wish to use something like https://github.com/mongodb-js/mongodb-language-model to achieve this.
This library creates an AST from the proposed input, and then traverses this AST to check if it looks like a valid MongoDB query. If it does, the library will then evaluate the code to produce the parsed query.
This library currently supports three different modes for parsing queries:
strict: [default] Disallows comments and calling methods
import parse from 'ejson-shell-parser';
const query = parse(
`{
_id: ObjectID("132323"),
simpleCalc: 6,
date: new Date(1578974885017)
}`,
{ mode: 'strict' }
);
/*
query = { _id: ObjectID("132323"), simpleCalc: 6, date: Date('1578974885017') }
*/
weak: Disallows comments, allows calling methods
import parse from 'ejson-shell-parser';
const query = parse(
`{
_id: ObjectID("132323"),
simpleCalc: Math.max(1,2,3) * Math.min(4,3,2)
}`,
{ mode: 'weak' }
);
/*
query = { _id: ObjectID("132323"), simpleCalc: 6 }
*/
loose: Supports calling methods on Math, Date and ISODate, allows comments
import parse from 'ejson-shell-parser';
const query = parse(
`{
_id: ObjectID("132323"), // a helpful comment
simpleCalc: Math.max(1,2,3) * Math.min(4,3,2)
}`,
{ mode: 'loose' }
);
/*
query = { _id: ObjectID("132323"), simpleCalc: 6 }
*/
The options object passed into parse has the following parameters:
{
mode: ('loose' || 'weak' || 'strict') // Will assign (allowMethods & allowComments) for you
allowMethods: true, // Allow function calls, ie Date.now(), Math.Max(), (new Date()).getFullYear()
allowComments: true, // Allow comments (// and /* */)
}
The flags can be set to override the default value from a given mode, ie:
{
mode: 'strict',
allowComments: true
}
This options object will disallow method calls, but will allow comments
FAQs
Parses valid MongoDB EJSON Shell queries. This library does not validate that these queries are correct. It's focus is on parsing untrusted input. You may wish to use something like https://github.com/mongodb-js/mongodb-language-model to achieve this.
The npm package ejson-shell-parser receives a total of 4,208 weekly downloads. As such, ejson-shell-parser popularity was classified as popular.
We found that ejson-shell-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 34 open source maintainers 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.