0

Hi I used HPE Fortify to scan my application and it show a cross site scripting vulnerability on my codes.

How do i prevent cross site scripting based on the codes below?

LabelErrorResult.Text += "<li>Duplicate selection for sequence " + ddl.SelectedValue + "</li>";
Marcus
  • 11
  • 1
  • 1
  • 4

1 Answers1

0

Use HtmlEncode and then decode it like

String unsafevar = HttpContext.Current.Server.HtmlEncode("ddl.SelectedValue");

LabelErrorResult.Text += "<li>Duplicate selection for sequence " + HttpContext.Current.Server.HtmlDecode(usafevar); + "</li>";

For more you can visit msdn https://msdn.microsoft.com/en-us/library/w3te6wfz(v=vs.110).aspx

Saad Suri
  • 1,352
  • 1
  • 14
  • 26