Secure XSS Filters - Just sufficient output filtering to prevent XSS!
npm install xss-filtersSecure XSS Filters
=================
Just sufficient output filtering to prevent XSS!
[![npm version][npm-badge]][npm]
[![dependency status][dep-badge]][dep-status]

[npm]: https://www.npmjs.org/package/xss-filters
[npm-badge]: https://img.shields.io/npm/v/xss-filters.svg?style=flat-square
[dep-status]: https://david-dm.org/yahoo/xss-filters
[dep-badge]: https://img.shields.io/david/yahoo/xss-filters.svg?style=flat-square
- More Secure. Context-dependent output filters that are developer-friendly. It is safe to apply these filters like so:
document.write("" + xssFilters.uriInHTMLData(url) + "");
In this example, the traditional wisdom of blindly escaping some special html entity characters (& < > ' " ` `) would not stop XSS (e.g., when url is equal to javascript:alert(1) or onclick=alert(1)).
- Faster with Just Sufficient Encoding. Encode the minimal set of characters to thwart JavaScript executions, thus preventing XSS attacks while keeping most characters intact. Compared to the traditional blindly escape filter, our filters are up to two times faster, and there is no more double-encoding problems such as '&lt;'!!
!alt Visualizing the concept of just sufficient encoding
Figure 1. "Just sufficient" encoding based on the HTML5 spec.
Install the xss-filters npm, and include it as a dependency for your project.
`sh`
npm install xss-filters --save
Require xss-filters, and you may use it with your favorite template engine. Or just use it directly:
`javascript
var express = require('express');
var app = express();
var xssFilters = require('xss-filters');
app.get('/', function(req, res){
var firstname = req.query.firstname; //an untrusted input collected from user
res.send('
app.listen(3000);
`
Simply download the latest minified version from the dist/ folder OR from the CDN. Embed it in your HTML file, and all filters are available in a global object called xssFilters.
`html`
...
API Documentations
-------
(1) Filters MUST ONLY be applied to UTF-8-encoded documents.
(2) DON'T apply any filters inside any scriptable contexts, i.e.,