fleet: the admin routes read all three legs, as the engine's guards do

The fleet front guarded its admin routes with the loopback socket alone.
The socket is the one leg that forges: a DNS-rebinding page is same-origin
with its victim's browser and dials through loopback, and a localhost proxy
delivers remote clients on loopback sockets carrying the public Host. With
CORS open by default, a web page in the operator's browser could unload and
park any model, reload the fleet, and read the topology -- disk paths in
the body -- from outside the machine.

The three-leg rule (loopback socket, no foreign Origin, a Host that names
this box) was Server::local_operator's, locked inside Server. Hoist it to
server::local_operator(request, bind_host, local_hosts) beside the request
whose fields it reads, keep the member as the delegate it now is, and let
the fleet's guard call the very same predicate with its own config's host
and --allow-host names. One rule, two callers, no forked wording.
This commit is contained in:
fl0l0u committed 2026-11-15 20:38:09 +00:00
1 parent 2a2b756371
commit 41a1aa00fe
6 files changed
+83 -32

No files matched your search

+3 -18
View File
@@ -62,24 +62,9 @@ Server::Server(const Deps& d, const ServerOptions& o)
}
bool Server::local_operator(const HttpRequest& req) const {
if (!req.peer_is_loopback() || req.is_cross_origin()) return false;
if (req.host_is_loopback()) return true;
const std::string host = req.host_authority();
if (host.empty()) return false; /* a socket always carries a Host; the in-process case
passed host_is_loopback on its empty peer */
for (const std::string& a : opt_.local_hosts) {
std::string want = a;
for (char& ch : want) ch = (char)std::tolower((unsigned char)ch);
if (want == host) return true;
}
/* Bound to one concrete address, the box answers to that name on itself. */
std::string bind = opt_.host;
for (char& ch : bind) ch = (char)std::tolower((unsigned char)ch);
if (!bind.empty() && bind.front() == '[' && bind.back() == ']')
bind = bind.substr(1, bind.size() - 2);
if (!bind.empty() && bind != "0.0.0.0" && bind != "::" && bind != "*")
return bind == host;
return false;
/* The three-leg rule itself lives beside the request it reads (server::local_operator,
* http.cpp) so the fleet's front applies the very same one. */
return server::local_operator(req, opt_.host, opt_.local_hosts);
}
Server::~Server() { stop(); }