fix: harden control ui framing + ws origin

This commit is contained in:
Peter Steinberger
2026-02-03 16:00:57 -08:00
parent 0223416c61
commit 66d8117d44
11 changed files with 265 additions and 91 deletions

View File

@@ -51,6 +51,30 @@ type SettingsHost = {
pendingGatewayUrl?: string | null;
};
function isTopLevelWindow(): boolean {
try {
return window.top === window.self;
} catch {
return false;
}
}
function normalizeGatewayUrl(raw: string): string | null {
const trimmed = raw.trim();
if (!trimmed) {
return null;
}
try {
const parsed = new URL(trimmed);
if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") {
return null;
}
return trimmed;
} catch {
return null;
}
}
export function applySettings(host: SettingsHost, next: UiSettings) {
const normalized = {
...next,
@@ -118,8 +142,8 @@ export function applySettingsFromUrl(host: SettingsHost) {
}
if (gatewayUrlRaw != null) {
const gatewayUrl = gatewayUrlRaw.trim();
if (gatewayUrl && gatewayUrl !== host.settings.gatewayUrl) {
const gatewayUrl = normalizeGatewayUrl(gatewayUrlRaw);
if (gatewayUrl && gatewayUrl !== host.settings.gatewayUrl && isTopLevelWindow()) {
host.pendingGatewayUrl = gatewayUrl;
}
params.delete("gatewayUrl");