Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-sanitizer

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-sanitizer

Express middleware for the sanitizer module.

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.1K
decreased by-5.9%
Maintainers
1
Weekly downloads
 
Created
Source

npm Build Status npm dependencies Known Vulnerabilities

Notice: The primary dependency for this library hasn't been updated in 5 years. Before using this library, consider other options such as express-validator.

express-sanitizer

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

yarn add express-sanitizer

or

npm install --save express-sanitizer

Usage

Import the module

const expressSanitizer = require('express-sanitizer');

Mount the middleware below the express.json() (or, prior to express v4.16, bodyParser()) instantiation and above mounting of your routes

app.use(express.json());

// Mount express-sanitizer middleware here
app.use(expressSanitizer());

app.post('/', function(req, res, next) {
  // replace an HTTP posted body property with the sanitized string
  const sanitizedString = req.sanitize(req.body.propertyToSanitize);
  // send the response -- res.body.sanitized = " world"
  res.send({ sanitized: sanitizedString });
});

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 (note the borderline abandonware comments in that repo!).

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

v1.0.6

  • Removed unused dependency

v1.0.5

  • Unit tests (better late than never)

v1.0.4

  • Merged PR #3 from Brian M. Jemilo II

v1.0.3

  • Updated README to base example on an express-generator scaffolded application

v1.0.2

  • Updated sanitizer dependency to 0.1.3
  • Merged PR #4 from @ScottRamsden

v1.0.1

  • Updated sanitizer dependency to 0.1.2

v1.0.0

  • Update to v1

v0.1.1

  • Merged PR removing unused dependency

v0.1.0

  • Initial release

Contributors

License

Copyright (c) 2021 Mark Andrews 20metresbelow@gmail.com, MIT License

Keywords

FAQs

Package last updated on 16 Apr 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc