HTML - Cross-site scripting (XSS)

> (World Wide) Web - (W3|WWW) > HyperText markup Language (HTML)

1 - About

A security vulnerability caused by not validating user input.

Web browsers, for security and privacy reasons, prevent documents in different domains from affecting each other; that is, cross-site scripting is disallowed.

When hosting untrusted content (such as user-generated content), web applications can limit that content's authority by restricting its media type. For example, serving user-generated content as image/png is less risky than serving user-generated content as text/html. Of course, many web applications incorporate untrusted content in their HTML documents. If not done carefully, these applications risk leaking their origin's authority to the untrusted content, a vulnerability commonly known as cross-site scripting.


3 - Example

Suppose a page looked at its URL's query string to determine what to display, and the site then redirected the user to that page to display a message, as in:

 <li><a href="message.cgi?say=Hello">Say Hello</a>
 <li><a href="message.cgi?say=Welcome">Say Welcome</a>
 <li><a href="message.cgi?say=Kittens">Say Kittens</a>

If the message was just displayed to the user without escaping, a hostile attacker could then craft a URL that contained a script element:

If the attacker then convinced a victim user to visit this page, a script of the attacker's choosing would run on the page. Such a script could do any number of hostile actions, limited only by what the site offers: if the site is an e-commerce shop, for instance, such a script could cause the user to unknowingly make arbitrarily many unwanted purchases.

This is called a cross-site scripting attack.

4 - Documentation / Reference

web/html/xss.txt ยท Last modified: 2019/03/16 21:36 by gerardnico