Don't throw a 500 error when verifying csrf token on a session without a cookie

This commit is contained in:
Michael Hall 2018-07-07 16:54:52 -04:00
parent 36ba966da7
commit 6ca8c22569

View file

@ -28,7 +28,7 @@ def verify_csrf(token_key='csrftoken'):
def wrap_view(view_func):
def check_csrf_token(request, *args, **kwargs):
csrf_token = _sanitize_token(request.GET.get(token_key, ''))
match = _compare_salted_tokens(csrf_token, request.COOKIES[settings.CSRF_COOKIE_NAME])
match = _compare_salted_tokens(csrf_token, request.COOKIES.get(settings.CSRF_COOKIE_NAME, ''))
if not match:
raise PermissionDenied
else: