在Angular 13项目上运行CheckMarx时,未检查的循环条件输入

发布于 2025-01-22 23:23:47 字数 989 浏览 5 评论 0原文

在Angular 13项目上运行CheckMarx时,报告结果“循环条件的未检查输入”中等问题。即使限制对象长度,问题也无法解决。 以下是代码:

deepCopy(obj) {
 if (null === obj || "object" !== typeof obj) 
 {return obj};
 if (obj instanceof Array) {
     const copy = [];
     const maxlength=50;
     let len = obj.length;
     if (len > maxlength) {
       len = maxlength
     }
     for (let i = 0; i < len; i++) {
         copy[i] = this.deepCopy(obj[i]);
     }
     return copy;
   
 }

这里的对象将其传递给服务中从组件定义的此方法:

     modelChanges(event, type, child) {
    this.value = this._sharedService.deepCopy(this.value);
    this.value[type][child] = event;
  }

CheckMarx报告说:

method&lt; div class =“ jumbotron” style =“ margin-top:0.5rem;” [ngstyle] =“ styletab”&gt;在src/app/pop/popcreate/popc-define/popc-define.component.html的第1行中获取元素$ event的用户输入。这个元素的价值流动 通过代码未经验证,最终在deepcopy的环境中使用 src/app/shared/shared.service.ts。这构成了循环条件的未检查输入

任何与此相关的建议?

While running the checkmarx on angular 13 project the report results a 'Unchecked Input For loop Condition' medium issue. Even after limiting the object length the issue is not resolved.
Below is the piece of code:

deepCopy(obj) {
 if (null === obj || "object" !== typeof obj) 
 {return obj};
 if (obj instanceof Array) {
     const copy = [];
     const maxlength=50;
     let len = obj.length;
     if (len > maxlength) {
       len = maxlength
     }
     for (let i = 0; i < len; i++) {
         copy[i] = this.deepCopy(obj[i]);
     }
     return copy;
   
 }

Here the object is passed to this method defined in the service from component as:

     modelChanges(event, type, child) {
    this.value = this._sharedService.deepCopy(this.value);
    this.value[type][child] = event;
  }

Checkmarx report says:

Method <div class="jumbotron " style="margin-top: 0.5rem; " [ngStyle]="styleTab"> at line 1 of src/app/pop/popcreate/popc-define/popc-define.component.html gets user input from element $event . This element’s value flows
through the code without being validated, and is eventually used in a loop condition in deepCopy at line 25 of
src/app/shared/shared.service.ts. This constitutes an Unchecked Input for Loop Condition

Any suggestions related to this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等数载,海棠开 2025-01-29 23:23:47

这个结果是假阳性。由于循环显然有限,因此这里没有脆弱性。您可能应该将结果标记为“不可剥削”并继续生活。

This result is a false positive. Since the loop is clearly limited, there's no vulnerability here. You should probably mark the result as "not exploitable" and get on with life.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文