Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
bson-compilers
Advanced tools
Transpilers for building BSON documents in any language. Current support
provided for shell
and javascript
as inputs. java
, c#
and python
as
outputs.
const compiler = require('bson-compilers');
const input = 'javascript';
const output = 'java';
const string =`
{ item: "book", qty: Binary(Buffer.from("5")), tags: ["red", "blank"], dim_cm: [14, Int32("81")] }`;
try {
const compiledString = compiler[input][output].compile(string);
console.log(compiledCode);
// new Document("item", "book").append("qty", new Binary("5".getBytes("UTF-8")))
// .append("tags", Arrays.asList("red", "blank"))
// .append("dim_cm", Arrays.asList(14L, 81")))
} catch (error) {
console.error(error);
}
Output a compiled string given input and output languages.
shell
and javascript
are currently supported.java
,
python
, shell
, javascript
, and csharp
are currently supported.Output a string containing the set of import statements for the generated code to compile. These are all the packages that the compiled code could use so that the compiler output will be runnable.
Any compiler errors that occur will be thrown. To catch them, wrap the
compiler
in a try/catch
block.
bson-compilers
will send back letting you know
the compiler error.bson-compilers
adds to the error object to
help you distinguish error types.There are a few different error classes thrown by bson-compilers
, each with
their own error code:
This will occur when you're using a method with a wrong number of arguments, or
the arguments are of the wrong type.
For example, ObjectId().equals()
requires one argument and it will throw if
anything other than one argument is provided:
// ✘: this will throw a BsonCompilersArgumentError.
ObjectId().equals(ObjectId(), ObjectId());
// ✔: this won't throw
ObjectId().equals(ObjectId());
// ✘: this will throw a BsonCompilersArgumentError.
ObjectId({});
// ✔: this won't throw
ObjectId();
Will be thrown if an invalid method or property is used on a BSON object. For
example, since new DBRef()
doesn't have a method .foo()
, compiler will
throw:
// ✘: method foo doesn't exist, so this will throw a BsonCompilersAttributeError .
new DBRef('newCollection', new ObjectId()).foo()
// ✔: this won't throw, since .toString() method exists
new DBRef('newCollection', new ObjectId()).toString(10)
This will throw if you have a syntax error. For example missing a colon in Object assignment, or forgetting a comma in array definition:
// ✘: this is not a proper object definition; will throw E_SYNTAX_GENERIC
{ key 'beep' }
// ✘: this is not a proper array definition, will throw E_SYNTAX_GENERIC
[ 'beep'; 'boop' 'beepBoop' ]
// ✔: neither of these will throw
{ key: 'beep' }
[ 'beep', 'boop', 'beepBoop' ]
This error will occur if a symbol is treated as the wrong type. For example, if a non-function is called:
// ✘: MAX_VALUE is a constant, not a function
Long.MAX_VALUE()
// ✔: MAX_VALUE without a call will not throw
Long.MAX_VALUE
If an argument has been passed that is not in the range of expected values.
If there is a feature in the input code that is not currently supported by the compiler.
A generic runtime error will be thrown for all errors that are not covered by the
above list of errors. These are usually constructor requirements, for example
when using a RegExp()
an unsupported flag is given:
// ✘: these are not proper 'RegExp()' flags, a BsonCompilersRuntimeError will be thrown.
new RegExp('ab+c', 'beep')
// ✔: 'im' are proper 'RegExp()' flags
new RegExp('ab+c', 'im')
In the case where something has gone wrong within compilation, and an error has occured. If you see this error, please create an issue on Github!
npm install -S bson-compilers
Head over to the readme on contributing to find out more information on project structure and setting up your environment.
FAQs
Source to source compilers using ANTLR
The npm package bson-compilers receives a total of 0 weekly downloads. As such, bson-compilers popularity was classified as not popular.
We found that bson-compilers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 36 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
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.