{
"info": {
"author": "Vladimir Iakovlev",
"author_email": "nvbn.rm@gmail.com",
"bugtrack_url": null,
"classifiers": [
"Development Status :: 4 - Beta",
"Environment :: Web Environment",
"Environment :: Web Environment :: Mozilla",
"Framework :: Django",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Topic :: Software Development :: Libraries :: Python Modules"
],
"description": "What is this?\n-------------\n\n``django-session-csrf`` is an alternative implementation of Django's CSRF\nprotection that does not use cookies. Instead, it maintains the CSRF token on\nthe server using Django's session backend. The csrf token must still be\nincluded in all POST requests (either with `csrfmiddlewaretoken` in the form or\nwith the `X-CSRFTOKEN` header).\n\n\nInstallation\n------------\n\nFrom PyPI::\n\n pip install django-session-csrf-per-view\n\nFrom github::\n\n git clone git://github.com/mozilla/django-session-csrf.git\n\nReplace ``django.core.context_processors.csrf`` with\n``session_csrf.context_processor`` in your ``TEMPLATE_CONTEXT_PROCESSORS``::\n\n TEMPLATE_CONTEXT_PROCESSORS = (\n ...\n 'session_csrf.context_processor',\n ...\n )\n\nReplace ``django.middleware.csrf.CsrfViewMiddleware`` with\n``session_csrf.CsrfMiddleware`` in your ``MIDDLEWARE_CLASSES``\nand make sure it is listed after the AuthenticationMiddleware::\n\n MIDDLEWARE_CLASSES = (\n ...\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n ...\n 'session_csrf.CsrfMiddleware',\n ...\n )\n\nThen we have to monkeypatch Django to fix the ``@csrf_protect`` decorator::\n\n import session_csrf\n session_csrf.monkeypatch()\n\nMake sure that's in something like your root ``urls.py`` so the patch gets\napplied before your views are imported.\n\n\nDifferences from Django\n-----------------------\n\n``django-session-csrf`` does not assign CSRF tokens to anonymous users because\nwe don't want to support a session for every anonymous user. Instead, views\nthat need anonymous forms can be decorated with ``@anonymous_csrf``::\n\n from session_csrf import anonymous_csrf\n\n @anonymous_csrf\n def login(request):\n ...\n\n``anonymous_csrf`` uses the cache to give anonymous users a lightweight\nsession. It sends a cookie to uniquely identify the user and stores the CSRF\ntoken in the cache. It can be controlled through these settings:\n\n ``ANON_COOKIE``\n the name used for the anonymous user's cookie\n\n Default: ``anoncsrf``\n\n ``ANON_TIMEOUT``\n the cache timeout (in seconds) to use for the anonymous CSRF tokens\n\n Default: ``60 * 60 * 2 # 2 hours``\n\nNote that by default Django uses local-memory caching, which will not\nwork with anonymous CSRF if there is more than one web server thread.\nTo use anonymous CSRF, you must configure a cache that's shared\nbetween web server instances, such as Memcached. See the `Django cache\ndocumentation