Skip to content

Commit c863e58

Browse files
committed
fix(preload): add URL protocol filter for openExternal (#1314)
1 parent 6698524 commit c863e58

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

build/entitlements.mac.plist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
<true/>
77
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
88
<true/>
9-
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
10-
<true/>
119
<key>com.apple.security.files.user-selected.read-write</key>
1210
<true/>
1311
<key>com.apple.security.files.user-selected.read-only</key>

src/preload/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ import {
1010
} from 'electron'
1111
import { exposeElectronAPI } from '@electron-toolkit/preload'
1212

13+
const ALLOWED_PROTOCOLS = ['http:', 'https:', 'mailto:', 'tel:', 'deepchat:']
14+
15+
const isValidExternalUrl = (url: string): boolean => {
16+
try {
17+
const parsed = new URL(url)
18+
return ALLOWED_PROTOCOLS.includes(parsed.protocol.toLowerCase())
19+
} catch {
20+
return false
21+
}
22+
}
23+
1324
// Cache variables
1425
let cachedWindowId: number | undefined = undefined
1526
let cachedWebContentsId: number | undefined = undefined
@@ -44,6 +55,10 @@ const api = {
4455
return cachedWebContentsId
4556
},
4657
openExternal: (url: string) => {
58+
if (!isValidExternalUrl(url)) {
59+
console.warn('Preload: Blocked openExternal for disallowed URL:', url)
60+
return Promise.reject(new Error('URL protocol not allowed'))
61+
}
4762
return shell.openExternal(url)
4863
},
4964
toRelativePath: (filePath: string, baseDir?: string) => {

0 commit comments

Comments
 (0)