Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions build/entitlements.mac.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
Expand Down
15 changes: 15 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import {
} from 'electron'
import { exposeElectronAPI } from '@electron-toolkit/preload'

const ALLOWED_PROTOCOLS = ['http:', 'https:', 'mailto:', 'tel:', 'deepchat:']

const isValidExternalUrl = (url: string): boolean => {
try {
const parsed = new URL(url)
return ALLOWED_PROTOCOLS.includes(parsed.protocol.toLowerCase())
} catch {
return false
}
}

// Cache variables
let cachedWindowId: number | undefined = undefined
let cachedWebContentsId: number | undefined = undefined
Expand Down Expand Up @@ -44,6 +55,10 @@ const api = {
return cachedWebContentsId
},
openExternal: (url: string) => {
if (!isValidExternalUrl(url)) {
console.warn('Preload: Blocked openExternal for disallowed URL:', url)
return Promise.reject(new Error('URL protocol not allowed'))
}
return shell.openExternal(url)
},
toRelativePath: (filePath: string, baseDir?: string) => {
Expand Down