top of page
  • Writer's pictureAdi "Adico" Cohen

Microsoft Anti-XSS Library Bypass (MS12-007)

The following post describes the second bypass I found to the toStaticHTML function in IE - back in 2012.



The Microsoft Anti-XSS Library is used in ASP .NET applications to protect against Cross-Site Scripting attacks, by providing methods for input sanitization.


Microsoft Anti-XSS Library 3.0 and 4.0 are vulnerable to an attack in which an attacker is able to create a specially formed CSS, that after passing through the GetSafeHTML or GetSafeHTMLFragment methods, contains an expression that triggers a JavaScript call in Internet Explorer.

The following ASP .NET code demonstrates the vulnerability:

1. string data = Microsoft.Security.Application.Sanitizer.GetSafeHtml("<html>a<style><!--div{font-family:Foo,Bar\\,'a\\a';font-family:';color:expression(alert(1));y'}--></style><div>b</div></html>");

2. string data = Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment("<div style=\"font-family:Foo,Bar\\,'a\\a';font-family:';color:expression(alert(1));y'\">aaa</div>");


The string value can be broken down to a readable form (before sanitization):


A bug in the Anti-XSS library causes the closing apostrophe in the first CSS rule to be dropped. Because of the string not being properly terminated, Internet Explorer now renders this CSS in a different way, which triggers a javascript call (after sanitization):



Every application that relies on either GetSafeHTML or GetSafeHtmlFragment to sanitize user supplied data is vulnerable to XSS.


Microsoft has issued a the Anti-XSS library 4.2 to address this issue.



An old post from 2012. Originally published under Watchfire's (IBM) Blog

Discovered by - Adi Cohen, IBM Application Security Research

260 views0 comments

Recent Posts

See All

XSS in Gmail's Amp4Email

Background AMP is most commonly used as a framework to develop fast-loading content on the web. One of AMP's projects, AMP4Email has been adopted in recent years by many of the leading mail services a

JSON-based XSS exploitation

The following post describes a new method to exploit injections in JSON file - Back in 2012 Introduction: In the world of Web2.0 and mash web applications, security researchers come across more and mo

toStaticHTML: The Second Encounter (CVE-2012-1858)

The following post describes the second bypass I found to the toStaticHTML function in IE - back in 2012. Introduction: The toStaticHTML component, which is found in Internet Explorer > 8, SharePoint


bottom of page