Skip to main content

Add WAF rules to block known bots and malicious traffic for Django applications. Provides easy integration with popular WAF services like Cloudflare.

Project description

dj-waf 🙅

Add WAF rules to block known bots and malicious traffic for Django applications

Provides easy integration with popular WAF services like Cloudflare.

Features 🤩

  • Create WAF rules in Cloudflare directly from Django.

Installation

pip install dj-waf

OR

uv add dj-waf

Usage

Add the app to your INSTALLED_APPS in settings.py:

INSTALLED_APPS = [
    ...
    "dj_waf",
]

Configure your WAF settings in settings.py:

# settings.py

WAF = {
    "default": {
        "BACKEND": "django_waf.backends.cloudflare.CloudflareBackend",
        "OPTIONS": {
            "apikey": "waf-cloudflare-api-key",
            "domain": "your-example-domain.com",
            "rules": [
                {
                    "description": "django-waf",
                    "expression": '(http.request.uri.path wildcard r"/wp-*") or (http.request.uri.path wildcard r"/*wp-*") or (http.request.uri.path wildcard r"/wordpress*") or (http.request.uri.path wildcard r"/*wordpress*") or (http.request.uri.path wildcard r"*.php") or (http.request.uri.path eq "/.env") or (http.request.uri.path wildcard r"/admin/*")',
                    "action": "block",
                    "enabled": True,
                }
            ],
        },
    },
}

Then run the management command to apply the rules:

python manage.py create_waf_rules

The command will create WAF rules in your configured WAF provider (e.g., Cloudflare) based on the rules defined in your WAF settings.

You can also configure multiple WAF providers and specify which one to use:

python manage.py create_waf_rules --backend cloudflare

To see all available options:

python manage.py create_waf_rules --help

Available Backends

  • cloudflare

Test 🧪

  1. uv install pip install -e .[dev]
  2. just test

Contributing 🤝

Contributions are welcome! Please feel free to submit a Pull Request.

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

dj_waf-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dj_waf-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file dj_waf-0.1.0.tar.gz.

File metadata

  • Download URL: dj_waf-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dj_waf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 55f09602f53a8ed41331af2ec84de0e1be11e85a09fc616d3a38b8aeaeff074f
MD5 f862c960a6121c9574907b52c0d961f2
BLAKE2b-256 6ad1a5a95a52e33acdfdc1cd9225f1f85bb4d6d4e5181d87ef47a6fb46744c11

See more details on using hashes here.

Provenance

The following attestation bundles were made for dj_waf-0.1.0.tar.gz:

Publisher: publish.yml on adamghill/dj-waf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dj_waf-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dj_waf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dj_waf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7831e0d16feef32dd937a81f565b729701bfab511dec5288533d4abe1728f10f
MD5 a6ccb8d6cd5d7fc79348a0fd8ea19c8f
BLAKE2b-256 f52a2099d32f179183efb86f8d83c57f2e3095437f923405f3ede8989503ec6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for dj_waf-0.1.0-py3-none-any.whl:

Publisher: publish.yml on adamghill/dj-waf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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