express-sanitize-middleware

Sanitize Express request body, query, param, headers

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
express-sanitize-middleware
1.0.36 years ago6 years agoMinified + gzip package size for express-sanitize-middleware in KB

Readme

express-sanitize-middleware
Sanitize Express request body, query, param, and headers.
Heads up! This package wraps MapBox's port of Google's Caja sanitizer. Please see the aforementioned repository for details on the actual sanitization functionality.

Installation

# Via NPM
npm install express-sanitize-middleware --save

# Via Yarn
yarn add express-sanitize-middleware

Getting Started

express-sanitize-middleware exposes one function sanitizeRequest.
It can be used anywhere Express middleware can.

Example: sanitize request body

const express = require('express');
const sanitizeRequest = require('../middleware/express-sanitize-middleware');

const router = express.Router();

router.post('/', [
  sanitizeRequest({
    body: true
  }),
], (req, res, next) => {
  return res.json({message: 'Request body sanitized!'});
});

API Reference

sanitizeRequest(options)

The options argument is required and should contain at least one key dictacting what request property to sanitize.
| Option key | Default | | -------- | ----------- | | body | false | | header | false | | params | false | | query | false |

License

MIT License Copyright (c) 2018 Joel Colucci