request_filters
===============
A sort of software firewall for your django application which provides advances capabilities for blocking or logging requests at runtime. Only for use in wagtail projects - might support django-only in the future.
Supports filtering based on:
- IP
- USER_AGENT
- PATH
- QUERY_STRING
- REFERER
- COUNTRY
- METHOD
Matching based on:
- Absolute (== in most cases. Differs for: IP (Checks subnet if cidr provided), COUNTRY (Checks country code or name as returned by GeoIP2))
- Glob (fnmatch)
- Regex (re)
- In (IP based on cidr, splits most
filter_value's' by comma and checks if the request's value is in the list)
Quick start
-
Add 'request_filters' to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ..., 'request_filters', ] -
Add
request_filters.middleware.RequestFilterMiddlewareto yourMIDDLEWAREas the FIRST ENTRY.MIDDLEWARE = [ ..., 'request_filters.middleware.RequestFilterMiddleware', ] -
See the options section for more information on how to configure the app.
-
Log into your wagtail admin and configure your filters.
Options
EXCLUDED_APPS
List of excluded apps, all requests to these apps will be allowed (If resolver_match is available). Exclusions should preferably happen via IP ranges or absolute IPs.
EXCLUDED_APPS: list[str] = [
"admin",
]
EXCLUDED_PATHS
Excluded paths, all requests to these paths will skip filtering
Paths should be in the format of a glob pattern. Exclusions should preferably happen via IP ranges or absolute IPs.
EXCLUDED_PATHS: list[str] = [
"/admin/*",
f"{getattr(settings, 'STATIC_URL', '/static/')}*",
f"{getattr(settings, 'MEDIA_URL', '/media/')}*",
]
EXCLUDED_IPS
Excluded IP addresses, all requests from these IPs will be allowed.
# This is the safest way to exclude requests from being filtered.
EXCLUDED_IPS: list[str] = [
"127.0.0.0/8", "::1/128",
]
Caching
Caching settings and their defaults.
# Default cache backend to use for storing settings and filters
CACHE_BACKEND: str = "default"
# Namespaces for cache keys.
SETTINGS_CACHE_KEY: str = "request_filters_settings"
FILTERS_CACHE_KEY: str = "request_filters_filters"
# Timeout the cache for the filter settings for 5 minutes by default
SETTINGS_CACHE_TIMEOUT: timezone.timedelta = timezone.timedelta(minutes=5)
# Timeout the cache for the filters for 1 hour by default
FILTERS_CACHE_TIMEOUT: timezone.timedelta = timezone.timedelta(hours=1)
# Clear cache when settings are saved
CLEAR_CACHE_ON_SAVE_SETTINGS: bool = True
# Clear cache when filters are saved
CLEAR_CACHE_ON_SAVE_FILTERS: bool = True
Exception Message
Message shown when a filter raises an exception, or blocks the request.
BLOCK_MESSAGE: str = _("You are not allowed to access this resource")
Filter Headers
Add headers to the response which displays minimal information about the filters.
ADD_FILTER_HEADERS: bool = True # Add headers to the response which displays minimal information about the filters.
Create a log entry for requests which have passed all filters.
Not recommended for production.
LOG_HAPPY_PATH: bool = False # Log requests that are allowed by the filters
Default values for the check and action functions.
DEFAULT_CHECK_VALUE: Union[bool, callable] = True # Allow checks to pass by default
DEFAULT_ACTION_VALUE: callable = lambda self, filter, settings, request, get_response: HttpResponseForbidden(
_("You are not allowed to access this resource")
)
Metadata
Release files for request-filters 1.1.7
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 | Actions |
|---|---|---|---|---|
| request_filters-1.1.7.tar.gz | 29.3 kB | Without provenance | Details for request_filters-1.1.7.tar.gz |
Release files / request_filters-1.1.7.tar.gz
| Download URL | request_filters-1.1.7.tar.gz |
|---|---|
| Size | 29.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b721fd3a8467e626e30434526a3ab850dcd8870df92b1c39b4051a090f1e06f3
|
|
BLAKE2b-256 checksum How to use checksums |
94b0284c5faf780cfc63c67d15dc74d75ebf221ec5e91d9604b26147be4713c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Security for request-filters 1.1.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.