Registration (case-insensitive unique names, 8-256 char passwords, no email), sign-in with a generic error and a fresh session, internal-only ?next=, POST-only sign-out, password change that closes the other sessions. The failed-login backoff, the registration quota and the password-change guard live in the database so every web process shares them; the client IP is the last X-Forwarded-For hop. One responsive stylesheet with light/dark theme, labelled fields, alerts and no inline scripts or styles; Italian error pages and a readable CSRF failure. Mutation checks: open redirects, uncounted failures and a missing CSRF middleware are all caught. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
14 lines
722 B
Python
14 lines
722 B
Python
"""The caller's address, for the throttles that are keyed by it (SEC-42, B-54)."""
|
|
|
|
|
|
def client_ip(request) -> str:
|
|
"""The *last* hop of X-Forwarded-For: the one written by our own proxy. The first elements are whatever
|
|
the client sent, so reading from the front would let a fake value per request dodge every IP-keyed
|
|
control. Caddy also overwrites the header with the real peer (Caddyfile), so either half closes it;
|
|
without the header (direct access) the socket peer is used."""
|
|
forwarded = request.META.get("HTTP_X_FORWARDED_FOR", "")
|
|
hops = [hop.strip() for hop in forwarded.split(",") if hop.strip()]
|
|
if hops:
|
|
return hops[-1]
|
|
return request.META.get("REMOTE_ADDR", "unknown")
|