Sensitive Files Middleware
- class smarter.lib.django.middleware.sensitive_files.SmarterBlockSensitiveFilesMiddleware(get_response)[source]
Bases:
SmarterMiddlewareMixinMiddleware that blocks requests probing for sensitive files.
Features:
ASGI and WSGI compatible
Path normalization
Amnesty support
Request throttling
In-memory inspection
- __init__(get_response)[source]
Note: this needs to exist; something in the Python MRO requires it, even if it does nothing.
If you remove this, you will get a mysterious error about something downstream expecting exactly one object.
- property formatted_class_name: str[source]
Return the formatted class name for logging.
It names the instance, not a request.
- increment_throttle(client_ip)[source]
Add one to a client’s probe count in the cache, and reset its
THROTTLE_TIMEOUT.While the cache can’t be written, e.g. during a Redis outage, the probe isn’t counted.
- is_amnesty_path(path)[source]
Return whether a path is exempt from the sensitive-file check.
A path is exempt when it is an amnesty url, or when it or one of its segments matches an allowed pattern.
- classmethod is_sensitive_request(path)[source]
Return whether a normalized path asks for a sensitive file.
- is_throttled(client_ip)[source]
Return whether a client has reached the throttle limit of sensitive-file probes.
While the cache can’t be read, e.g. during a Redis outage, no client is throttled (issue #1091).
- static iter_path_segments(path)[source]
Return the non-empty segments of a path, e.g.
aandbfor/a//b/.