Code Monkey home page Code Monkey logo

xss-escape's Introduction

#xss-escape

Escapes strings for safe insertion into html, and helps prevents cross site scripting attacks.

xss-escape escapes the following characters to their respective html character codes.

  • & -> &
  • < -> &lt;
  • > -> &gt;
  • " -> &quot;
  • ' -> &#x27;
  • / -> &#x2F;
  • Note that xss-escape only protects data being used in the body of html elements. It does not protect in other contexts such as html attribute or url contexts.

##In NodeJS npm install xss-escape

var xssEscape = require('xss-escape');
var escapedString = xssEscape(unsafeString);

##In the Browser

<script src="path/to/xss-escape.js"></script>
<script>
    var escapedString = xssEscape(unsafeString);
</script>

##Can be used with nested objects or arrays.

var escapedObject = xssEscape({ a: 'foo', [{ b: 'bar' }, 'baz' ] });

##Run Tests While in the project's root directory.

  • npm install
  • nodeunit test.js

or run tests on every file save.

  • grunt watch

##Run Benchmarks While in the project's root directory run.

  • npm install
  • grunt benchmark

xss-escape's People

Contributors

dubfriend avatar foxvision avatar

Stargazers

Jinhyeong Bak avatar Adam Demirel avatar SeyyedKhandon avatar Ryu | Chia-Lung Chen avatar Pavel avatar Unknown avatar Richard Shaw avatar Hani Gamal avatar tony avatar 方文雄 avatar  avatar

Watchers

James Cloos avatar  avatar CIH avatar

xss-escape's Issues

Booleans not handled

It doesn't seem to handle booleans. This addition will fix it:

24a25,28
>     var isBoolean = function (value) {
>         return typeof value === 'boolean';
>     };
>     
89a94,96
>         else if(isBoolean(data)) {
>             escapedData = data;
>         }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.