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

+11
View File
@@ -102,6 +102,16 @@ TEST(an_empty_api_key_is_refused) {
CHECK(c.api_key == "k");
}
/* --allow-host repeats: the loopback-only routes take the set of names, and an empty one is
* a hole cut by a typo, so it is refused like the empty key. */
TEST(allow_host_repeats_and_refuses_the_empty_name) {
CHECK_EQ(parse_fresh({ "--allow-host", "" }), RAD_E_INVAL);
Config c;
CHECK_EQ(parse({ "--allow-host", "box", "--allow-host", "box.example" }, &c), 0);
CHECK(c.allow_hosts.size() == 2);
CHECK(c.allow_hosts[0] == "box" && c.allow_hosts[1] == "box.example");
}
/* A flag written last with no argument is refused rather than reading past argv. */
TEST(a_flag_missing_its_argument_is_refused_rather_than_read_past) {
Config c;
@@ -482,6 +492,7 @@ const std::map<std::string, std::vector<std::string>>& legal_values() {
{ "--draft-window", { "fixed" } }, { "--draft-short-from", { "4" } },
{ "--draft-coupling", { "on" } },
{ "--host", { "127.0.0.1" } }, { "--port", { "8001" } }, { "--api-key", { "k" } },
{ "--allow-host", { "box" } },
{ "--served-model-name", { "m" } }, { "--mm-max-patches", { "1024" } },
{ "--control-vector", { "off" } },
{ "--generation-config", { "/g.json" } }, { "--override-chat-template", { "/t.jinja" } },