Giter Site home page Giter Site logo

escapist.js's Introduction

Escapist.js

Escapist is a small JavaScript library that gives strong protection from cross-site scripting (XSS) by aggressively escaping untrusted data for display in HTML.

Escapist is essentially a fork of the Reform library's JavaScript implementation from OWASP, written by Michael Eddington.

The bulk of the escapist code is Reform's. Escapist provides some small updates as well as a simpler, namespaced API around the tried-and-true Reform code. The core Reform logic has not been modified.

(I first wrote this code a few years ago as a simple wrapper around Reform, and am recreating the code now, starting from a clean copy of Reform.js v.0.12, so the code pedigree is clear & escapist's changes can be reviewed commit by commit in this new git project.)

Usage

You can use escapist in JavaScript code or HTML templates. Add the built file from dist/escapist.js to your project, include it in your HTML via a <script> tag, and then call the escapist API as needed. Its functions return properly escaped text for inclusion in HTML:

<p> <%= escapist.html( untrustedText ) %> </p>

Or you can use the secure alias for escapist:

<p> <%= secure.html( untrustedText ) %> </p>

There are different functions for the different client-side contexts in which untrusted data has to be escaped (HTML & HTML attributes for now; URL query parameters coming soon).

API

Escapist provides a simple API with clear semantics. It uses a secure global namespace (and escapist, too) with these functions:

  • secure.html( untrustedText ) : escape for inclusion of the string variable untrustedText in HTML elements.
  • secure.attr( untrustedText ) : escape for inclusion in a quoted HTML attribute.

Install Source & Build

Check out the source, install node.js with npm package manager, then install grunt-cli globally:

npm install -g grunt-cli

Then cd to the escapist directory and npm install to install the escapist.js dependencies.

To build, run grunt to create the full dist/escapist.js distribution file.

Tests

Escape.js uses qunit for unit tests. To run the tests, first run a simple test server so you can load the tests/index.html file in a browser:

node tests/testserver.js

Then point your browser to http://localhost:8080/tests/ to run the tests & view the test results.

License

MIT License.

Escapist is MIT licensed. It includes modified code from Reform, which is also uses the MIT license. See the license file for details.

escapist.js's People

Contributors

mstapp avatar

Stargazers

Piotr Kowalski avatar Jeff Garretson avatar

Watchers

 avatar James Cloos avatar

escapist.js's Issues

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.