tilie_server.security#
The origin, body-limit and referrer-policy ASGI middleware.
- class tilie_server.security.OriginGuard(app, *, token, hosts, origins)[source]#
Bases:
objectReject requests that do not come from the server’s own origin.
Three checks run on every HTTP request and WebSocket handshake, before any route is reached:
the
Hostheader must be one of the server’s hosts, which defeats DNS rebinding (403 otherwise);an
Originheader, when present, must be one of the server’s origins, which defeats cross-site requests from other pages (403 otherwise);when the server has a token, every path under
/api/must carryAuthorization: Bearer <token>with that token (401 otherwise).
A rejected WebSocket handshake is closed before it is accepted.
- tilie_server.security.body_limit_message(limit)[source]#
The refusal of a body longer than
limitbytes, the limit named bytilie_server.settings.size_named().
- class tilie_server.security.BodyLimit(app, *, limit)[source]#
Bases:
objectRefuse a request body longer than
limitbytes with 413.A
Content-Lengthover the limit is refused at once, without reading the body. A body sent without one (chunked) is read here, chunk by chunk, and refused as soon as the bytes received pass the limit; a body within it is handed to the application as it came, so the route runs only with a whole body inside the limit.
- class tilie_server.security.NoReferrer(app)[source]#
Bases:
objectSend
Referrer-Policy: no-referrerwith every HTTP response.With this policy the browser sends none of the server’s URLs as a
Referer, so no other site learns them, whatever a URL may carry. Rejections byOriginGuardandBodyLimitcarry the header as well.- Parameters:
app (ASGIApp)
- HEADER = (b'referrer-policy', b'no-referrer')#