Cross Site Scripting (XSS): Do I need to escape the ampersand?

风流意气都作罢 提交于 2019-11-27 23:48:30

You should really take a look at the OWASP XSS Prevention Cheat Sheet.

You should escape & because it can be used to circumvent other defenses. Consider this code:

<button onclick="confirm('Do you really want to delete <%= data_from_user; %> ?'">Delete</button>

To defend against XSS inside the onclick event handler, the developer escapes ', ", < and > in data_from_user and thinks everything is ok. The problem is that if the attacker types &#39; which passes the escaping, but ends up allowing the attacker to run javascript.

Example here: http://erlend.oftedal.no/blog/?blogid=124

you use & to concatenate params in the URL:

Reflected XXS:
Script code is injected in the URL which the webpage reflects to victims

http://mybank.com/page?message= < script src = “evil _script.js” />

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!