繁体   English   中英

js 代码 $(this).attr('name') 的 checkmarx 扫描问题

[英]checkmarx scan issue with the js code $(this).attr('name')

我在我的js文件中写了下面这行代码

var radio =
DOMPurify.sanitize($($.parseHTML(decodeURIComponent(encodeURIComponent($
(this).attr('name'))))).text());

并且 checkmarx 扫描在上面的行抛出以下错误

“应用程序在生成的 output 中嵌入不受信任的数据,在 com.js 的上述行中。这些不受信任的数据未经适当的清理或编码直接嵌入到 output 中,使攻击者能够将恶意代码注入 output。”

有人可以告诉我我做错了什么以及我需要做什么才能解决这个漏洞问题吗? 提前致谢

我已经实施了 DOMPurify.sanitize

我在您的代码中看到两个相互矛盾的问题。

  1. 您正在编码 (this).attr('name')然后将其解码回来(为什么?)
  2. 您不需要使用 parseHtml,因为 (this).attr('name') 已经是 DOM object

你可以简单地把它写成:

var radio = DOMPurify.sanitize(($(this).attr('name')).text());

暂无
暂无

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

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