Created
April 20, 2014 09:16
-
-
Save helhum/11109474 to your computer and use it in GitHub Desktop.
Correctly (HTML) encoded values can lead to XSS when re-used in JavaScript context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Value = <h1>Hello</h1> | |
<!-- Assuming {Value} will be correctly encoded for HTML attribute context --> | |
<a href="/foo" id="foo" title="{Value}">{Value}</a> | |
<div id="targetEl"></div> | |
<script> | |
// This kind of JS can still lead to XSS | |
var title = jQuery("#foo").attr("title"); | |
// jQuery inserts the plain HTML into the DOM and even evaluates <script> tags | |
jQuery("#targetEl").html(title); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment