A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.npmjs.com/package/xss-filters below:

xss-filters - npm

Secure XSS Filters

Just sufficient output filtering to prevent XSS!

Goals Design Quick Start Server-side (nodejs)

Install the xss-filters npm, and include it as a dependency for your project.

npm install xss-filters --save

Require xss-filters, and you may use it with your favorite template engine. Or just use it directly:

var express = require('express');

var app = express();

var xssFilters = require('xss-filters');

 

app.get('/', function(req, res){

  var firstname = req.query.firstname; 

  res.send('<h1> Hello, ' + xssFilters.inHTMLData(firstname) + '!</h1>');

});

 

app.listen(3000);

Client-side (browser)

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.

<!doctype html>

...

<script src="dist/xss-filters.min.js"></script>

<script>

var firstname = "..."; 

document.write('<h1> Hello, ' + xssFilters.inHTMLData(firstname) + '!</h1>')

</script> 

API Documentations WARNINGS

(1) Filters MUST ONLY be applied to UTF-8-encoded documents.

(2) DON'T apply any filters inside any scriptable contexts, i.e., <script>, <style>, <object>, <embed>, and <svg> tags as well as style="" and onXXX="" (e.g., onclick) attributes. It is unsafe to permit untrusted input inside a scriptable context.

A workaround, if you need to include data for JS, is to use:

<input id="strJS" value="{{{inDoubleQuotedAttr data}}}">

and retrieve your data with document.getElementById('strJS').value.

The API

There are five context-sensitive filters for generic input:

Here we use {{{ }}} to indicate output expression to ease illustrations

Whenever possible, apply the most specific filter that describes your context and data:

Input\Context HTMLData HTMLComment SingleQuotedAttr DoubleQuotedAttr UnQuotedAttr Full URI uriInHTMLData() uriInHTMLComment() uriInSingleQuotedAttr() uriInDoubleQuotedAttr() uriInUnQuotedAttr() URI Path uriPathInHTMLData() uriPathInHTMLComment() uriPathInSingleQuotedAttr() uriPathInDoubleQuotedAttr() uriPathInUnQuotedAttr() URI Query uriQueryInHTMLData() uriQueryInHTMLComment() uriQueryInSingleQuotedAttr() uriQueryInDoubleQuotedAttr() uriQueryInUnQuotedAttr() URI Component uriComponentInHTMLData() uriComponentInHTMLComment() uriComponentInSingleQuotedAttr() uriComponentInDoubleQuotedAttr() uriComponentInUnQuotedAttr() URI Fragment uriFragmentInHTMLData() uriFragmentInHTMLComment() uriFragmentInSingleQuotedAttr() uriFragmentInDoubleQuotedAttr() uriFragmentInUnQuotedAttr()

Check out the documentations for more details.

Contributing

To contribute, make changes in src/ and tests/, and then do:

npm test              

npm run-script build  

npm run-script docs   

License

This software is free to use under the Yahoo BSD license. See the LICENSE file for license text and copyright information.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4