Socket
Socket
Sign inDemoInstall

scorpion4dev-express-autosanitizer

Package Overview
Dependencies
1
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    scorpion4dev-express-autosanitizer

automatic sanitization of req body fields, params and query. automatically does sanitization and escaping as middleware.


Version published
Weekly downloads
1
decreased by-87.5%
Maintainers
1
Install size
85.6 kB
Created
Weekly downloads
 

Readme

Source

Installation

npm i --save scorpion4dev-express-autosanitizer

Usage

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

const sanitizer = require('scorpion4dev-express-autosanitizer')

Mount the middleware

const options = {
  body: Boolean, // default is true
  params: Boolean, // default is true
  query: Boolean, // default is true
  cookies: Boolean, // default is false
  headers: Boolean, // default is false
  escapeHtml: Boolean, // default is false
  replaceOriginal: Boolean, // will replace the dangerous input
  replaceCustomValue: Object, // will replace input string with custom value
  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 the original place and the safe version will be stored in req.sanitized.

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

Example for the replaceCustomValue option

...
const options = {
  replaceCustomValue: {
    '$null': null
  }
}
...

app.get('/', (req, res) => {
  console.log(req.query.exampleParam) // assume the output is "$null"
  console.log(req.sanitized.query.exampleParam) // output will be replace by null
})

Keywords

FAQs

Last updated on 07 Sep 2021

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