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 🧪
uv install pip install -e .[dev]just test
Contributing 🤝
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55f09602f53a8ed41331af2ec84de0e1be11e85a09fc616d3a38b8aeaeff074f
|
|
| MD5 |
f862c960a6121c9574907b52c0d961f2
|
|
| BLAKE2b-256 |
6ad1a5a95a52e33acdfdc1cd9225f1f85bb4d6d4e5181d87ef47a6fb46744c11
|
Provenance
The following attestation bundles were made for dj_waf-0.1.0.tar.gz:
Publisher:
publish.yml on adamghill/dj-waf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dj_waf-0.1.0.tar.gz -
Subject digest:
55f09602f53a8ed41331af2ec84de0e1be11e85a09fc616d3a38b8aeaeff074f - Sigstore transparency entry: 715916934
- Sigstore integration time:
-
Permalink:
adamghill/dj-waf@4053bbf020f63e2ced4ee56dd05a88a45445092f -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/adamghill
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4053bbf020f63e2ced4ee56dd05a88a45445092f -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7831e0d16feef32dd937a81f565b729701bfab511dec5288533d4abe1728f10f
|
|
| MD5 |
a6ccb8d6cd5d7fc79348a0fd8ea19c8f
|
|
| BLAKE2b-256 |
f52a2099d32f179183efb86f8d83c57f2e3095437f923405f3ede8989503ec6d
|
Provenance
The following attestation bundles were made for dj_waf-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on adamghill/dj-waf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dj_waf-0.1.0-py3-none-any.whl -
Subject digest:
7831e0d16feef32dd937a81f565b729701bfab511dec5288533d4abe1728f10f - Sigstore transparency entry: 715916940
- Sigstore integration time:
-
Permalink:
adamghill/dj-waf@4053bbf020f63e2ced4ee56dd05a88a45445092f -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/adamghill
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4053bbf020f63e2ced4ee56dd05a88a45445092f -
Trigger Event:
release
-
Statement type: