mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 00:48:27 +00:00
Security: Prevent gateway credential exfiltration via URL override (#9179)
* Gateway: require explicit auth for url overrides * Gateway: scope credential blocking to non-local URLs only Address review feedback: the previous fix blocked credential fallback for ALL URL overrides, which was overly strict and could break workflows that use --url to switch between loopback/tailnet without passing credentials. Now credential fallback is only blocked for non-local URLs (public IPs, external hostnames). Local addresses (127.0.0.1, localhost, private IPs like 192.168.x.x, 10.x.x.x, tailnet 100.x.x.x) still get credential fallback as before. This maintains the security fix (preventing credential exfiltration to attacker-controlled URLs) while preserving backward compatibility for legitimate local URL overrides. * Security: require explicit credentials for gateway url overrides (#8113) (thanks @victormier) * Gateway: reuse explicit auth helper for url overrides (#8113) (thanks @victormier) * Tests: format gateway chat test (#8113) (thanks @victormier) * Tests: require explicit auth for gateway url overrides (#8113) (thanks @victormier) --------- Co-authored-by: Victor Mier <victormier@gmail.com>
This commit is contained in:
committed by
GitHub
parent
96abc1c864
commit
a13ff55bd9
@@ -113,9 +113,14 @@ describe("callGateway url resolution", () => {
|
||||
resolveGatewayPort.mockReturnValue(18789);
|
||||
pickPrimaryTailnetIPv4.mockReturnValue(undefined);
|
||||
|
||||
await callGateway({ method: "health", url: "wss://override.example/ws" });
|
||||
await callGateway({
|
||||
method: "health",
|
||||
url: "wss://override.example/ws",
|
||||
token: "explicit-token",
|
||||
});
|
||||
|
||||
expect(lastClientOptions?.url).toBe("wss://override.example/ws");
|
||||
expect(lastClientOptions?.token).toBe("explicit-token");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -257,6 +262,40 @@ describe("callGateway error details", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("callGateway url override auth requirements", () => {
|
||||
beforeEach(() => {
|
||||
loadConfig.mockReset();
|
||||
resolveGatewayPort.mockReset();
|
||||
pickPrimaryTailnetIPv4.mockReset();
|
||||
lastClientOptions = null;
|
||||
startMode = "hello";
|
||||
closeCode = 1006;
|
||||
closeReason = "";
|
||||
resolveGatewayPort.mockReturnValue(18789);
|
||||
pickPrimaryTailnetIPv4.mockReturnValue(undefined);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||
delete process.env.OPENCLAW_GATEWAY_PASSWORD;
|
||||
});
|
||||
|
||||
it("throws when url override is set without explicit credentials", async () => {
|
||||
process.env.OPENCLAW_GATEWAY_TOKEN = "env-token";
|
||||
process.env.OPENCLAW_GATEWAY_PASSWORD = "env-password";
|
||||
loadConfig.mockReturnValue({
|
||||
gateway: {
|
||||
mode: "local",
|
||||
auth: { token: "local-token", password: "local-password" },
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
callGateway({ method: "health", url: "wss://override.example/ws" }),
|
||||
).rejects.toThrow("explicit credentials");
|
||||
});
|
||||
});
|
||||
|
||||
describe("callGateway password resolution", () => {
|
||||
const originalEnvPassword = process.env.OPENCLAW_GATEWAY_PASSWORD;
|
||||
|
||||
@@ -338,6 +377,24 @@ describe("callGateway password resolution", () => {
|
||||
|
||||
expect(lastClientOptions?.password).toBe("from-env");
|
||||
});
|
||||
|
||||
it("uses explicit password when url override is set", async () => {
|
||||
process.env.OPENCLAW_GATEWAY_PASSWORD = "from-env";
|
||||
loadConfig.mockReturnValue({
|
||||
gateway: {
|
||||
mode: "local",
|
||||
auth: { password: "from-config" },
|
||||
},
|
||||
});
|
||||
|
||||
await callGateway({
|
||||
method: "health",
|
||||
url: "wss://override.example/ws",
|
||||
password: "explicit-password",
|
||||
});
|
||||
|
||||
expect(lastClientOptions?.password).toBe("explicit-password");
|
||||
});
|
||||
});
|
||||
|
||||
describe("callGateway token resolution", () => {
|
||||
@@ -364,18 +421,21 @@ describe("callGateway token resolution", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("uses remote token when remote mode uses url override", async () => {
|
||||
it("uses explicit token when url override is set", async () => {
|
||||
process.env.OPENCLAW_GATEWAY_TOKEN = "env-token";
|
||||
loadConfig.mockReturnValue({
|
||||
gateway: {
|
||||
mode: "remote",
|
||||
remote: { token: "remote-token" },
|
||||
mode: "local",
|
||||
auth: { token: "local-token" },
|
||||
},
|
||||
});
|
||||
|
||||
await callGateway({ method: "health", url: "wss://override.example/ws" });
|
||||
await callGateway({
|
||||
method: "health",
|
||||
url: "wss://override.example/ws",
|
||||
token: "explicit-token",
|
||||
});
|
||||
|
||||
expect(lastClientOptions?.token).toBe("remote-token");
|
||||
expect(lastClientOptions?.token).toBe("explicit-token");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user