简体   繁体   English

JavaScript 中的 XSS 漏洞

[英]XSS vulnerability in javascript

Fortify showing XSS vulnerability for following code on document.write Fortify 在 document.write 上显示以下代码的 XSS 漏洞

for (var i in this.links)
{
 if (i == this.links.length - 1)
 {
   document.write(((i == 0) ? "" : " | ") + this.text[i]);
 }
 else
 {
   document.write(((i == 0) ? "" : " | ") + "<a href='" + this.links[i] + "'>" + this.text[i] + "</a>");
 }
} 

You need to sanitize your data before you use document.write.在使用 document.write 之前,您需要清理数据。 Also, since you're inserting HTML into the DOM you are opening yourself up for DOM XSS Attacks.此外,由于您将 HTML 插入到 DOM 中,因此您正在为 DOM XSS 攻击敞开大门。

I advise you to read this on how to prevent XSS and this to prevent DOM based XSS attacks我建议你阅读关于如何防止XSS和这个防止基于DOM的XSS攻击

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM