express-auto-sanitize

1.1.0 • Public • Published

GitHub license Download

Installation

npm i --save express-auto-sanitize

Usage

Import the module with this declaration at the top of the file:

const sanitizer = require('express-auto-sanitize')

Mount the middleware

const options = {
    query: Boolean,
    body: Boolean,
    cookies: Boolean,
    original: Boolean, // will keep the original version in req.original
    sanitizerFunction: Function // use your personnal sanitizing algorithm
}
app.use(sanitizer(options))

Note: if you use the body option, make sure you mount the sanitizer between the body-parser/cookie-parser middleware and your routes declaration.

Output

After the middleware has processed the input, the original version will be stored in req.original and the safe version will replace the dangerous input.

app.get('/', (req, res) => {
    console.log(req.query.exampleParam) // safe and sanitized
    console.log(req.original.query.exampleParam) // potentially dangerous
})

License

express-auto-sanitize is MIT licensed.

Package Sidebar

Install

npm i express-auto-sanitize

Weekly Downloads

56

Version

1.1.0

License

MIT

Unpacked Size

9.4 kB

Total Files

8

Last publish

Collaborators

  • afrigon