authbox.sanitization
Last updated 2 months ago by rhys_hampton_io .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install authbox.sanitization 
SYNC missed versions from official npm registry.

AuthBox sanitization middleware

Usage

Basic

The following example will sanitize both req.query and req.body values

const express = require('express');
const bodyParser = require('body-parser');
const sanitization = require('authbox.sanitization');

const app = express();
app.use(bodyParser.urlencoded({ extended: true }));

// This line must come AFTER using body-parser
app.use(sanitization());

Customise what is sanitized

You can also specify if you want to not sanitise either query or body values

app.use(sanitization({
  sanitizeQuery: false,
}));
app.use(sanitization({
  sanitizeBody: false,
}));

Customise sanitization

You can also customise the sanitization routine. The following example shows applying a custom rule to enforce a specific regex for a uid parameter.

app.use(sanitization({
  sanitizer: (key, value) => {
    if(key.toLowerCase() === 'uid') {
      return !/^[A-Za-z0-9]+$/.test(value) ? '' : value;
    } else {
      // You can still call the default sanitizer too
      return sanitization.defaultSanitizer(key, value);
    }
  },
}));

Current Tags

  • 1.0.0                                ...           latest (2 months ago)

1 Versions

  • 1.0.0                                ...           2 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |