Skip to content

Commit 14fd3c5

Browse files
committed
fix(doctor): recognize trusted-proxy authentication
1 parent 6862adf commit 14fd3c5

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

‎src/commands/doctor-security.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,42 @@ describe("noteSecurityWarnings gateway exposure", () => {
230230
expect(message).not.toContain("CRITICAL");
231231
});
232232

233+
it("recognizes trusted-proxy as an explicit auth mode without certifying readiness", async () => {
234+
const cfg = {
235+
gateway: {
236+
bind: "lan",
237+
trustedProxies: ["192.0.2.10"],
238+
controlUi: { allowedOrigins: ["https://control.example.test"] },
239+
auth: {
240+
mode: "trusted-proxy",
241+
trustedProxy: {
242+
userHeader: "x-forwarded-user",
243+
allowUsers: ["[email protected]"],
244+
},
245+
},
246+
},
247+
} satisfies OpenClawConfig;
248+
249+
const findings = await collectSecurityWarnings(cfg, {});
250+
const exposureFindings = findings.filter((finding) =>
251+
finding.checkId.startsWith("gateway.bind_"),
252+
);
253+
expect(exposureFindings).toEqual([
254+
expect.objectContaining({
255+
checkId: "gateway.bind_network_accessible",
256+
severity: "warn",
257+
detail: expect.stringContaining("configured authentication boundary"),
258+
remediation: expect.not.stringContaining("openclaw doctor --fix"),
259+
}),
260+
]);
261+
262+
await noteSecurityWarnings(cfg);
263+
const message = lastMessage();
264+
expect(message).not.toContain("without authentication");
265+
expect(message).toContain("direct Gateway access is restricted");
266+
expect(message).toContain("openclaw security audit --deep");
267+
});
268+
233269
it("warns when OPENCLAW_GATEWAY_TOKEN env conflicts with gateway.auth.token config (#74271)", async () => {
234270
process.env.OPENCLAW_GATEWAY_TOKEN = "env-token-123";
235271
const cfg = {

‎src/commands/doctor-security.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export async function collectSecurityWarnings(
325325
findings.push(...collectDurableExecApprovalWarnings(approvals));
326326
}
327327

328-
// Network exposure needs auth proof before doctor can treat non-loopback bind as intentional.
328+
// Network exposure needs an explicit auth mechanism before Doctor treats it as intentional.
329329
const tailscaleMode = cfg.gateway?.tailscale?.mode ?? "off";
330330
const gatewayBind = (cfg.gateway?.bind ?? "loopback") as string;
331331
const customBindHost = cfg.gateway?.customBindHost?.trim();
@@ -362,7 +362,7 @@ export async function collectSecurityWarnings(
362362
];
363363

364364
if (isExposed) {
365-
if (!hasSharedSecret) {
365+
if (!hasSharedSecret && resolvedAuth.mode !== "trusted-proxy") {
366366
const authFixLines =
367367
resolvedAuth.mode === "password"
368368
? [
@@ -397,7 +397,7 @@ export async function collectSecurityWarnings(
397397
title: "WARNING",
398398
detail: [
399399
`Gateway bound to ${bindDescriptor} (network-accessible).`,
400-
"Ensure your auth credentials are strong and not exposed.",
400+
"Ensure the configured authentication boundary is strong and direct Gateway access is restricted.",
401401
].join("\n"),
402402
remediation: saferRemoteAccessLines.join("\n"),
403403
});

0 commit comments

Comments
 (0)