Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you do a GET request before POSTing to the password reset view, you get the CSRF token in a cookie, which you can then send in your POST request. </p> <p>If you insist on exempting the view: I think the problem lies in the way the CSRF protection is applied to the <code>password_reset</code> view. It is explicitly decorated by <code>csrf_protect</code>. </p> <p>To have a closer look at the problem, lets assume <code>original_password_reset_view</code> is <code>password_reset</code> without the <code>csrf_protect</code>. Basically, you are doing this: </p> <pre><code>csrf_exempt(csrf_protect(original_password_reset_view)) # ^^ your code # ^^ the decorator in django.contrib.auth.views </code></pre> <p>And adding in the effect of the <code>CsrfViewMiddleware</code>, we get the equivalent of</p> <pre><code>csrf_protect(csrf_exempt(csrf_protect(original_password_reset_view))) </code></pre> <p><code>csrf_protect</code> is just a <a href="https://github.com/django/django/blob/master/django/views/decorators/csrf.py#L5" rel="noreferrer">middleware-turned-decorator</a> from <code>CsrfViewMiddleware</code>. <code>csrf_exempt</code> on the other hand <a href="https://github.com/django/django/blob/master/django/views/decorators/csrf.py#L58" rel="noreferrer">simply sets <code>csrf_exempt=True</code></a> on its argument. So the middleware, represented by the outer <code>csrf_protect</code>, sees the <code>csrf_exempt=True</code> value on the view and disables its CSRF projection. It negates the <strong>outer</strong> <code>csrf_protect</code>. So we have:</p> <pre><code>csrf_protect(original_password_reset_view) </code></pre> <p>The view is still protected. Basically, there is no sane way around. (An insane way: write a middleware that sets <code>request.csrf_processing_done = True</code> for that specific URL. Don't do that...)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload