vibesketch.server.guard

The local server’s front door: who may talk to it and how much they may send (#69).

A server bound to the loopback interface is reachable only from this machine, but a web page in any browser on it can still send requests. A page from another site is told apart by its Origin. A site that points its own name at 127.0.0.1 (DNS rebinding) shares the server’s origin, but cannot change the Host it sends. So a loopback server answers only requests whose Host names this machine, and refuses state from pages whose Origin is anything else. A server bound to another interface was asked for by name; it takes any Host and leaves access to its network.

Every request body is also bounded (vibesketch.limits.MAX_REQUEST_BYTES): it is read up to the bound and refused with 413 past it, before the application parses anything.

Module Attributes

LOOPBACK

The names this machine answers to on its loopback interface.

Functions

is_loopback(host)

Classes

Guard(app, *, hosts, max_body)

ASGI middleware: the Host and Origin checks and the request body bound.

vibesketch.server.guard.LOOPBACK = frozenset({'127.0.0.1', '::1', 'localhost'})

The names this machine answers to on its loopback interface.

class vibesketch.server.guard.Guard(app, *, hosts, max_body)[source]

Bases: object

ASGI middleware: the Host and Origin checks and the request body bound.

Parameters:
  • app (ASGIApp)

  • hosts (Iterable[str] | None)

  • max_body (int)

vibesketch.server.guard.is_loopback(host)[source]
Parameters:

host (str)

Return type:

bool