简体   繁体   English

使用 javascript 加载部分视图:HP FORTIFY 可能的 XSS

[英]Partial View loading using javascript : Possible XSS by HP FORTIFY

I have a js function , which Fortify identified as XSS vulnerable as below.我有一个 js 函数,Fortify 将其识别为 XSS 漏洞,如下所示。 Can you suggest any solution for this since the method is intensively used in my app.您能否为此提出任何解决方案,因为该方法在我的应用程序中被大量使用。

I am here trying to call a partialview in ajax and the result html am appending to a specified dom div我在这里尝试在 ajax 中调用部分视图,结果 html 附加到指定的 dom div

My function look like the below我的功能如下所示

      function loadPartialViewToDiv(div, obj, api) {
        try {
                
    

const myUrl = new URL(window.location.origin +  api); // always local URL only 
    
    $.ajax({       
    
    url: myUrl ,
    data: obj,
    cache: false,
    type: "POST",
    dataType: "html",
    
    success: function (data, textStatus, XMLHttpRequest) {        
    
    if (data != undefined && data != null) {        
    
    $('#' + div).html(data);        
    
    }    
    
    
    }
    
    
    });
    
    
    } catch (e) {
    
    
    ('#' + div).html('Error');
    
    
    }
    
    }

The dynamic DOM element id was the issue ($('#' + div).html(data); ), we fixed it using two methods动态 DOM 元素 id 是问题 ($('#' + div).html(data); ),我们使用两种方法修复它

  1. giving a static id.给出一个静态ID。 $('#abcd').html(data); $('#abcd').html(数据);
    OR或者
  2. change as $('#' + div).text($(data));更改为 $('#' + div).text($(data));

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

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