Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python library for XSS filtering? [closed]

Tags:

python

xss

Is there a good, actively maintained python library available for filtering malicious input such as XSS?

like image 412
MathOldTimer Avatar asked May 23 '09 11:05

MathOldTimer


People also ask

How can XSS be prevented?

To protect most from XSS vulnerabilities, follow three practices: Escape user input. Escaping means to convert the key characters in the data that a web page receives to prevent the data from being interpreted in any malicious way. It doesn't allow the special characters to be rendered.

What is XSS filter?

Cross-site scripting (XSS) is a computer security vulnerability that allows malicious attackers to inject client-side script into web pages viewed by other users. You can use the Cross-site Scripting Filter setting to check all HTTP GET requests sent to IBM® OpenPages® with Watson™.

What is HTML escaping for XSS?

Escaping is the primary means to avoid cross-site scripting attacks. When escaping, you are effectively telling the web browser that the data you are sending should be treated as data and should not be interpreted in any other way.

What is filter evasion?

Cross-Site Scripting (XSS): Filter Evasion and Sideloading I'll show you some techniques hackers use to get past common remediation efforts. First is filter evasion, which uses different types of tags to insert malicious code when filters are in place to prevent scripts from running.


2 Answers

If you are using a web framework and a template engine like Jinja2 there is a chance that the template engine or the framework has something built in just for that.

There is something in the cgi module that can help you:

cgi.escape('malicious code here'), see: http://docs.python.org/library/cgi.html#cgi.escape

Also Jinja2 provides escaping:

from jinja2 import utils
str(utils.escape('malicious code here'))
like image 174
Paul Avatar answered Sep 22 '22 22:09

Paul


You can easily code XSS-defense in Python, see for example http://code.activestate.com/recipes/496942/ for an instructive and usable piece of code.

like image 39
Alex Martelli Avatar answered Sep 26 '22 22:09

Alex Martelli