Skip to content

azu/express-mongo-sanitize-reporter

Repository files navigation

Warning ⚠️

express-mongo-sanitize support dryRun option.

Please use express-mongo-sanitize.

express-mongo-sanitize-reporter

Dry-Run mode for express-mongo-sanitize.

This express middleware does not drop sanitized property. Instead of it, It just calls report function as callback.

Motivation

express-mongo-sanitize drop invalid property from request.

I want to check that the application use $ and . as valid case before introducing express-mongo-sanitize.

So, I want to get dry-run/report-only mode for express-mongo-sanitize.

Install

Install with npm:

npm install express-mongo-sanitize-reporter

Usage

You can set report option for this middleware.

It is dry-run mode.

import express from 'express';
import bodyParser from 'body-parser'; 
import mongoSanitize from 'express-mongo-sanitize-reporter';

const app = express();

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

// To report data, use:
app.use(mongoSanitize({
  report: (req, key, value) => console.warn("This request will be invalid", req)
}));

Sanitizing mode:

import express from 'express';
import bodyParser from 'body-parser'; 
+ import mongoSanitize from 'express-mongo-sanitize';
- import mongoSanitize from 'express-mongo-sanitize-reporter';

const app = express();

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

// To remove data, use:
+ app.use(mongoSanitize());
- app.use(mongoSanitize({
-   report: (req, key, value) => console.warn("This request will be invalid", req)
- }));

Changelog

See Releases page.

Running tests

Install devDependencies and Run npm test:

npm test

Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, please create an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

License

MIT © azu