Rule Definition
jQuery before 1.9.0 is vulnerable to Cross-site Scripting (XSS) attacks. The jQuery(strInput) function does not differentiate selectors from HTML in a reliable fashion. In vulnerable versions, jQuery determined whether the input was HTML by looking for the '<' character anywhere in the string, giving attackers more flexibility when attempting to construct a malicious payload. In fixed versions, jQuery only deems the input to be HTML if it explicitly starts with the '<' character, limiting exploitability only to attackers who can control the beginning of a string, which is far less common. This rule has been listed as CVE-2012-6708 in the CVE registry.
Remediation
Do not use .html() or upgrade the jQuery library version
Violation Code Sample
// version impacted by the vulnerability
<script src="https://code.jquery.com/jquery-1.9.0.js"></script>
<div id="log">Test passed</div>
...
<script>
$("#log").html(
$("element[attribute='<div><strong>you should not see this</strong></div>']").html()
);
</script>
...
Fixed Code Sample
// version NOT impacted by the vulnerability
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<div id="log">Test passed</div>
...
<script>
$("#log").html(
$("element[attribute='<div><strong>you should not see this</strong></div>']").html()
);
</script>
...
Reference
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-6708
Related Technologies
Technical Criterion
CWE-676 - Use of Potentially Dangerous Function
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.