加载中...

Python

  1. Home
  2. Computing & Technology
  3. Python

Programming Secure Web Applications in Python

By Al Lukaszewski, About.com

5 of 10

Cross Site Scripting (XSS)

A cross-site scripting exploit works like this:

  1. An attacker identifies a web application that echoes user-provided data in its URLs (e.g., a search string).
  2. The attacker then forms a URL that includes HTML (not necessarily with a header) and some in-line script like Javascript or PHP.
  3. The attacker then, by hook or by crook, gets a victim to click on the link. This can be on a web page or an email -- anything that is HTML-based.
  4. When the victim clicks the link, the victim's browser send a GET request with the malformed HTML-Script combination to the vulnerable application.
  5. When the web application echoes the user data, the victim's browser reads the URL, along with the HTML, and executes the script contained therein. The scripting can be used for just about anything - user cookies, modifying web links, pilfering passwords, etc.

All of this is possible because the web application receives user data, does not check the input, and echoes it back in a URL. Naturally, this feeds back into the first issue, unvalidated input. If, however, the input field must be able to handle code, be sure to replace any instances of metacharacters with their escaped version and handle the string with Python's verbatim mode as much as reasonably possible.

5 of 10

Explore Python

More from About.com

Python

  1. Home
  2. Computing & Technology
  3. Python

©2009 About.com, a part of The New York Times Company.

All rights reserved.