Created
November 10, 2010 22:39
-
-
Save newtonapple/671669 to your computer and use it in GitHub Desktop.
Fun with InnerHTML & getAttribute. Be careful when using data-attribute...
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
var s = "<p data-foo=\"<script>alert('TEST')</script>\">testing 123</p>"; | |
document.body.innerHTML = s; | |
document.getElementsByTagName('p')[0].getAttribute('data-foo'); | |
// => "<script>alert('TEST')</script>" | |
var s = "<p data-foo=\"\<script\>alert('TEST')</script>\">testing 123</p>"; | |
document.body.innerHTML = s; | |
document.getElementsByTagName('p')[0].getAttribute('data-foo'); | |
// => "<script>alert('TEST')</script>" | |
var s = '<p data-foo="' + "<script>alert('TEST')</script>" + '">testing 123' + '</p>'; | |
document.body.innerHTML = s; | |
document.getElementsByTagName('p')[0].getAttribute('data-foo'); | |
// => "<script>alert('TEST')</script>" | |
var s = "<p>testing 123</p>"; | |
document.body.innerHTML = s; | |
document.getElementsByTagName('p')[0].setAttribute('data-foo', "<script>alert('TEST')</script>"); | |
document.getElementsByTagName('p')[0].getAttribute('data-foo'); | |
// => "<script>alert('foo')</script>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment