【问题标题】:Cross Site Scripting attack: protected void RowDataBound(object sender, GridViewRowEventArgs e)跨站脚本攻击:protected void RowDataBound(object sender, GridViewRowEventArgs e)
【发布时间】:2015-11-04 16:59:42
【问题描述】:

这是我在这里的第一篇文章:

扫描报告中有 2 个问题。请帮我解决这个问题:

  1. Xss 攻击:protected void gvMSMQ_RowDataBound(object sender, GridViewRowEventArgs e)**

  2. 信息泄露: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;
    }
}

【问题讨论】:

  • 欢迎来到 StackOverflow!您应该确保用您使用的语言标记您的问题。另外,很高兴知道您使用的是什么扫描仪。
  • 当然。使用 C# 和 WH Sentinel

标签: c# security xss


【解决方案1】:

跨站脚本 (XSS) 是一种注入漏洞。此漏洞允许恶意用户通过未经验证的输入插入自己的代码(Javascript、HTML 等)。更多关于 XSS 的信息可以在这里找到:OWASP Guide to XSS

扫描仪可能会根据这一行发出警报:

e.Row.Cells[0].Attributes.Add("OnClick", "OpenTable('" + str + "','" + img.ClientID + "')");

通过这行代码,您将一个onclick 属性添加到一个HTML 元素,然后添加对OpenTable() 的调用,其中str 作为参数的一部分传递。 str的值来自protected void gvMSMQ_RowDataBound(object sender, GridViewRowEventArgs e)中的e,可能是恶意输入。由于e 在使用前没有经过清理,恶意用户可以使用e 参数在onclick 属性值中插入恶意代码。

第二个问题是信息泄露。安全最佳实践是清理错误消息,为潜在的攻击者提供尽可能少的信息。错误消息可以揭示所用技术或系统工作方式的详细信息。此信息可能对有针对性的攻击很有用。

问题可能来自以下代码行:

lblError.Text = "RowBound - " + errorMessage + "......" + ex.Message;

当您打印ex.Message 时,您可能会暴露可能用于攻击的错误详细信息。更好的错误消息将表明发生了问题,但不会透露细节。请参阅OWASP's guide to Error Handling, Auditing, and Logging 获取指导。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-12
    • 1970-01-01
    • 2011-05-19
    • 2015-04-01
    • 2011-09-07
    • 2011-10-24
    • 1970-01-01
    • 2018-10-27
    相关资源
    最近更新 更多