summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2017-09-17 22:24:05 +0200
committerTim Graham <timograham@gmail.com>2017-09-20 16:32:24 -0400
commit42847327d1277451ee7a61716f7b9f62f50ecbdc (patch)
tree07baf7b092402eb95bfa348f4267f39bc88a95f5 /django
parent19ea298aaff3ebecb26466f469226953d451e347 (diff)
[1.11.x] Fixed #28488 -- Reallowed error handlers to access CSRF tokens.
Regression in eef95ea96faef0b7dbbe0c8092202b74f68a899b. Backport of c4c128d67c7dc2830631c6859a204c9d259f1fb1 from master
Diffstat (limited to 'django')
-rw-r--r--django/middleware/csrf.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/django/middleware/csrf.py b/django/middleware/csrf.py
index d7359e4912..13134309a5 100644
--- a/django/middleware/csrf.py
+++ b/django/middleware/csrf.py
@@ -201,15 +201,16 @@ class CsrfViewMiddleware(MiddlewareMixin):
# Set the Vary header since content varies with the CSRF cookie.
patch_vary_headers(response, ('Cookie',))
- def process_view(self, request, callback, callback_args, callback_kwargs):
- if getattr(request, 'csrf_processing_done', False):
- return None
-
+ def process_request(self, request):
csrf_token = self._get_token(request)
if csrf_token is not None:
# Use same token next time.
request.META['CSRF_COOKIE'] = csrf_token
+ def process_view(self, request, callback, callback_args, callback_kwargs):
+ if getattr(request, 'csrf_processing_done', False):
+ return None
+
# Wait until request.META["CSRF_COOKIE"] has been manipulated before
# bailing out, so that get_token still works
if getattr(callback, 'csrf_exempt', False):
@@ -285,6 +286,7 @@ class CsrfViewMiddleware(MiddlewareMixin):
reason = REASON_BAD_REFERER % referer.geturl()
return self._reject(request, reason)
+ csrf_token = request.META.get('CSRF_COOKIE')
if csrf_token is None:
# No CSRF cookie. For POST requests, we insist on a CSRF cookie,
# and in this way we can avoid all CSRF attacks, including login