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_APPSinsettings.py:
INSTALLED_APPS = [
...
"dj_waf",
]
- 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,
}
],
},
},
}
- 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
- Go to https://dash.cloudflare.com/profile/api-tokens
- Click
Create Token - Scroll to the bottom and click
Get startedin the "Create Custom Token" section - In the Permissions area, select
Zone,Zone Settings,Read - Click
Add more - Select
Zone,Zone WAF,Edit - Click
Continue to summary - Click
Create Token - Copy API token from
User API Tokenspage
Available Backends
cloudflare
Test 🧪
uv install pip install -e .[dev]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)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dj_waf-0.2.0.tar.gz | 4.8 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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 logRelease 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 logSecurity 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.
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 logA 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.