Skip to content

Instantly share code, notes, and snippets.

@kramer
Created April 22, 2013 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kramer/5438403 to your computer and use it in GitHub Desktop.
Save kramer/5438403 to your computer and use it in GitHub Desktop.
Bottlepy plugin for csrf token checking.
def require_csrf(callback):
def wrapper(*args, **kwargs):
session = request.environ.get('beaker.session')
if request.method == 'POST':
csrf = request.form.get('csrf')
if not csrf or csrf != session.get('csrf'):
abort(400)
session['csrf'] = generate_csrf_token()
body = callback(*args, **kwargs)
return body
return wrapper
app = Bottle()
app.install(require_csrf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment