# HG changeset patch
# User Brodie Rao <brodie@bitheap.org>
# Date 1297297039 28800
# Branch releases/1.2.X
# Node ID 62ee79e7fcc8f220d8d34c0066083bbbf425f122
# Parent 61c0665bc6c15ed9db42a7ca5da2678efa551934
Apply CSRF checks to PUT and DELETE in addition to POST
diff --git a/django/middleware/csrf.py b/django/middleware/csrf.py
|
a
|
b
|
class CsrfViewMiddleware(object):
|
| 123 | 123 | if getattr(callback, 'csrf_exempt', False): |
| 124 | 124 | return None |
| 125 | 125 | |
| 126 | | if request.method == 'POST': |
| | 126 | if request.method in ('POST', 'PUT', 'DELETE'): |
| 127 | 127 | if getattr(request, '_dont_enforce_csrf_checks', False): |
| 128 | 128 | # Mechanism to turn off CSRF checks for test suite. It comes after |
| 129 | 129 | # the creation of CSRF cookies, so that everything else continues to |
| … |
… |
class CsrfViewMiddleware(object):
|
| 160 | 160 | else: |
| 161 | 161 | csrf_token = request.META["CSRF_COOKIE"] |
| 162 | 162 | |
| 163 | | # check incoming token |
| | 163 | # Check the incoming token in the request's POST data. For |
| | 164 | # PUT and DELETE requests, we only support the X-CSRFToken |
| | 165 | # header. |
| 164 | 166 | request_csrf_token = request.POST.get('csrfmiddlewaretoken', "") |
| 165 | 167 | if request_csrf_token == "": |
| 166 | 168 | # Fall back to X-CSRFToken, to make things easier for AJAX |