2017-04-21 64 views
0

正在处理的代码部分容易受到存储的XSS的影响。以下是代码。如何在Asp.net中克服存储的跨站点脚本漏洞c#

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  OnRowCancelingEdit="GridView1_RowCancelingEdit"  
      OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_OnRowDeleting" OnPageIndexChanging="GridView1_PageIndexChanging" Width ="1000px" class="grid"> 


     <Columns> 

      <asp:TemplateField HeaderText="User Name"> 
       <ItemTemplate> 
        <asp:Label ID="lbl_Name" runat="server" Text='<%#Eval("Uname") %>'></asp:Label> 
       </ItemTemplate> 
       <EditItemTemplate> 
        <asp:TextBox ID="txt_Name" runat="server" Text='<%#Eval("Uname") %>'></asp:TextBox> //this is the line vulnerable to XSS 
       </EditItemTemplate> 
      </asp:TemplateField>  </columns> 
</asp:GridView> 

代码背后

DataTable dt = new DataTable(); 
     try 
     { 
      SqlConnection con = new SqlConnection(conn); 
      con.Open(); 
      SqlDataAdapter adapt = new SqlDataAdapter("Select Uid,Uname,Utype,Uemail,ClientName,ProjectName,Ulog from usrtable where ClientName='" + clientname + "' and Utype='Admin' or ClientName='" + clientname + "'and Utype='Normal'", con); 
      **adapt.Fill(dt);**//this is again vulnerable 
      con.Close(); 
     } 

if (dt.Rows.Count > 0) 
       { 
        GridView1.DataSource = dt; 
        GridView1.DataBind(); 
       } 

我不熟悉XSS。我经历了很多文件。它要求我们对数据进行编码。但在我的情况下,我该如何继续。我在GV中有许多标签和文本框作为项目模板。使用它来更新表格行。

+0

需要代码隐藏。 – Webbanditten

+0

我编辑过。请检查源代码 – Aswini

回答