XSS derives from the possibility of injecting malicious data into the form of JavaScript code
using an input channel such as querystring parameters sent via Get HTTP method or fields of a data
entry form sent via Post.
The malicious JavaScript code not validated and therefore not blocked on the server side is
executed against a response going on the user's client.
So XSS is a type of attack that does no harm directly to the server, but to the user.
XSS can be used by malicious attackers, for example, to steal session cookies from legitimate users
and send the relative session ID to an attacker, or to redirect users of a site to login pages of
a fake clone site in order to steal authentication credentials.
The DOM-based type of XSS can occure when JavaScript code in a page does not suitably validate data,
that it can take as input.
Here is an example of a JavaScript code in a Web page that is vulnerable to DOM-based XSS
The problem stems from the fact that the document.write function does not validate its argument before
using it, allowing the injection of malicious JavaScript.
The non-persistent type of XSS is typical of applications in which an input to the application
sent via request is returned with a response by reloading the same page with a postback or on a different
page.
In the persistent tipology, the non validated malicious JavaScript is even saved in a database and
then retrieved through queries and sent on clients.
For the remedy to XSS is important before validation to normalize or canonicalize the data.
The table shows the various possibilities of character transcoding that a malicious attacker could exploit
to bypass the validation without canonicalization of the data
Among the possible remedies for XSS is the use of regular expression to search for the malicious
pattern consisting of the tag script /script used to enclose the malicious JavaScript code that
an attacker could inject.
Here is an example of C sharp code that implements a remedy for XSS
And here an example of Java code that implements a remedy for XSS with regular expression.
Some links for further information on the topic of cross site scripting.
Thank you very much for your kind attention.