Skip to main content

Django Cerber

CI Status Documentation Status Test coverage percentage

uv Ruff prek

PyPI Version Supported Python versions License


Documentation: https://django-cerber.readthedocs.io

Source Code: https://github.com/iddqd1/django-cerber


Login anomaly detection for Django: country changes, Tor and session revocation.

Installation

Install this via pip (or your favourite package manager):

pip install django-cerber

Add the app to your INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    "django_cerber",
]

MIDDLEWARE = [
    # ...
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    # ...
    "django_cerber.middleware.CerberMiddleware",
]

Then run python manage.py migrate. For the GeoIP country source install the extra: pip install "django-cerber[geoip]".

Configuration

All settings are optional. Add them to your Django settings module to override the defaults, for example:

from datetime import timedelta

CERBER_WINDOW = timedelta(minutes=30)
CERBER_COUNTRY_SOURCES = ("cloudflare", "geoip")
CERBER_GEOIP_DATABASE = "/var/lib/geoip/GeoLite2-Country.mmdb"
CERBER_BLOCKED_COUNTRIES = ("KP",)
Setting Default Description
CERBER_ENABLED True Whether login checks are performed at all.
CERBER_WINDOW timedelta(hours=1) A country change faster than this is treated as impossible travel.
CERBER_COUNTRY_SOURCES ('cloudflare',) Where the client's country comes from, tried in order until one knows it.

"cloudflare" reads the CF-IPCountry header, "geoip" looks the client IP up in CERBER_GEOIP_DATABASE. E.g. ("cloudflare", "geoip") uses GeoIP as a fallback when the request didn't come through Cloudflare.
CERBER_GEOIP_DATABASE None Path to a MaxMind GeoIP2/GeoLite2 (or DB-IP) Country or City .mmdb file.

Required by the "geoip" source; needs pip install django-cerber[geoip].
CERBER_PROXY_IP_HEADER None Header set by your reverse proxy with the address it received the request from, e.g. "X-Forwarded-For" or "X-Real-IP". None = use REMOTE_ADDR.

Only set this when every request goes through that proxy, otherwise clients can forge it.
CERBER_PROXY_COUNT 1 Number of your own proxies that append to CERBER_PROXY_IP_HEADER.

For a comma separated list such as X-Forwarded-For: client, proxy1, the address is taken this many entries from the right; anything further left was sent by the client and is ignored.
CERBER_VERIFY_CLOUDFLARE_IP True Trust Cloudflare's headers only when the peer address is a Cloudflare IP.
CERBER_BLOCKED_COUNTRIES () ISO-3166 alpha-2 codes whose logins are always blocked, e.g. ("RU", "KP").

Takes precedence over everything else, including impossible-travel exceptions. Use "T1" here to block Tor via Cloudflare as well.
CERBER_BLOCK_TOR False Block logins from Tor exit nodes (Cloudflare reports them as T1).
CERBER_LOGOUT_ALL_SESSIONS True On a blocked login, also end every other session of that user.
CERBER_REDIRECT_URL None Where blocked browser logins are redirected. Defaults to LOGIN_URL.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Tomasz Drobiszewski
Tomasz Drobiszewski

💻 📖 🤔 🚧 ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

Credits

Copier

This package was created with Copier and the browniebroke/pypackage-template project template.

Metadata

Release files for django-cerber 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-cerber 0.1.1
File Size Uploaded Provenance Actions
django_cerber-0.1.1.tar.gz 24.9 kB With provenance Details for django_cerber-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-cerber 0.1.1
File Interpreter ABI Platform Actions
django_cerber-0.1.1-py3-none-any.whl Python 3 none any Details for django_cerber-0.1.1-py3-none-any.whl

Total release size: 46.0 kB

Release files / django_cerber-0.1.1.tar.gz

Download URL django_cerber-0.1.1.tar.gz
Size 24.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c7c62ef234c10b8c9ad34fca703a9e1280f84b9eeafd21d481815300570f96f4
BLAKE2b-256 checksum
How to use checksums
1175f0f96176d08900d164f6b4ed00506a4eeb3cad9e454c34eca58bfafc11ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / django_cerber-0.1.1-py3-none-any.whl

Download URL django_cerber-0.1.1-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f34bbe2fb31c3e0fa6f21afd67bdf25bb63e3c9d1ba64bda9dcfebfc71fd884e
BLAKE2b-256 checksum
How to use checksums
4d5560bced7b0ad3c16d5492abdbb8fe97fc507b47a11fdbd8f7f4590a8134f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Security for django-cerber 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_cerber-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page