forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternalUrl.ts
More file actions
16 lines (15 loc) · 796 Bytes
/
Copy pathexternalUrl.ts
File metadata and controls
16 lines (15 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Shared scheme allow-list guard for handing a URL to the OS. A prompt-injected
// chat reply or a malformed checkout/portal URL could otherwise carry a file://,
// UNC, or custom-protocol URL; passing those to shell.openExternal enables
// NTLM-hash leak / protocol-handler abuse. The main window's window-open handler
// (http/https/mailto) and the billing customer-portal opener (http/https) both
// route through this one parser instead of hand-rolling their own.
/** True iff `url` parses and its scheme is one of `allowed` (bare, no trailing colon). */
export function isAllowedExternalScheme(url: string, allowed: string[]): boolean {
try {
const scheme = new URL(url).protocol // e.g. "https:"
return allowed.some((a) => scheme === `${a}:`)
} catch {
return false
}
}