Skip to content

Instantly share code, notes, and snippets.

@helhum
Created April 20, 2014 09:16
Show Gist options
  • Save helhum/11109474 to your computer and use it in GitHub Desktop.
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
// 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