Skip to content

Commit

Permalink
CSRF: Avoid creating a session on error page
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Oct 12, 2020
1 parent 13eb13a commit e773fe9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion weblate/trans/views/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def denied(request, exception=None):


def csrf_failure(request, reason=""):
return render(
response = render(
request,
"403_csrf.html",
{
Expand All @@ -58,6 +58,12 @@ def csrf_failure(request, reason=""):
},
status=403,
)
# Avoid setting CSRF cookie on CSRF failure page, otherwise we end up creating
# new session even when user might already have one (because browser did not
# send the cookies with the CSRF request and Django doesn't see the session
# cookie).
response.csrf_cookie_set = True
return response


def server_error(request):
Expand Down

0 comments on commit e773fe9

Please sign in to comment.