Skip to content

Commit 90a2792

Browse files
committed
fix(security): recognize loopback trusted proxy authentication
1 parent 6e82723 commit 90a2792

3 files changed

Lines changed: 31 additions & 15 deletions

File tree

‎src/security/audit-gateway-config.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ export function collectGatewayConfigFindings(
8585
: explicitAuthMode === "none" || explicitAuthMode === "trusted-proxy"
8686
? false
8787
: tokenConfigured || passwordConfigured;
88-
const hasTailscaleAuth = auth.allowTailscale && tailscaleMode === "serve";
89-
const hasGatewayAuth = hasSharedSecret || hasTailscaleAuth;
88+
const hasGatewayAuth = hasSharedSecret || auth.mode === "trusted-proxy";
89+
const hasLoopbackAuth = hasGatewayAuth || (auth.allowTailscale && tailscaleMode === "serve");
9090
const allowRealIpFallback = cfg.gateway?.allowRealIpFallback === true;
9191
const mdnsMode = cfg.discovery?.mdns?.mode ?? "minimal";
9292

@@ -115,7 +115,7 @@ export function collectGatewayConfigFindings(
115115
"If you keep them enabled, keep gateway.bind loopback-only (or tailnet-only), restrict network exposure, and treat the gateway token/password as full-admin.",
116116
});
117117
}
118-
if (bind !== "loopback" && !hasSharedSecret && auth.mode !== "trusted-proxy") {
118+
if (bind !== "loopback" && !hasGatewayAuth) {
119119
findings.push({
120120
checkId: "gateway.bind_no_auth",
121121
severity: "critical",
@@ -150,7 +150,7 @@ export function collectGatewayConfigFindings(
150150
});
151151
}
152152

153-
if (bind === "loopback" && controlUiEnabled && !hasGatewayAuth) {
153+
if (bind === "loopback" && controlUiEnabled && !hasLoopbackAuth) {
154154
findings.push({
155155
checkId: "gateway.loopback_no_auth",
156156
severity: "critical",
@@ -293,7 +293,6 @@ export function collectGatewayConfigFindings(
293293
}
294294

295295
if (auth.mode === "trusted-proxy") {
296-
const trustedProxiesLocal = cfg.gateway?.trustedProxies ?? [];
297296
const trustedProxyConfig = cfg.gateway?.auth?.trustedProxy;
298297

299298
findings.push({
@@ -311,7 +310,7 @@ export function collectGatewayConfigFindings(
311310
"See /gateway/trusted-proxy-auth for setup guidance.",
312311
});
313312

314-
if (trustedProxiesLocal.length === 0) {
313+
if (trustedProxies.length === 0) {
315314
findings.push({
316315
checkId: "gateway.trusted_proxy_no_proxies",
317316
severity: "critical",

‎src/security/audit-gateway-exposure.test.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,12 @@ describe("security audit gateway exposure findings", () => {
330330
).toBe(true);
331331
});
332332

333-
it("evaluates trusted-proxy auth guardrails", () => {
333+
it.each(["loopback", "lan"] as const)("evaluates trusted-proxy auth guardrails on %s", (bind) => {
334334
const cases: Array<{
335335
name: string;
336336
cfg: OpenClawConfig;
337337
expectedCheckId: string;
338338
expectedSeverity: "warn" | "critical";
339-
suppressesGenericSharedSecretFindings?: boolean;
340339
}> = [
341340
{
342341
name: "trusted-proxy base mode",
@@ -352,7 +351,6 @@ describe("security audit gateway exposure findings", () => {
352351
},
353352
expectedCheckId: "gateway.trusted_proxy_auth",
354353
expectedSeverity: "critical",
355-
suppressesGenericSharedSecretFindings: true,
356354
},
357355
{
358356
name: "missing trusted proxies",
@@ -462,16 +460,17 @@ describe("security audit gateway exposure findings", () => {
462460
];
463461

464462
for (const testCase of cases) {
465-
const findings = collectGatewayConfigFindings(testCase.cfg, testCase.cfg, {});
463+
const cfg = { ...testCase.cfg, gateway: { ...testCase.cfg.gateway, bind } };
464+
const findings = collectGatewayConfigFindings(cfg, cfg, {});
466465
expect(
467466
hasFinding(testCase.expectedCheckId, testCase.expectedSeverity, findings),
468467
testCase.name,
469468
).toBe(true);
470-
if (testCase.suppressesGenericSharedSecretFindings) {
471-
const checkIds = findings.map((finding) => finding.checkId);
472-
expect(checkIds).not.toContain("gateway.bind_no_auth");
473-
expect(checkIds).not.toContain("gateway.auth_no_rate_limit");
474-
}
469+
const checkIds = findings.map((finding) => finding.checkId);
470+
expect(checkIds, testCase.name).toContain("gateway.trusted_proxy_auth");
471+
expect(checkIds, testCase.name).not.toContain("gateway.bind_no_auth");
472+
expect(checkIds, testCase.name).not.toContain("gateway.loopback_no_auth");
473+
expect(checkIds, testCase.name).not.toContain("gateway.auth_no_rate_limit");
475474
}
476475
});
477476

‎src/security/audit-gateway.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ function hasFindingWithSeverity(
1818
}
1919

2020
describe("security audit gateway config findings", () => {
21+
it.each([
22+
{ bind: "loopback", allowTailscale: true, missingAuth: false },
23+
{ bind: "loopback", allowTailscale: false, missingAuth: true },
24+
{ bind: "lan", allowTailscale: true, missingAuth: true },
25+
] as const)("limits Tailscale auth to its enabled loopback path: %j", (testCase) => {
26+
const cfg: OpenClawConfig = {
27+
gateway: {
28+
bind: testCase.bind,
29+
auth: { allowTailscale: testCase.allowTailscale },
30+
tailscale: { mode: "serve" },
31+
},
32+
};
33+
const findings = collectGatewayConfigFindings(cfg, cfg, {});
34+
const checkId =
35+
testCase.bind === "loopback" ? "gateway.loopback_no_auth" : "gateway.bind_no_auth";
36+
expect(hasFindingWithSeverity(checkId, "critical", findings)).toBe(testCase.missingAuth);
37+
});
38+
2139
it("evaluates gateway auth presence and rate-limit guardrails", async () => {
2240
await Promise.all([
2341
withEnvAsync(

0 commit comments

Comments
 (0)