C# 跨站点脚本攻击:受保护的void RowDataBound(对象发送方,GridViewRowEventArgs e)
这是我在这里的第一篇帖子: 从扫描报告中获得2个问题。请帮助我缓解此问题:C# 跨站点脚本攻击:受保护的void RowDataBound(对象发送方,GridViewRowEventArgs e),c#,security,xss,C#,Security,Xss,这是我在这里的第一篇帖子: 从扫描报告中获得2个问题。请帮助我缓解此问题: Xss攻击:protectedvoid gvmmq_RowDataBound(对象发送方,GridViewRowEventArgs e)** 信息泄漏:lblError.Text=“RowBound-”+errorMessage+“…”+ex.Message 谢谢你的帮助 protected void gvMSMQ_RowDataBound(object sender, GridViewRowEventArgs e) {
protectedvoid gvmmq_RowDataBound(对象发送方,GridViewRowEventArgs e)**
lblError.Text=“RowBound-”+errorMessage+“…”+ex.Message
protected void gvMSMQ_RowDataBound(object sender, GridViewRowEventArgs e)
{
string Path = string.Empty;
string errorMessage = "";
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Image img = (Image)e.Row.Cells[0].FindControl("img1");
Literal ltrl = (Literal)e.Row.FindControl("lit1");
ltrl.Text = ltrl.Text.Replace("trCollapseGrid", "trCollapseGrid" + e.Row.RowIndex.ToString());
string str = "trCollapseGrid" + e.Row.RowIndex.ToString();
e.Row.Cells[0].Attributes.Add("OnClick", "OpenTable('" + str + "','" + img.ClientID + "')");
e.Row.Cells[0].RowSpan = 1;
errorMessage = "Two";
//Path = lstMSMQ[e.Row.RowIndex].Path;
UCEnvironmentViewerQueueGrid ucQueueGrids = (UCEnvironmentViewerQueueGrid)e.Row.FindControl("ucQueueGrids");
Classes.MSMQprofile msmqObj = new Classes.MSMQprofile();
var rowItems = e.Row.DataItem;
msmqObj = rowItems as Classes.MSMQprofile;
ucQueueGrids.lstNormalMSMQ = msmqObj.NormalQueueList;
//ucQueueGrids.lstJournalQueue = msmqObj.JournalQueueList;
ucQueueGrids.BindControl();
}
}
catch (Exception ex)
{
//error on this line!
lblError.Text = "RowBound - " + errorMessage + "......" + ex.Message;
}
}
跨站点脚本(XSS)是一个注入漏洞。此漏洞允许恶意用户通过未经验证的输入插入自己的代码(Javascript、HTML等)。有关XSS的更多信息,请参见:
扫描程序可能基于以下行引发警报:
e.Row.Cells[0].Attributes.Add("OnClick", "OpenTable('" + str + "','" + img.ClientID + "')");
使用这行代码,您将向HTML元素添加一个onclick
属性,然后添加对OpenTable()
的调用,其中str
作为参数的一部分传递。str
的值来自protected void gvsmq_RowDataBound(对象发送方,GridViewRowEventArgs e)
中的e
,这可能是恶意输入。由于e
在使用前未被清除,恶意用户可以使用e
参数在onclick
属性值中插入恶意代码
第二个问题是信息泄漏。安全最佳实践是清除错误消息,尽可能少地向潜在攻击者提供信息。错误消息可以显示所使用技术的详细信息,或者系统如何工作。这些信息在有针对性的攻击中可能很有用
问题可能来自以下代码行:
lblError.Text=“行绑定-”+errorMessage+“…”+ex.Message代码>
打印ex.Message
时,可能会暴露可能用于攻击的错误详细信息。更好的错误消息将指示出现了问题,但不会透露细节。请参阅以获取指导。欢迎来到StackOverflow!你应该确保用你正在使用的语言标记你的问题。另外,如果你能知道你用的是什么扫描仪,那就太好了。使用C#和WH Sentinel