Socket
Socket
Sign inDemoInstall

express-mongo-sanitize

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    express-mongo-sanitize

Sanitize your express payload to prevent MongoDB operator injection.


Version published
Maintainers
1
Install size
9.40 kB
Created

Changelog

Source

[1.1.0] - 2016-01-13

Added

  • The middleware also now sanitizes keys with a .. This is in line with Mongo's reserved operators.

Readme

Source

Express Mongoose Sanitize

Express 4.x middleware which sanitizes user-supplied data to prevent MongoDB Operator Injection.

Installation

npm install express-mongo-sanitize

Usage

Add as a piece of express middleware, before defining your routes.

var express = require('express'),
    bodyParser = require('body-parser'),
    mongoSanitize = require('express-mongo-sanitize');

var app = express();

app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(mongoSanitize());

What?

This module removes any keys in objects that begin with a $ sign from req.body, req.query or req.params.

Why?

Object keys starting with a $ are reserved for use by MongoDB as operators. Without this sanitization, malicious users could send an object containing a $ operator, which could change the context of a database operation. Most notorious is the $where operator, which can execute arbitrary JavaScript on the database.

The best way to prevent this is to sanitize the received data, and remove any offending keys.

Credits

Inspired by mongo-sanitize.

License

MIT

Keywords

FAQs

Last updated on 13 Jan 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc