Skip to main content

Middleware which sets SameSite flag for session and csrf cookies in legacy versions of Django. Forked from https://pypi.org/project/django-cookies-samesite/

Project description

https://badge.fury.io/py/django-cookies-samesite.svg https://travis-ci.org/jotes/django-cookies-samesite.svg?branch=master https://codecov.io/gh/jotes/django-cookies-samesite/branch/master/graph/badge.svg

Django 2.1.x introduces support of SameSite flag for session and csrf cookie.

Unfortunately, this functionality will not be ported to older versions of Django e.g. 1.11.x.

This repository contains a middleware which automatically sets SameSite attribute for session and csrf cookies in legacy versions of Django.

Quickstart

Install django-cookies-samesite:

pip install django-cookies-samesite

Add the middleware to the top of MIDDLEWARE_CLASSES:

MIDDLEWARE_CLASSES = (
    'django_cookies_samesite.middleware.CookiesSameSite',
    ...
)

Set your preferred SameSite policy in settings.py:

SESSION_COOKIE_SAMESITE = 'Lax'

This can be ‘Lax’, ‘Strict’, or None to disable the flag.

Also, you can set this flag in your custom cookies:

SESSION_COOKIE_SAMESITE_KEYS = {'my-custom-cookies'}

After that you should be able to see SameSite flag set for session and csrf cookies: ![screenshot]()

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in rendering this package:

History

0.1.0 (2018-05-16)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-cookies-samesite-fork-0.2.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

django_cookies_samesite_fork-0.2.1-py2.py3-none-any.whl (5.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-cookies-samesite-fork-0.2.1.tar.gz.

File metadata

  • Download URL: django-cookies-samesite-fork-0.2.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.7.4

File hashes

Hashes for django-cookies-samesite-fork-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7d064b2fd1e0b5aa3037a35c7907c9bccc5384f8899dc02412b947820e0acb59
MD5 053c1faded35b0dc9fa3b5cf9adede70
BLAKE2b-256 bbdc2c72529dbca6610d11b7a5146d0b49c26edb347b9864f1e81d7999b4d6d3

See more details on using hashes here.

File details

Details for the file django_cookies_samesite_fork-0.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: django_cookies_samesite_fork-0.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.7.4

File hashes

Hashes for django_cookies_samesite_fork-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 053540e7dad735423afb6307e7c23287072b517eb848a520251d7bfd1aace150
MD5 29f64cd201fc814a6da5b70f95f3c22f
BLAKE2b-256 be86fec6096e064ca24a7d17f3ae71dd6e280fdda8e512e751d7ef9f77ce294e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page