XSS (Cross-site Scripting) allows an attacker to execute a dynamic script (Javascript, VbScript) in the context of the application. This allows several different attack opportunities, mostly hijacking the current session of the user or changing the look of the page by changing the HTML on the fly to steal the user's credentials. This happens because the input entered by a user has been interpreted as HTML/Javascript/VbScript by the browser.
XSS targets the users of the application instead of the server. Although this is a limitation, since it allows attackers to hijack other users' session, an attacker might attack an administrator to gain full control over the application.
Impact
There are many different attacks that can be leveraged through the use of XSS, including:
Hi-jacking users' active session
Changing the look of the page within the victims browser.
Mounting a successful phishing attack.
Intercept data and perform man-in-the-middle attacks.
Remedy
The issue occurs because the browser interprets the input as active HTML, Javascript or VbScript. To avoid this, all input and output from the application should be filtered. Output should be filtered according to the output format and location. Typically the output location is HTML. Where the output is HTML ensure that all active content is removed prior to its presentation to the server.
Prior to sanitizing user input, ensure you have a pre-defined list of both expected and acceptable characters with which you populate a white-list. This list needs only be defined once and should be used to sanitize and validate all subsequent input.
There are a number of pre-defined, well structured white-list libraries available for many different environments, good examples of these include, OWASP Reform and Microsoft Anti Cross-site Scripting libraries are good examples.
<html><head><META HTTP-EQUIV="Pragma" CONTENT="no-cache"><META HTTP-EQUIV="cache-control" CONTENT="no-cache"><STYLE TYPE="text/css"><!-- BODY {font-size:10pt;} TD {font-size:10pt;} INPUT {font-size:9pt;} SELECT {font-size:9pt;} TEXTAREA {font-size:10pt;} TH {font-size:10pt;} FONT {font-size:10pt;} .small_font {font-size:8pt;} .big_font {font-size:12pt;}--></STYLE><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><script language="JavaScript"><!--// --></script><title>Web Chat Logged you out</title></head><body BACKGROUND="/img/whttxtr2.jpg" BGCOLOR="white" TEXT="black" onload="window.focus()"><LINK REL = "stylesheet" TYPE = "text/css" HREF = "/webchat?cmd_get_js2=dbabble.css"><script language="JavaScript" src="/webchat?cmd_get_js2=dbabble.js"></script><b> Your login has expired.<br>This is probably because you have not connected to the server for too long, but may be because you have logged in and logged out from another location.<br>You must login again.</b><br><script language="JavaScript"><!--var olderror;function myonerror(msg, url, lno) { window.onerror=olderror; nwin=window.open("/webchat?cmd=relogin&tok='"--></style></script><script>netsparker(0x00015F)</script>","mainframe"); if (nwin) { nwin.focus(); } return true;}mwin=window.open("","mainframe");if (mwin) { olderror=window.onerror; window.onerror=myonerror; // Supress error message if vchat window is not showing main-menu mwin.Relogin(); window.onerror=olderror; }// --></script></body></html>