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.
bson-buffer
Advanced tools
This is a fork with breaking changes!
This is a fork of the mongodb js-bson project located at https://github.com/mongodb/js-bson). The modifications are simple, but breaks compatibility with the original software.
See the BSON-buffer changes
section for more details.
If you don't yet know what BSON actually is, read the spec.
The browser version of the BSON parser is compiled using webpack and the current version is pre-compiled in the browser_build directory. To build a new version perform the following operation.
npm install
npm run build
A simple example of how to use BSON in the browser:
<script src="./browser_build/bson.js"></script>
<script>
function start() {
// Get the Long type
var Long = BSON.Long;
// Create a bson parser instance
var bson = new BSON();
// Serialize document
var doc = { long: Long.fromNumber(100) }
// Serialize a document
var data = bson.serialize(doc)
// De serialize it again
var doc_2 = bson.deserialize(data)
}
</script>
A simple example of how to use BSON in node.js
:
// Get BSON parser class
var BSON = require('bson')
// Get the Long type
var Long = BSON.Long;
// Create a bson parser instance
var bson = new BSON();
// Serialize document
var doc = { long: Long.fromNumber(100) }
// Serialize a document
var data = bson.serialize(doc)
console.log('data:', data)
// Deserialize the resulting Buffer
var doc_2 = bson.deserialize(data)
console.log('doc_2:', doc_2)
npm install bson-ext
For all BSON types documentation, please refer to the documentation for the mongodb driver.
https://github.com/mongodb/node-mongodb-native
new BSON()
- Creates a new BSON seralizer/deserializer you can use to serialize and deserialize BSON.
The BSON serialize method takes a javascript object and an optional options object and returns a Node.js Buffer.
The BSON serializeWithBufferAndIndex method takes an object, a target buffer instance and an optional options object and returns the end serialization index in the final buffer.
The BSON calculateObjectSize method takes a javascript object and an optional options object and returns the size of the BSON object.
The BSON deserialize method takes a node.js Buffer and an optional options object and returns a deserialized Javascript object.
The BSON deserializeStream method takes a node.js Buffer, startIndex and allow more control over deserialization of a Buffer containing concatenated BSON documents.
The purpose of this fork is to introduce direct conversion of BSON type Binary to Buffer and vice versa. In the browser it uses Uint8Array instead of Buffer, but the general idea is the same. This only works reliably if there is only need for a single subtype.
Example:
var in = { payload: new Buffer('00FF00FF00FF', 'hex') }
var ser = BSON.serialize(in);
var out = BSON.deserialize(ser);
Value of out
in this fork implementation
{ payload: Buffer } // '00FF00FF00FF'
Value of out
in original implementation
{ payload: {
_bsonType: 'Binary',
sub_type: BSON_BINARY_SUBTYPE_DEFAULT,
buffer: Buffer } } // '00FF00FF00FF'
FAQs
A bson parser for node.js and the browser
We found that bson-buffer 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.