mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
fix(ui): accept same-origin http and relative gateway URLs for client version
This commit is contained in:
@@ -243,6 +243,26 @@ describe("resolveControlUiClientVersion", () => {
|
|||||||
).toBe("2026.3.3");
|
).toBe("2026.3.3");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("returns serverVersion for same-origin relative targets", () => {
|
||||||
|
expect(
|
||||||
|
resolveControlUiClientVersion({
|
||||||
|
gatewayUrl: "/ws",
|
||||||
|
serverVersion: "2026.3.3",
|
||||||
|
pageUrl: "https://control.example.com/openclaw/",
|
||||||
|
}),
|
||||||
|
).toBe("2026.3.3");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns serverVersion for same-origin http targets", () => {
|
||||||
|
expect(
|
||||||
|
resolveControlUiClientVersion({
|
||||||
|
gatewayUrl: "https://control.example.com/ws",
|
||||||
|
serverVersion: "2026.3.3",
|
||||||
|
pageUrl: "https://control.example.com/openclaw/",
|
||||||
|
}),
|
||||||
|
).toBe("2026.3.3");
|
||||||
|
});
|
||||||
|
|
||||||
it("omits serverVersion for cross-origin targets", () => {
|
it("omits serverVersion for cross-origin targets", () => {
|
||||||
expect(
|
expect(
|
||||||
resolveControlUiClientVersion({
|
resolveControlUiClientVersion({
|
||||||
|
|||||||
@@ -102,8 +102,8 @@ export function resolveControlUiClientVersion(params: {
|
|||||||
try {
|
try {
|
||||||
const page = new URL(pageUrl);
|
const page = new URL(pageUrl);
|
||||||
const gateway = new URL(params.gatewayUrl, page);
|
const gateway = new URL(params.gatewayUrl, page);
|
||||||
const expectedWsProtocol = page.protocol === "https:" ? "wss:" : "ws:";
|
const allowedProtocols = new Set(["ws:", "wss:", "http:", "https:"]);
|
||||||
if (gateway.protocol !== expectedWsProtocol || gateway.host !== page.host) {
|
if (!allowedProtocols.has(gateway.protocol) || gateway.host !== page.host) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return serverVersion;
|
return serverVersion;
|
||||||
|
|||||||
Reference in New Issue
Block a user