Add Electron desktop shell workspace
This commit is contained in:
parent
b803d10836
commit
5d8e5ea44a
16 changed files with 1652 additions and 21 deletions
44
apps/desktop/src/security.ts
Normal file
44
apps/desktop/src/security.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
export const DESKTOP_PRODUCTION_URL = "https://flow.deltaisland.io";
|
||||
export const DESKTOP_LOCAL_DEV_URL = "http://127.0.0.1:3000";
|
||||
|
||||
const TRUSTED_ORIGINS = new Set([
|
||||
new URL(DESKTOP_PRODUCTION_URL).origin,
|
||||
new URL(DESKTOP_LOCAL_DEV_URL).origin,
|
||||
"http://localhost:3000"
|
||||
]);
|
||||
|
||||
const HTTP_PROTOCOLS = new Set(["http:", "https:"]);
|
||||
|
||||
const parseUrl = (candidate: string): URL | null => {
|
||||
try {
|
||||
return new URL(candidate);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const isTrustedAppUrl = (candidate: string): boolean => {
|
||||
const url = parseUrl(candidate);
|
||||
if (!url || !HTTP_PROTOCOLS.has(url.protocol)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return TRUSTED_ORIGINS.has(url.origin);
|
||||
};
|
||||
|
||||
export const isSafeExternalUrl = (candidate: string): boolean => {
|
||||
const url = parseUrl(candidate);
|
||||
if (!url || !HTTP_PROTOCOLS.has(url.protocol)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !TRUSTED_ORIGINS.has(url.origin);
|
||||
};
|
||||
|
||||
export const resolveDesktopStartUrl = (candidate: string | undefined): string => {
|
||||
if (candidate && isTrustedAppUrl(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
|
||||
return DESKTOP_PRODUCTION_URL;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue