Files
moloapp/audit/MOLO-EXPOSE-001/reproduce.cpp
T

60 lines
2.4 KiB
C++

// MOLO-EXPOSE-001: UpstreamHostAllowed's private/local allow-list is a
// bare string-prefix test, so a public hostname that merely starts with a
// private-looking label (e.g. "10.evil.com") is misclassified as private
// and let through when it should be rejected. See README.md.
//
// UpstreamHostAllowed is a pure function (no I/O, no server needed): the
// real policy check reverse.md documents and src/realtime/expose/tunnel.cpp
// calls before registering an upstream.
#include <cstdio>
#include "realtime/expose/upstream.h"
using molo::realtime::expose::UpstreamHostAllowed;
struct Case {
const char* host;
bool should_be_private; // the correct verdict: is this really loopback/RFC1918/link-local?
};
int main() {
// These are real public DNS names (any attacker can register one) that
// share a prefix with a private-range literal. The correct verdict for
// all of them is "not private".
static const Case kCases[] = {
{"10.evil.com", false},
{"127.evil.com", false},
{"192.168.attacker.net", false},
{"169.254.attacker.net", false},
{"172.99.evil.com", false},
// Sanity controls: a real private literal must still pass.
{"10.0.0.5", true},
{"192.168.1.1", true},
};
int failures = 0;
for (const auto& c : kCases) {
bool allowed = UpstreamHostAllowed(c.host, /*allow_public=*/false);
bool wrong = allowed != c.should_be_private;
std::printf("%-28s allowed=%-5s want_private=%-5s %s\n", c.host,
allowed ? "true" : "false", c.should_be_private ? "true" : "false",
wrong ? "MISMATCH" : "ok");
if (wrong) failures++;
}
if (failures > 0) {
std::printf(
"FAIL: %d/%zu cases misclassified; UpstreamHostAllowed (src/realtime/expose/"
"upstream.cpp) uses host.rfind(\"10.\",0)==0 style bare prefix tests, so a "
"public hostname that starts with a private-looking label is accepted as "
"private even though DNS will resolve it to an arbitrary public (or "
"attacker-controlled) address: an allow-list bypass in the policy reverse.md "
"documents as \"upstream host must be loopback / RFC1918 / link-local unless "
"allow_public is set\" (CWE-184, incomplete allow-list)\n",
failures, sizeof(kCases) / sizeof(kCases[0]));
return 1;
}
std::printf("PASS: all %zu cases classified correctly\n", sizeof(kCases) / sizeof(kCases[0]));
return 0;
}