Ushka

ushka.security.middleware

Security middleware, on by default.

It runs around every request, outside your own middleware, so even error pages and CORS preflights carry the protections. Everything is configured in the [security] section of ushka.toml (or USHKA_SECURITY_*).

Order: trusted hosts, CORS preflight, CSRF, your handler, then the headers.

CSRF protection needs no token and no secret key. Browsers tell the server where a request came from (Sec-Fetch-Site and Origin), and a state-changing request that came from another site is refused. Requests with neither header are not from a browser (curl, a mobile app, a server), so they cannot be forged through a victim's browser and pass.

class SecurityMiddleware

Trusted hosts, CSRF, CORS and security headers, built from the config.

websocket_allowed

def websocket_allowed(request: Request) -> bool

Handshake check: trusted host, and no cross-site browser (the WebSocket twin of CSRF: cookies ride along on a cross-site new WebSocket).