server: stop treating the loopback socket as identity

Three guards read a loopback peer plus a matching Origin as "this is
the machine's operator". Two real topologies forge exactly that:

DNS rebinding hands a hostile page its victim's own browser, so the
peer IS loopback, and the page is same-origin with the server, so the
Origin/Host compare stays silent. Only the Host still says which name
the client asked for, and the attacker's domain cannot be made to read
as the loopback.

The documented TLS-proxy topology puts every remote client behind a
loopback socket, and a non-browser client sends no Origin at all; the
proxy passes the public Host, which the new check refuses.

Server::local_operator now guards the keyless routes: the socket, the
Origin, and a Host naming the loopback, --allow-host, or a concrete
bind address. GET /admin/control-vector takes the guard POST already
had, placed before the 404-that-means-no-vector so a remote page can
probe neither; keyless DELETE /sessions and /reset_prefix_cache --
which destroy other clients' cached conversations -- answer the
machine only. --allow-host (repeatable) admits names an operator
reaches the box by from the box itself.

A local user at the console stays admitted; nothing about a key-set
server changes. GUIDE 6.6 states the new posture.
This commit is contained in:
fl0l0u authored and StillDeadcode committed 2026-10-31 07:50:43 +01:00
1 parent d54f3b9e6e
commit ec53bce5dc
14 files changed
+257 -43

No files matched your search

+15 -5
View File
@@ -509,14 +509,15 @@ HttpResponse Server::handle_diagnostics(const HttpRequest& req) {
return error_response(err_not_implemented(
"the server was not given a diagnostics provider; this build has no engine attached"),
req.peer);
if (opt_.api_key.empty() && (!req.peer_is_loopback() || req.is_cross_origin())) {
/* A cross-origin browser is not a loopback client even when its own machine serves
* this port: the drive-by that guard exists to refuse. */
if (opt_.api_key.empty() && !local_operator(req)) {
/* A cross-origin browser is not a loopback client even when the victim's own machine
* serves this port, and under rebinding or a localhost proxy the socket alone says
* loopback for anyone: the Host is what still names who the client asked. */
ApiError e;
e.status = 403;
e.type = "permission_error";
e.message = "without --api-key, /diagnostics answers only loopback clients; start the "
"server with --api-key to read it from elsewhere";
e.message = "without --api-key, /diagnostics answers only a loopback client naming this "
"machine; start the server with --api-key to read it from elsewhere";
return error_response(e, req.peer);
}
metrics_.observe_http(200);
@@ -530,6 +531,15 @@ HttpResponse Server::handle_reset_prefix_cache(const HttpRequest& req) {
if (!deps_.sched)
return error_response(err_not_implemented("the server has no engine attached"), req.peer);
/* Wiping every client's cached prefix is an operator act: keyless, it belongs to the
* machine, not to whichever browser or page can reach the port. */
if (opt_.api_key.empty() && !local_operator(req))
return error_response(
err_forbidden("without --api-key, /reset_prefix_cache runs only from a loopback "
"client naming this machine; start the server with --api-key to run "
"it from elsewhere"),
req.peer);
const int64_t n = deps_.sched->reset_prefix_cache();
if (n < 0)
return error_response(err_not_implemented(