# mongo-sanitize

> Helper to sanitize mongodb queries against query selector injections

Latest version **1.1.0** (published 2020-03-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install mongo-sanitize
pnpm add mongo-sanitize
yarn add mongo-sanitize
bun add mongo-sanitize
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-03-02 |
| First published | 2014-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/mongo-sanitize) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 142 |
| Author | Valeri Karpov |
| Maintainers | vkarpov15 |
| Keywords | mongodb, sanitize, query, selector, injection, Petko |

## Links

- npm: https://www.npmjs.com/package/mongo-sanitize
- Repository: https://github.com/vkarpov15/mongo-sanitize
- Homepage: https://github.com/vkarpov15/mongo-sanitize#readme
- Issues: https://github.com/vkarpov15/mongo-sanitize/issues
- npm.io page: https://npm.io/package/mongo-sanitize

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2020-03-02
- 1.0.1 — 2018-11-26
- 1.0.0 — 2014-09-04

## README

mongo-sanitize
==============

For the passionately lazy, a standalone module that sanitizes inputs against [query selector injection attacks](http://blog.websecurify.com/2014/08/hacking-nodejs-and-mongodb.html):

```
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.

---
_Source: https://npm.io/package/mongo-sanitize · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
