Files
webadderall eaf87be95b Recordly 2.0 local review stack 2/6
Dependency-ordered review preparation. Not pushed or remotely reviewed.
2026-11-06 05:24:21 +11:00

34 lines
1.1 KiB
TypeScript

import type { IpcMainInvokeEvent } from "electron";
import { type AppLocale, SUPPORTED_LOCALES } from "../src/i18n/config";
/** Only a supported locale from one of the app's own top-level documents may change native UI. */
export function validateAppLocaleRequest(
event: Pick<IpcMainInvokeEvent, "sender" | "senderFrame">,
value: unknown,
trustedBaseUrls: readonly string[],
): value is AppLocale {
if (typeof value !== "string" || !SUPPORTED_LOCALES.some((locale) => locale === value))
return false;
if (
!event.senderFrame ||
event.senderFrame !== event.sender.mainFrame ||
event.sender.isDestroyed()
)
return false;
try {
const candidate = new URL(event.senderFrame.url);
if (candidate.username || candidate.password) return false;
return trustedBaseUrls.some((base) => {
const trusted = new URL(base);
return (
["http:", "https:", "file:"].includes(trusted.protocol) &&
candidate.protocol === trusted.protocol &&
candidate.host === trusted.host &&
candidate.pathname === trusted.pathname
);
});
} catch {
return false;
}
}