Skip to content

Commit

Permalink
Provide a more useful message when the csrf check fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Oct 26, 2015
1 parent cd5995b commit ac76618
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bodhi/validators.py
Expand Up @@ -34,13 +34,18 @@
import bodhi.schemas


csrf_error_message = """CSRF tokens do not match. This happens if you have
the page open for a long time. Please reload the page and try to submit your
data again. Make sure to save your input somewhere before reloading.
""".replace('\n', ' ')

# This one is a colander validator which is different from the cornice
# validators defined elsehwere.
def validate_csrf_token(node, value):
request = pyramid.threadlocal.get_current_request()
expected = request.session.get_csrf_token()
if value != expected:
raise colander.Invalid(node, 'CSRF tokens do not match')
raise colander.Invalid(node, csrf_error_message)


def cache_nvrs(request, build):
Expand Down

0 comments on commit ac76618

Please sign in to comment.