Skip to content

Commit 92ff20a

Browse files
kieferrmTyriar
authored andcommitted
app.ts - check uris
1 parent 48089b3 commit 92ff20a

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

  • src/vs/code/electron-main

src/vs/code/electron-main/app.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { app, ipcMain as ipc, systemPreferences, shell, Event, contentTracing, protocol, powerMonitor, IpcMainEvent, BrowserWindow } from 'electron';
6+
import { app, ipcMain as ipc, systemPreferences, shell, Event, contentTracing, protocol, powerMonitor, IpcMainEvent, BrowserWindow, dialog } from 'electron';
77
import { IProcessEnvironment, isWindows, isMacintosh } from 'vs/base/common/platform';
88
import { WindowsMainService } from 'vs/platform/windows/electron-main/windowsMainService';
99
import { IWindowOpenable } from 'vs/platform/windows/common/windows';
@@ -80,6 +80,7 @@ import { coalesce } from 'vs/base/common/arrays';
8080
import { IStorageKeysSyncRegistryService } from 'vs/platform/userDataSync/common/storageKeys';
8181
import { StorageKeysSyncRegistryChannel } from 'vs/platform/userDataSync/common/userDataSyncIpc';
8282
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
83+
import { mnemonicButtonLabel, getPathLabel } from 'vs/base/common/labels';
8384

8485
export class CodeApplication extends Disposable {
8586
private windowsMainService: IWindowsMainService | undefined;
@@ -605,6 +606,11 @@ export class CodeApplication extends Disposable {
605606
return undefined;
606607
}
607608
})).filter(pendingUriToHandle => {
609+
// if URI should be blocked, filter it out
610+
if (this.shouldBlockURI(pendingUriToHandle)) {
611+
return false;
612+
}
613+
608614
// filter out any protocol link that wants to open as window so that
609615
// we open the right set of windows on startup and not restore the
610616
// previous workspace too.
@@ -623,6 +629,10 @@ export class CodeApplication extends Disposable {
623629
const environmentService = this.environmentService;
624630
urlService.registerHandler({
625631
async handleURL(uri: URI): Promise<boolean> {
632+
// if URI should be blocked, behave as if it's handled
633+
if (app.shouldBlockURI(uri)) {
634+
return true;
635+
}
626636

627637
// Check for URIs to open in window
628638
const windowOpenableFromProtocolLink = app.getWindowOpenableFromProtocolLink(uri);
@@ -727,6 +737,29 @@ export class CodeApplication extends Disposable {
727737
});
728738
}
729739

740+
private shouldBlockURI(uri: URI): boolean {
741+
if (uri.authority === Schemas.file && isWindows) {
742+
const res = dialog.showMessageBoxSync({
743+
title: product.nameLong,
744+
type: 'question',
745+
buttons: [
746+
mnemonicButtonLabel(localize({ key: 'open', comment: ['&& denotes a mnemonic'] }, "&&Yes")),
747+
mnemonicButtonLabel(localize({ key: 'cancel', comment: ['&& denotes a mnemonic'] }, "&&No")),
748+
],
749+
cancelId: 1,
750+
message: localize('confirmOpenMessage', "An external application wants to open '{0}' in {1}. Do you want to open this file or folder?", getPathLabel(uri.fsPath), product.nameShort),
751+
detail: localize('confirmOpenDetail', "If you did not initiate this request, it may represent an attempted attack on your system. Unless you took an explicit action to initiate this request, you should press 'No'"),
752+
noLink: true
753+
});
754+
755+
if (res === 1) {
756+
return true;
757+
}
758+
}
759+
760+
return false;
761+
}
762+
730763
private getWindowOpenableFromProtocolLink(uri: URI): IWindowOpenable | undefined {
731764
if (!uri.path) {
732765
return undefined;

0 commit comments

Comments
 (0)