Archived
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:
1 parent
d54f3b9e6e
commit
ec53bce5dc
14 files changed
+257
-43
No files matched your search
+28
-3
@@ -14,6 +14,7 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
@@ -57,6 +58,27 @@ Server::Server(const Deps& d, const ServerOptions& o)
|
||||
register_routes();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Server::~Server() { stop(); }
|
||||
|
||||
/* A sink may be freed only after the scheduler reports its request terminal, since
|
||||
@@ -2251,12 +2273,15 @@ HttpResponse Server::handle_lora_admin(const HttpRequest& req, bool load) {
|
||||
if (!opt_.lora_load || !opt_.lora_unload)
|
||||
return fail(404, "not_found_error", "this server was started without runtime LoRA (--lora or "
|
||||
"--max-loras)");
|
||||
if (opt_.api_key.empty() && (!req.peer_is_loopback() || req.is_cross_origin()))
|
||||
if (opt_.api_key.empty() && !local_operator(req))
|
||||
/* A cross-origin browser counts as neither loopback nor local: the victim's own browser
|
||||
* is loopback to this port, and that is exactly how a hostile page would reach here. */
|
||||
* is loopback to this port, and that is exactly how a hostile page would reach here —
|
||||
* under DNS rebinding it even arrives with a matching Host unless the Host names the
|
||||
* loopback, and through a localhost proxy every remote client does. Reading a path on
|
||||
* this machine is a local operator's act. */
|
||||
return fail(403, "permission_error", "loading an adapter reads a path on this machine, and a "
|
||||
"server started without --api-key takes it only from a "
|
||||
"loopback client");
|
||||
"loopback client naming this machine");
|
||||
/* Bounded like a generation body: this parses client text the same way, and a deep bracket
|
||||
* nest would overflow this worker's stack when the tree is torn down. */
|
||||
bool over = false, deep = false;
|
||||
|
||||
Reference in new issue
Block a user