Microsoft toStaticHTML HTML Sanitizing Bypass

Aleph Research Advisory





  1. Microsoft Internet Explorer

  2. Microsoft SharePoint

  3. Microsoft Lync


Apply patches.

Technical Details

An attacker is able to create a specially formed CSS that will overcome toStaticHTML’s security logic; therefore, after passing the specially crafted CSS string through the toStaticHTML function, it will contain an expression that triggers a JavaScript call.

The following JavaScript code demonstrates the vulnerability:


In this case the function’s return value would be JavaScript executable:


The reason this code bypasses the filter engine is due to twofold:

The filtering engine allows the string “expression(“ to exists in “non-dangerous” locations within the CSS. A bug in Internet Explorer’s CSS parsing engine doesn’t properly terminate strings that are opened inside brackets and closed outside of them. When combining these two factors the attacker is able to “confuse” the filtering mechanism into “thinking” that a string is open when in fact it is terminated and vice versa. With this ability the attacker can trick the filtering mechanism into entering a state of the selector context which is considered safer where in fact the code is just a new declaration of the same selector, thus breaking the state machine and bypassing the filter.

Due to this weakness, every application that relies on the toStaticHTML component to sanitize user supplied data had probably been vulnerable to XSS.



  • Adi Cohen

External References