Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

mongo-sanitize

vkarpov15155kMIT1.1.0TypeScript support: definitely-typed

Helper to sanitize mongodb queries against query selector injections

mongodb, sanitize, query, selector, injection, Petko

readme

mongo-sanitize

For the passionately lazy, a standalone module that sanitizes inputs against query selector injection attacks:

var sanitize = require('mongo-sanitize');

// The sanitize function will strip out any keys that start with '$' in the input,
// so you can pass it to MongoDB without worrying about malicious users overwriting
// query selectors.
var clean = sanitize(req.params.username);

Users.findOne({ name: clean }, function(err, doc) {
  // ...
});

If sanitize() is passed an object, it will mutate the original object.

changelog

1.1.0 / 2020-03-01

  • feat: sanitize recursively and refactor tests #6 YC

1.0.1 / 2018-11-26

  • docs: add repo url to package.json #4 rdubigny