Created
May 3, 2011 16:05
-
-
Save dimitrov/953622 to your computer and use it in GitHub Desktop.
A decorator function for preventing cross-site scriting attacks for bottle.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import bottle | |
from bottle import route | |
def websafe(func): | |
""" | |
A decorator function for preventing cross-site scriting attacks | |
""" | |
def wrapper(*args, **kwargs): | |
result = func(*args, **kwargs) | |
result = result.replace(u"&", u"&") | |
result = result.replace(u"<", u"<") | |
result = result.replace(u">", u">") | |
result = result.replace(u"'", u"'") | |
result = result.replace(u'"', u""") | |
return result | |
return wrapper | |
@route('/hello/:name') | |
@websafe | |
def hello(name): | |
return "Hello %s!" % name | |
application = bottle.default_app() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment