Skip to content

Commit

Permalink
[1.5.x] Fixed bug causing CSRF token not to rotate on login.
Browse files Browse the repository at this point in the history
Thanks Gavin McQuillan for the report.

Backport of ac4fec5 from master
  • Loading branch information
timgraham committed Oct 18, 2013
1 parent 312ca5e commit 0fb2897
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 0 additions & 1 deletion django/contrib/auth/tests/views.py
Expand Up @@ -392,7 +392,6 @@ def test_login_csrf_rotate(self, password='password'):
CsrfViewMiddleware().process_view(req, login_view, (), {}) CsrfViewMiddleware().process_view(req, login_view, (), {})
req.META["SERVER_NAME"] = "testserver" # Required to have redirect work in login view req.META["SERVER_NAME"] = "testserver" # Required to have redirect work in login view
req.META["SERVER_PORT"] = 80 req.META["SERVER_PORT"] = 80
req.META["CSRF_COOKIE_USED"] = True
resp = login_view(req) resp = login_view(req)
resp2 = CsrfViewMiddleware().process_response(req, resp) resp2 = CsrfViewMiddleware().process_response(req, resp)
csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, None) csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, None)
Expand Down
5 changes: 4 additions & 1 deletion django/middleware/csrf.py
Expand Up @@ -58,7 +58,10 @@ def rotate_token(request):
Changes the CSRF token in use for a request - should be done on login Changes the CSRF token in use for a request - should be done on login
for security purposes. for security purposes.
""" """
request.META["CSRF_COOKIE"] = _get_new_csrf_key() request.META.update({
"CSRF_COOKIE_USED": True,
"CSRF_COOKIE": _get_new_csrf_key(),
})




def _sanitize_token(token): def _sanitize_token(token):
Expand Down

0 comments on commit 0fb2897

Please sign in to comment.