Archived
server: name the caller a vouched proxy carried, without arming the guard
An operator running radiance behind a reverse proxy sees one address in every log line: the proxy's. --trusted-proxy CIDR (repeatable) vouches for the networks whose sockets may say who they carried. An X-Forwarded-For from inside a vouched network is walked from the right: vouched hops are skipped, the first address no vouched CIDR covers is the caller, a chain of only vouched hops ends at its leftmost, and anything else falls back to the socket. From an unvouched socket the header names no one, because it has not been vouched for. Attribution is not authority, and the split that keeps them apart is mechanical. HttpRequest carries `peer`, the attributed caller, sanitized where it is built because a named address arrives in a header and the log keeps no client text otherwise -- and `raw_peer`, the socket as the kernel saw it, which is now the only address peer_is_loopback() reads. A proxy on loopback therefore hands the keyless loopback-only routes to none of its clients; it only names them where the proxy used to stand. transport_test pins both halves: the walk at the unit level, and over a real socket that a vouched proxy plus X-Forwarded-For leaves the loopback guard answering 200 and the cross-origin 403 untouched. httplib's own set_trusted_proxies -- new this side of the vendor bump -- is deliberately unarmed. It rewrites req.remote_addr, the very field the guards would read as the socket peer, so one over-broad vouched network would move the guard rather than the log line. Radiance reads the header itself, and ip_in_cidr refuses across families: a vouched ::ffff:0:0/96 vouches for no IPv4 socket. Config rejects anything but a numeric network with a prefix at startup, because a typo there would silently unvouch a proxy; the refusals the transport answers before the router log the attributed caller too, so the audit trail stays one line per request whoever the socket belongs to.
This commit is contained in:
1 parent
40e1b3073b
commit
b6acbd69e4
11 files changed
+352
-22
No files matched your search
@@ -2756,6 +2756,7 @@ TEST(the_models_root_path_follows_the_key) {
|
||||
HttpRequest remote;
|
||||
remote.path = "/v1/models";
|
||||
remote.peer = "192.168.1.20:50122";
|
||||
remote.raw_peer = remote.peer;
|
||||
remote.headers["Host"] = "box.example:8000";
|
||||
CHECK(!json::parse(f.srv->router().dispatch(remote).body)["data"][0].contains("root"));
|
||||
/* The rebinding page: a loopback socket, an attacker's Origin and Host -- the pair the
|
||||
@@ -2763,12 +2764,14 @@ TEST(the_models_root_path_follows_the_key) {
|
||||
HttpRequest rebinding;
|
||||
rebinding.path = "/v1/models";
|
||||
rebinding.peer = "127.0.0.1:50122";
|
||||
rebinding.raw_peer = rebinding.peer;
|
||||
rebinding.headers["Host"] = "evil.test:8000";
|
||||
rebinding.headers["Origin"] = "http://evil.test:8000";
|
||||
CHECK(!json::parse(f.srv->router().dispatch(rebinding).body)["data"][0].contains("root"));
|
||||
HttpRequest local;
|
||||
local.path = "/v1/models";
|
||||
local.peer = "127.0.0.1:50122";
|
||||
local.raw_peer = local.peer;
|
||||
local.headers["Host"] = "localhost:8000";
|
||||
CHECK_EQ(json::parse(f.srv->router().dispatch(local).body)["data"][0]
|
||||
.value("root", std::string()),
|
||||
@@ -3097,6 +3100,7 @@ TEST(diagnostics_without_a_key_answers_loopback_only) {
|
||||
HttpRequest q;
|
||||
q.path = "/diagnostics";
|
||||
q.peer = peer;
|
||||
q.raw_peer = peer;
|
||||
if (host) q.headers["Host"] = host;
|
||||
if (origin) q.headers["Origin"] = origin;
|
||||
return s.router().dispatch(q).status;
|
||||
@@ -3148,6 +3152,7 @@ TEST(state_changing_routes_without_a_key_answer_the_machine_only) {
|
||||
q.path = "/sessions";
|
||||
q.query["label"] = "conv-1";
|
||||
q.peer = peer;
|
||||
q.raw_peer = peer;
|
||||
if (host) q.headers["Host"] = host;
|
||||
return s.router().dispatch(q).status;
|
||||
};
|
||||
@@ -3156,6 +3161,7 @@ TEST(state_changing_routes_without_a_key_answer_the_machine_only) {
|
||||
q.method = "POST";
|
||||
q.path = "/reset_prefix_cache";
|
||||
q.peer = peer;
|
||||
q.raw_peer = peer;
|
||||
if (host) q.headers["Host"] = host;
|
||||
return s.router().dispatch(q).status;
|
||||
};
|
||||
@@ -4908,10 +4914,12 @@ TEST(the_control_vector_field_overrides_the_default_or_is_refused) {
|
||||
q.path = "/admin/control-vector";
|
||||
q.body = R"({"enabled":true})";
|
||||
q.peer = "192.168.1.20:50122";
|
||||
q.raw_peer = q.peer;
|
||||
q.headers["Host"] = "127.0.0.1:8080";
|
||||
CHECK_EQ(f.srv->router().dispatch(q).status, 403);
|
||||
CHECK(!def);
|
||||
q.peer = "127.0.0.1:50122";
|
||||
q.raw_peer = q.peer;
|
||||
q.headers["Host"] = "localhost:8000";
|
||||
CHECK_EQ(f.srv->router().dispatch(q).status, 200);
|
||||
CHECK(def);
|
||||
@@ -4930,6 +4938,7 @@ TEST(the_control_vector_field_overrides_the_default_or_is_refused) {
|
||||
x.path = "/admin/control-vector";
|
||||
x.body = R"({"enabled":false})";
|
||||
x.peer = "127.0.0.1:50122";
|
||||
x.raw_peer = x.peer;
|
||||
x.headers["Origin"] = "http://evil.test";
|
||||
x.headers["Host"] = "127.0.0.1:8080";
|
||||
CHECK_EQ(f.srv->router().dispatch(x).status, 403);
|
||||
@@ -4942,6 +4951,7 @@ TEST(the_control_vector_field_overrides_the_default_or_is_refused) {
|
||||
HttpRequest g2;
|
||||
g2.path = "/admin/control-vector";
|
||||
g2.peer = "192.168.1.20:50122";
|
||||
g2.raw_peer = g2.peer;
|
||||
g2.headers["Host"] = "box.example:8000";
|
||||
CHECK_EQ(f.srv->router().dispatch(g2).status, 403);
|
||||
HttpRequest g3;
|
||||
|
||||
Reference in new issue
Block a user