Giter Site home page Giter Site logo

jsanity's Introduction

jSanity

A secure-by-default, performant, cross-browser client-side HTML sanitization library.

Reference:
OWASP AppSec EU 2013 Talk
Slides

Status

2/18/2016: @kh9n has completed a significant refactoring.

  • jQuery and setImmediate dependencies were removed!
  • jSanity now supports both sync and async modes.
  • Version rev'd to 0.3.

Demo / Benchmark pages

Demo
Benchmark

Todo

  • Support for more elements and attributes
  • Update / document the demo & benchmark pages
  • Unit tests
  • Better solution for STYLE elements
  • Integration with one or more javascript frameworks
  • Experimental override for default sanitization in various web platforms
  • Leverage newer features of the web platform (Shadow DOM, etc.)
  • Remove jQuery usage from benchmark page
  • General code clean up / modernization

Special thanks for making jSanity a reality:

  • Ben Livshits
  • Gareth Heyes
  • Loris D'Antoni
  • Mario Heiderich
  • Matt Thomlinson
  • Michael Fanning

jsanity's People

Contributors

jingxuan0109 avatar kh9n avatar michaelcfanning avatar microsoft-github-policy-service[bot] avatar msftgits avatar randomdross avatar zhujiahuifighting avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsanity's Issues

JSanity strips out text-decoration on Chrome 57+ and Firefox 36+

JSanity strips out text-decoration on Chrome 57+ and Firefox 36+
After those versions, the browsers switched text-decoration to be a shorthand for:

  • text-decoration-line
  • text-decoration-style
  • text-decoration-color
  • text-decoration-thickness

The sanitizer works by reading the computed values, so it sees these new properties, doesn't recognize them, and sets them to null.
Depending on the browser, this affects the shorthand property text-decoration differently, but in effect, it removes the property.

See also: https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration

XSS bypass by DOM Clobbering

Here is the vector:

<form name="body" onmouseover="alert(1)" style="height:800px"><fieldset name="attributes"><form></form><form name="parentNode"><img id="attributes"></form></fieldset></form>

some more vectors can be seen here: http://www.thespanner.co.uk/2012/06/05/jslr/

The above payload was by @cgvwzq โ€“ Pepe Vila to bypass JSLR (Gareth Heyes' old toy)

[XSS, Security] Bypass found using DOMPurify tests

Hi all,

it appears that jSanity can be bypassed using multiple techniques. We have not yet sorted out which ones - but the bypassed reproduce cleanly when using the DOMPurify test cases.

Steps to reproduce:

Strangely, we don't see any errors on the console, so we are not sure yet what causes the problem. Please let us know if this description is sufficient for you or if we should have a closer look together.

Additional Info:

support for picture and other harmless elements

I realize that picture is not in HTML5 but rather was proposed after it was finished, but it is implemented in many browsers, it is on a standards track, and it is as harmless as the img and source elements it's based around.

I also wonder what you think about allowing a couple old and nonstandard but still harmless elements: blink and marquee (even though I am aware that no modern browser even supports blink anymore).

Prototype properties and comments potential issues

Breaking out two issues from Koto (second comment in issue #5) to track separately:

var in Object will let through prototype properties:

<constructor desc="element name bypass, harmless" constructor="same here">
<b style="constructor: url(//do-stuff.harmless-now)">a</b>

HTML comments should not be let through, otherwise mXSS via e.g. document.createComment('--><script>alert(1)</script>')

[XSS, Security] Bypass found using mXSS and Scriptlets

Another bypass was spotted based on the mutations caused by the default jSanity behavior exposed on the demo. Affected browsers are MSIE <= 11 when running in older document modes.

Example Input:

<p style="font-family:'\22\3b\62\65havior:url(/callback.json?cb=<scriptlet>...</scriptlet>)\3b'">123

Resulting Output:

<span><p style='font-family: "";behavior:url(/callback.json?cb=<scriptlet>...</scriptlet>);";'>123</p></span>

This attack can be carried out, in case the attacker has control over another same-domain resource that would be served as JSON, image, XML or anything else that wouldn't render as a document.

Example Attack:
http://innerht.ml/challenges/kcal.pw/puzzle5.php/?name=%3Cmeta%20http-equiv=x-ua-compatible%20content=ie=5%20{}*{behavior:url%28%27http://innerht.ml/challenges/kcal.pw/styles.php?data=%253CSCRIPTLET%253E%2520%253CIMPLEMENTS%2520Type%253D%2522Behavior%2522%253E%253C%252FIMPLEMENTS%253E%2520%253CSCRIPT%2520Language%253D%2522javascript%2522%253Ealert%25281%2529%253C%252FSCRIPT%253E%2520%253C%252FSCRIPTLET%253E%27%29}

Note that DOMPurify protects itself against these kinds of attacks by falling back to use toStaticHTML in dangerous document modes. It might be recommendable for jSanity to do this as well:

https://github.com/cure53/DOMPurify/blob/master/src/purify.js#L632

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.