Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

How to avoid Reflected_xss_all_clients vulnerabilities in Winforms c#

Currently, I am working for a Winforms project. When I am scanning my Winforms application through CheckMarx then I am getting multiple Reflected_xss_all_clients vulnerabilities. I know there is no scripting in Winforms. XSS is a web threat but may be there would be some way to remediate these threats during scanning.

Here is the error code section 1:

private void UpdatePreviewValue()
  {
     try
     {
        // Set the preview value
        if (txtFieldValue.Text != string.Empty)
        {
           // Show the preview value
           lblPreview.Text = "(" + txtFieldValue.Text + ")";
        }
        else
        {
           // Show that there is no field value
           lblPreview.Text = Properties.Resources.Std_Txt_Fld_NoFieldValue;
        }
     }
     catch (Exception ex)
     {
        frmErrorHandler.ShowDataError(Properties.ErrorStrings.ErrorTitle_SrcFldCtlInteger_UpdatePreviewValue, DataErrorImageConstants.Exclamation, ex);
     }
  }

in above code section, the line lblPreview.Text = "(" + txtFieldValue.Text + ")";is throwing Reflected_xss_all_clients vulnerabilities.

Here is the error code section 2:

      /// <summary>
      /// Method to copy an existing node for moving inside a grid
      /// </summary>
      /// <param name="rowToCopy">GridRow to copy</param>
      /// <returns>GridRow</returns>
      private GridRow CopyGridRow(GridRow rowToCopy)
      {
         GridRow newRow = gridCategories.NewRow();
         newRow.Tag = rowToCopy.Tag;
         newRow.Cells[0].Text = rowToCopy.Cells[0].Text;
         newRow.Cells[0].Image = rowToCopy.Cells[0].Image;
         newRow.Cells[1].Text = rowToCopy.Cells[1].Text;

         if (rowToCopy.HasRows)
         {
            foreach (GridRow nestedRow in rowToCopy.NestedRows)
            {
               newRow.NestedRows.Add(CopyGridRow(nestedRow));
            }
         }

         return newRow;
      }

in above code section, the line newRow.Cells[0].Text = rowToCopy.Cells[0].Text; and newRow.Cells[1].Text = rowToCopy.Cells[1].Text;are throwing Reflected_xss_all_clientsvulnerabilities.

Here is the error code section 3:

  /// <summary>
  /// Method used to add a new discrete value to the listview
  /// </summary>
  private void AddDiscreteValue()
  {
     // check we have an entry to add
     if (txtDiscreteValue.Text != "")
     {
        SetDiscreteValue(txtDiscreteValue.Text, true, null, false);
     }
  }

In above code section, the line SetDiscreteValue(txtDiscreteValue.Text, true, null, false); is throwing Reflected_xss_all_clients vulnerabilities for txtDiscreteValue.Text

Please suggest any way to remediate it, if possible.

question from:https://stackoverflow.com/questions/65920643/how-to-avoid-reflected-xss-all-clients-vulnerabilities-in-winforms-c-sharp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Checkmarx will follow the string from input to use. Sometimes it identifies a variable which is not fillterd transited to the frontend as a XSS.

As for me, I always ignore the XSS reported from Checkmarx. Maybe you can use a fillter function before use the string variable. Like this

     txtFieldValue.Text=cleanXSS(txtFieldValue.Text) 

As for cleanXSS(), you can find many examples after google.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...