Skip to content

Commit 01f86c1

Browse files
authored
🐛 Fix(gui): restrict remote notice URLs to HTTP and HTTPS
Allow only HTTP and HTTPS URLs in all three remote notice actions before calling shell.openExternal. ISSUES CLOSED: #1458 Co-authored-by: carfeii <carfeii@users.noreply.github.com>
1 parent 25104f6 commit 01f86c1

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

‎src/main/apis/app/remoteNotice/index.ts‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ const REMOTE_NOTICE_LOCAL_STORAGE_FILE = 'picgo-remote-notice.json'
1919

2020
const REMOTE_NOTICE_LOCAL_STORAGE_PATH = path.join(STORE_PATH, REMOTE_NOTICE_LOCAL_STORAGE_FILE)
2121

22+
23+
// Only allow http/https links from remote notice actions, never a custom
24+
// OS-registered protocol scheme, since the remote notice document is not
25+
// cryptographically signed and openExternal can dispatch arbitrary URI
26+
// schemes to the OS.
27+
function isSafeExternalUrl (url: string): boolean {
28+
try {
29+
const parsed = new URL(url)
30+
return parsed.protocol === 'http:' || parsed.protocol === 'https:'
31+
} catch {
32+
return false
33+
}
34+
}
35+
2236
class RemoteNoticeHandler {
2337
private remoteNotice: IRemoteNotice | null = null
2438
private remoteNoticeLocalCountStorage: IRemoteNoticeLocalCountStorage | null = null
@@ -117,22 +131,24 @@ class RemoteNoticeHandler {
117131
clickToCopy: !!action.data?.copyToClipboard,
118132
copyContent: action.data?.copyToClipboard || '',
119133
callback () {
120-
if (action.data?.url) {
134+
if (action.data?.url && isSafeExternalUrl(action.data.url)) {
121135
shell.openExternal(action.data.url)
122136
}
123137
}
124138
})
125139
break
126140
case IRemoteNoticeActionType.OPEN_URL:
127141
// OPEN URL
128-
shell.openExternal(action.data?.url || '')
142+
if (action.data?.url && isSafeExternalUrl(action.data.url)) {
143+
shell.openExternal(action.data.url)
144+
}
129145
break
130146
case IRemoteNoticeActionType.COMMON:
131147
// DO COMMON CASE
132148
if (action.data?.copyToClipboard) {
133149
clipboard.writeText(action.data.copyToClipboard)
134150
}
135-
if (action.data?.url) {
151+
if (action.data?.url && isSafeExternalUrl(action.data.url)) {
136152
shell.openExternal(action.data.url)
137153
}
138154
break

0 commit comments

Comments
 (0)