javascript - 将 HREF 与 jQuery 结合使用是否容易受到 XSS 攻击?

标签 javascript jquery xss

Burp suite显示错误。

The application may be vulnerable to DOM-based cross-site scripting. Data is read from location and passed to jQuery() via the following statement: here location is javascript location object containing current address hash jQuery(location).attr('href').split("//")[1]; is the above code vulnerable to cross site scripting?

在下面的代码中使用了

var address = jQuery(location).attr('href').split('//')[1]; 
subdomain = address.split('.')[0]; 
this.href = this.href.replace(subdomain, 'www'); 
window.location = this.href;

最佳答案

似乎是一个误报错误。其他人也有类似的经历。

Burp suite 支持中心的一位人员表示:

The code is very close to being exploitable. If it was:

$(location).attr(‘href’, ‘’ + var1 + ’/’);

And var1 could be controlled by an attacker, they could inject “javascript:alert(document.domain)” and that would be executed. However, prepending the slash will prevent this.

Our static analysis is likely to produce false positives on similar patterns, as we don’t attempt to do string analysis.

Page of thread above

因此,只要您不允许变量进入您的 href 属性,那么您就可以了。在这种情况下,您似乎只读取 href 属性值。

关于javascript - 将 HREF 与 jQuery 结合使用是否容易受到 XSS 攻击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59731618/

相关文章:

jquery - 我无法获得 IE7 的正确窗口高度

python-3.x - 如何在F字符串中转义字段?

javascript - Antisamy 或 Content Security Policy 或两者都用于防止 XSS 攻击

php - strip_tags() 容易受到脚本攻击吗?

javascript - 使用 javascript 从 json 创建选择输入

javascript - Google 电子表格脚本 : toString() not returning a string?

jquery - CSS 悬停状态 - 循环效果

javascript - React 和 Electron,链接事件处理程序

javascript - 如何在 Razor 中使用 JavaScript 变量?

javascript - json 调用在 IE 10 中不会更新