Skip to content

gmfx/express-sanitizer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-sanitizer

Build Status

An express middleware for Caja-HTML-Sanitizer, which wraps Google Caja sanitizer.

A useful complement to the express-validator -- to fill a gap now that XSS sanitization support has been removed from that module's parent node-validator.

Installation

npm install express-sanitizer

Usage

Needs to be called after express.bodyParser() and before anything that requires the sanitized input, e.g.:

var express = require('express'),
    expressSanitizer = require('express-sanitizer');

app.use(express.bodyParser());
app.use(expressSanitizer([options])); // this line follows express.bodyParser()
app.post('/:urlparam', function(req, res) {
  //validation here

  // replace an HTTP posted body property with the sanitized string
  req.body.propertyToSanitize = req.sanitize(req.param('propertyToSanitize'));
});

Output

The string

'<script>hello</script> world'

will be sanitized to ' world'.

Limitations

This is a basic implementation of Caja-HTML-Sanitizer with the specific purpose of mitigating against persistent XSS risks.

Caveats

This module trusts the dependencies to provide basic persistent XSS risk mitigation. A user of this package should review all packages and make their own decision on security and fitness for purpose.

Changelog

v0.1.0

  • Initial release

Contributors

License

Copyright (c) 2014 Mark Andrews [email protected], MIT License

About

An express.js middleware for node-validator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published