Hi all,
Modified Code in django.middleware.csrf.py from CsrfViewMiddleware:
def process_view(self, request, callback, callback_args, callback_kwargs):
if getattr(request, 'csrf_processing_done', False):
return None
csrf_token = request.META['CSRF_COOKIE'] #CSRF_COOKIE is being rotating by our custom middleware
if csrf_token == None:
# Generate token and store it in the request, so it's
# available to the view.
request.META["CSRF_COOKIE"] = _get_new_csrf_key()
Django's Standard Code:
def process_view(self, request, callback, callback_args, callback_kwargs):
if getattr(request, 'csrf_processing_done', False):
return None
try:
csrf_token = _sanitize_token(
request.COOKIES[settings.CSRF_COOKIE_NAME])
# Use same token next time
request.META['CSRF_COOKIE'] = csrf_token
except KeyError:
csrf_token = None
# Generate token and store it in the request, so it's
# available to the view.
request.META["CSRF_COOKIE"] = _get_new_csrf_key()
I think there are a few more things that should be done here like a _sanitize_token call but this is the basic idea. The problem is I can't just modify the Django code because I don't understand the full set of possible side effects.
Does anyone know:
1. The history of why the Django developers have set up the code in this fashion.
2. Any side effects that should be expected from making a change like the above modified Django code.
3. A way to do this without modifying the Django base code.
Also, it seems like a version of CsrfViewMiddleware that is conducive to rotating on each request would be helpful as part of Django's base code. Is a change like this worth submitting a pull request to the Django repository?
Thanks for any help in advance,
ibrw100000
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4c3234d2-7c2a-4a42-b2b5-fbc4b38567d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment