According to OWASP recommendations, CSS values from an untrusted source should be escaped.
- Link to OWASP cheat sheet: https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.234_-_CSS_Escape_And_Strictly_Validate_Before_Inserting_Untrusted_Data_into_HTML_Style_Property_Values
In an attempt to follow these recommendations I am escaping my CSS values using Microsoft's AntiXss library, specifically System.Web.Security.AntiXss.AntiXssEncoder.CssEncode(value)
.
This produces a stylesheet that looks like this:
a,
a:visited {
color:\00002329c;
}
a:hover,
a:active {
color:\000023036;
}
body {
background:\000023eee;
color:\000023333;
font-family:Arial;
font-size:15px;
}
This works fine for IE and Chrome, but Firefox will not recognize the escaped values.
Is this a bug with Firefox or am I misinterpreting how to implement the OWASP recommendation? Also, if this is a Firefox shortcoming then what is the best work around?