Django: Generate new CSRF token per request/form

后端 未结 3 1589
眼角桃花
眼角桃花 2021-02-02 17:17

Can we change CSRF token per-form request or even per-request instead of same token for one active session?

3条回答
  •  日久生厌
    2021-02-02 17:57

    In the csrf middleware they do something like this, which overwrites the cookie set:

    request.META["CSRF_COOKIE"] = _get_new_csrf_key()
    

    You can import _get_new_csrf_key() via from django.middleware.csrf import _get_new_csrf_key(). Since is kind of a private method I would advise against some hacks like this though.

提交回复
热议问题