npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-sanitized-escaped

v1.1.1

Published

Express middleware for the sanitizer module using Caja's HTML Sanitizer and HTML escape using htmlencode. Forked from express-sanitize-escape as the original package is no longer maintained

Downloads

398

Readme

express-sanitized

Build Status

Installation

npm install express-sanitize-escape

Usage

Place this directly after all express.use(bodyParser) middlewares and before any express middleware that accesses query or body parameters, e.g.:

var bodyParser = require('body-parser');
var express = require('express');
var expressSanitized = require('express-sanitize-escape');

app.use(bodyParser.urlencoded);
app.use(bodyParser.json);
app.use(expressSanitized.middleware()); // this line follows app.use(bodyParser.json) or the last body parser middleware

The above sanitizes req.body and req.query. In order to sanitize req.params as well, pass in an express router or app to expressSanitized.sanitizeParams, along with the names of the params to sanitize, e.g.:

var express = require('express');
var expressSanitized = require('express-sanitize-escape');

var router = express.router();
expressSanitized.sanitizeParams(router, ['id','name']);

router.get('/:id', function(req, res, next)
{
    // req.params.id is now sanitized.
    ...
});

router.get('/:name', function(req, res, next)
{
    // req.params.name is now sanitized.
    ...
});

Output

The string

'<script>document.write('cookie monster')</script> download now'

will be sanitized to ' download now'.

and

< > ' " &

will be escaped to &lt; &gt; &#39; &quot; &amp;

Limitations

This is a basic implementation of Caja-HTML-Sanitizer with the specific purpose of mitigating against persistent XSS risks. And node-htmlencode to escape all html entities

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.

This module was inspired by express-sanitizer and express-sanitized. The difference here is: This middleware automatically sanitizes post and query values parameter. And automatically html escapes all strings.

Changelog

v1.0.0

  • This is a breaking change.
  • Change to use exports instead of module exports
  • Middleware is now exports.middleware so app.use(expressSanitized()) is now app.use(expressSanitized.middleware())
  • Added a function to decode the body expressSanitized.htmlDecodeBody()
  • Added tests for unicode characters

v0.6.3

  • Added function to sanitize request params of a router

v0.6.1

  • Added additional test for nested object and an array
  • Added chai js for testing

v0.6.0

  • Added htmlencoding
  • Change filer to recurse through all values of the object and sanitize only values that are strings
  • Updated docs to express 4.x and new bodyParser middleware
  • Added License file

v0.5.1

  • Initial release

Contributors

License

Copyright (c) 2016 Finger Food Studios [email protected], MIT License