2015-11-04 20 views
0

這是我的第一個帖子在這裏:跨站腳本攻擊:保護無效的RowDataBound(對象發件人,GridViewRowEventArgs E)

得到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; 
    } 
} 
+0

歡迎來到StackOverflow!您應該確保使用您正在使用的語言標記您的問題。另外,很高興知道您使用的掃描儀是什麼。 – Gray

+0

當然。使用C#和來自WH Sentinel –

回答

2

跨站點腳本(XSS)是一個注入漏洞。此漏洞允許惡意用戶通過未經驗證的輸入插入自己的代碼(Javascript,HTML等)。更多關於XSS可以在這裏找到:OWASP Guide to XSS

掃描儀可能引發一個警報基於這一行:

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

有了這行代碼,你添加onclick屬性的HTML元素,然後將OpenTable()的呼叫添加爲str作爲參數的一部分傳遞。 str的值來自,這可能是惡意輸入。由於e在使用前未經過消毒,因此惡意用戶可以使用e參數在onclick屬性值中插入惡意代碼。

第二個問題是信息泄漏。安全最佳做法是清理錯誤消息,爲潛在的攻擊者提供儘可能少的信息。錯誤消息可以揭示所用技術的細節,或系統的工作方式。這些信息對於有針對性的攻擊很有用。

問題很可能從以下行的代碼來:

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

當您打印ex.Message,你可能暴露,可以在攻擊中使用錯誤的詳細信息。更好的錯誤信息會表明發生了問題,但不會顯示具體信息。請參閱OWASP's guide to Error Handling, Auditing, and Logging以獲得指導。

+0

明確解釋。謝謝!!! –

相關問題