admin管理员组文章数量:1415421
HP fortify scan shows a dynamic code evaluation issue shows as below.It says eval() function in javascript leads to security issue. How fix this security issue. Below given is the code.
if (objItem.column == 'leftColumn')
{
strItems = lcItems.value
}
else if (objItem.column == 'rightColumn')
{
strItems = rcItems.value;
}
else if (objItem.column == 'toolbox')
{
strItems = tbItems.value;
}
objItems = eval(strItems);
item = null;
Here eval(strItems); is code for security violation. How fix this issue. see the issue details and remendations to fix issue Issue explanation
Recendation to fix issue
HP fortify scan shows a dynamic code evaluation issue shows as below.It says eval() function in javascript leads to security issue. How fix this security issue. Below given is the code.
if (objItem.column == 'leftColumn')
{
strItems = lcItems.value
}
else if (objItem.column == 'rightColumn')
{
strItems = rcItems.value;
}
else if (objItem.column == 'toolbox')
{
strItems = tbItems.value;
}
objItems = eval(strItems);
item = null;
Here eval(strItems); is code for security violation. How fix this issue. see the issue details and remendations to fix issue Issue explanation
Recendation to fix issue
Share Improve this question asked Feb 3, 2016 at 14:53 fortifysafeerfortifysafeer 431 gold badge2 silver badges5 bronze badges 5-
1
Without seeing what you're running through
eval
, it's not possible to tell you how to rewrite it withouteval
(or whether or not you can safely ignore the warnings, in the remote possibility that use ofeval
is actually necessary here). – apsillers Commented Feb 3, 2016 at 14:57 -
What is the code tryping to do? e.g. what does the
strItems
variable evaluate to? Once we know that, we can provide a better solution for you. – scunliffe Commented Feb 3, 2016 at 14:57 - document.getElementById(tbItemsID); – fortifysafeer Commented Feb 3, 2016 at 15:07
-
Are you saying that the value of
strItems
is actually"document.getElementById(tbItemsID);"
? If so, I would modify it to only be the ID that you care about, and then do the lookup by ID instead of the eval statement. – scunliffe Commented Feb 3, 2016 at 15:26 -
If all you want to do is avoid the warning, you could try
(0, eval)(strItems)
. But it would be much better to rewrite the code withouteval
. – user663031 Commented Feb 3, 2016 at 16:25
1 Answer
Reset to default 1It all depends on what the strItems
variable you are using evaluates to (e.g. how is it being used?)
If the value is the ID of another element, then changing the eval line to this would work:
objItems = document.getElementById(strItems);
However if it is the name of an element...
//presuming there is at least 1 match by name, drop the index if you want the "set"
objItems = document.getElementsByName(strItems)[0];
or something else? you'll need to change the code accordingly.
本文标签:
版权声明:本文标题:javascript - How to fix dynamic code evaluation issue in fortify scan because of using eval() in java script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745236444a2649066.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论