Directly writing an HTTP request parameter back to a web page allows for a cross-site scripting vulnerability. The data is displayed in a user's web browser as belonging to one site, but it is provided by some other site that the user browses to. In effect, such an attack allows one web site to insert content in the other one.
For web servers implemented with the Common Gateway Interface
(CGI), HTTP parameters are supplied via the
To guard against cross-site scripting, consider escaping special characters before writing the HTTP parameter back to the page.
In the following example, the
bad_server writes a
parameter directly back to the HTML page that the user will
good_server first escapes any HTML special
characters before writing to the HTML page.