Preventing Cross-Site Scripting Using Output Encoding

Cross-site scripting (XSS) is caused by web application that allows attackers to inject active content. A user agent, such as a web browser, runs the active content on the client side, circumventing the security policies of the client (for example, the same origin policy).

A processing step called output encoding as part of a defense-in-depth approach has to be applied to all untrusted values before it leaves the application and the proper encoding context could be identified. Output encoding transforms all characters of the untrusted value, which may cause the web browser's rendering process to interpret the data as syntax, into an alternative representation. In its rendered form, this alternative representation still represents its original value.