Skip to main content

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

  1. Add the app to your INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
    ...
    "dj_waf",
]
  1. Configure your WAF settings in settings.py:
# settings.py

WAF = {
    "default": {
        "BACKEND": "dj_waf.backends.cloudflare.CloudflareBackend",
        "OPTIONS": {
            "apikey": "cloudflare-waf-api-key",
            "domain": "your-example-domain.com",
            "rules": [
                {
                    "description": "dj-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,
                }
            ],
        },
    },
}
  1. 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.

Create Cloudflare API

  1. Go to https://dash.cloudflare.com/profile/api-tokens
  2. Click Create Token
  3. Scroll to the bottom and click Get started in the "Create Custom Token" section
  4. In the Permissions area, select Zone, Zone Settings, Read
  5. Click Add more
  6. Select Zone, Zone WAF, Edit
  7. Click Continue to summary
  8. Click Create Token
  9. Copy API token from User API Tokens page

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.

Metadata

Release files for dj-waf 0.2.0

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

Source distribution (sdist)

Source distribution for dj-waf 0.2.0
File Size Uploaded Provenance
dj_waf-0.2.0.tar.gz 4.8 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dj-waf 0.2.0
File Interpreter ABI Platform
dj_waf-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release files / dj_waf-0.2.0.tar.gz

Download URL dj_waf-0.2.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f8c829b01fa8df7a867f59294d9a9a87aa7342f4eda7d4c37c11921d73517363
BLAKE2b-256 checksum
How to use checksums
202c99af512da36d8c62be7425cf81cb529bc5db4ed6c73bd1477f1a3259ed2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Nov 22, 2025.

Transparency log

Release files / dj_waf-0.2.0-py3-none-any.whl

Download URL dj_waf-0.2.0-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15b0eb88e165f2375bf884c0704872938531ed803c09fa7be2c7c6156482cda6
BLAKE2b-256 checksum
How to use checksums
0fee4f1102acbe728401f69068c6fb3d3b28c67c56b79458b65de48891893691
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Nov 22, 2025.

Transparency log

Security for dj-waf 0.2.0

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dj_waf-0.2.0.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 Nov 22, 2025.

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.

Release history Release notifications | RSS feed

This release

0.2.0 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