Lab: Stored XSS into anchor href attribute with double quotes HTML-encoded
Observe
- Open detail blog post
- Try to post a comment with all value inserted (
Comment,Name,Email,Website) - After
Post Commentsuccess, open detail blog post again, and notice that we able to click the name of the user who post a comment. And if we click, we will redirected to the website url that we input in the fieldWebsite. - Inspect the element, and notice that the value of
Websitein the form are placed in thehrefattribute insideatag inside section comment. - Try to use
" onclick=”alert(document.domain);"in theWebsitewhen post a comment for execute a javascript onclick event, but after submit and inspect the web page, our code is replaced like this:
<a id="author" href="" onclick="alert(document.domain)"">name01</a>It seems like this website already implement double quotes HTML-encoded and it makes our javascript alert code won’t be executed with this payload.
Solution
- Post a new comment. But this time, in the
Websitefield use valuejavascript:alert(document.domain). - Post comment and success
- If we inspect element again, the
atag looks like this:
<a id="author" href="javascript:alert(document.domain)">name02</a>- Click user name on the comment section, and alert will popped up.
Conclusion
If website already prevent us to escape from href attribute and make us cannot use payload something like " onclick="alert(document.domain)". We still able to execute javascript code inside href attribute using prefix javascript:, for example href="javascript(document.domain)".