如何防止XSS攻击角应用
我的响应中有这个脚本< img src = x onerror =“ alert('taction')” ,在我执行此操作的.ts文件中 document.getElementById(“ help”)。innerhtml = this.help; 它正在前端执行并发出警报。建议如何停止此操作 使用内容安全性用作 但是没有用..有什么建议吗?请帮忙
I have this script in my response <img src=x onerror="alert('attack')" and in my .ts file i'm doing this
document.getElementById("help").innerHTML=this.help;
and it is executing in frontend and giving alert .. suggest how to stop this
using content-security-policy as
but no use.. any suggestions? please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用这样的消毒剂
Use sanitizer, like this
对于OnError事件属性,您需要使用事件侦听器重写,最好是在单独的JS文件中而不是内联。
如果它是未格式化的文本,则您的目标是使用InnerHTML插入,您应该使用TextContent方法,因为它是XSS安全的。另一个选择也是使用dompurify使其安全。
For the onerror event attribute you'll need to rewrite using an event listener instead, preferably in a separate js file and not inline.
If it is unformatted text you aim to insert with innerHTML you should use textContent method instead as it is XSS safe. Another option is also to use DOMPurify to make it XSS safe.