jQuery .attr()方法XSS安全吗?

Is jQuery .attr() method XSS safe?

本文关键字:安全 XSS 方法 attr jQuery      更新时间:2023-09-26

这是我的jquery代码片段

       var testURL = $(location).attr('search').split('&');
       ....
       $(location).attr('search',testURL.join('&'));

attr()方法XSS安全吗?看起来没有,因为我在文档中没有找到任何与转义相关的内容,如果没有,我如何转义它?

更新:-

基本上我的问题是在获取和设置两者的背景下。首先,我得到$(location).attr('search').split('&');,并在它上做分裂。如果查询字符串包含恶意数据,这里会有吗?

同时设置我正在做$(location).attr('search',testURL.join('&'),如果testURL包含恶意数据怎么办?

$(location).attr('search', whatever);

等价于

location.search = whatever;

所以它并不比纯Javascript版本更安全