Is there a good, actively maintained python library available for filtering malicious input such as XSS?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
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.
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.escapeAlso Jinja2 provides escaping:
The Strip-o-Gram library looks quite nice. I haven't checked it out properly, but it looks like it does things well (i.e. can whitelist HTML tags you specify, as well as HTML-escaping anything nasty).
Here's the example usage snippet, quoted from that page:
Hope that helps.