mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 05:31:23 +00:00
fix(gateway): preserve unbracketed IPv6 host headers
This commit is contained in:
@@ -5,8 +5,21 @@ import {
|
|||||||
isTrustedProxyAddress,
|
isTrustedProxyAddress,
|
||||||
pickPrimaryLanIPv4,
|
pickPrimaryLanIPv4,
|
||||||
resolveGatewayListenHosts,
|
resolveGatewayListenHosts,
|
||||||
|
resolveHostName,
|
||||||
} from "./net.js";
|
} from "./net.js";
|
||||||
|
|
||||||
|
describe("resolveHostName", () => {
|
||||||
|
it("returns hostname without port for IPv4/hostnames", () => {
|
||||||
|
expect(resolveHostName("localhost:18789")).toBe("localhost");
|
||||||
|
expect(resolveHostName("127.0.0.1:18789")).toBe("127.0.0.1");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("handles bracketed and unbracketed IPv6 loopback hosts", () => {
|
||||||
|
expect(resolveHostName("[::1]:18789")).toBe("::1");
|
||||||
|
expect(resolveHostName("::1")).toBe("::1");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("isTrustedProxyAddress", () => {
|
describe("isTrustedProxyAddress", () => {
|
||||||
describe("exact IP matching", () => {
|
describe("exact IP matching", () => {
|
||||||
it("returns true when IP matches exactly", () => {
|
it("returns true when IP matches exactly", () => {
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ export function resolveHostName(hostHeader?: string): string {
|
|||||||
return host.slice(1, end);
|
return host.slice(1, end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Unbracketed IPv6 host (e.g. "::1") has no port and should be returned as-is.
|
||||||
|
if (net.isIP(host) === 6) {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
const [name] = host.split(":");
|
const [name] = host.split(":");
|
||||||
return name ?? "";
|
return name ?? "";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user