express-mongo-sanitize-reporter
v2.1.0
Published
Dry-Run mode for express-mongo-sanitize.
Downloads
628
Maintainers
Readme
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.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Author
License
MIT © azu