Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sandbox - detect crash from running as admin and inform user properly #166958

Merged
merged 1 commit into from Nov 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 49 additions & 23 deletions src/vs/platform/windows/electron-main/windowImpl.ts
Expand Up @@ -44,6 +44,7 @@ import { IUserDataProfile } from 'vs/platform/userDataProfile/common/userDataPro
import { IStateMainService } from 'vs/platform/state/electron-main/state';
import product from 'vs/platform/product/common/product';
import { IUserDataProfilesMainService } from 'vs/platform/userDataProfile/electron-main/userDataProfile';
import { INativeHostMainService } from 'vs/platform/native/electron-main/nativeHostMainService';

export interface IWindowCreationOptions {
state: IWindowState;
Expand Down Expand Up @@ -180,7 +181,8 @@ export class CodeWindow extends Disposable implements ICodeWindow {
@IProductService private readonly productService: IProductService,
@IProtocolMainService private readonly protocolMainService: IProtocolMainService,
@IWindowsMainService private readonly windowsMainService: IWindowsMainService,
@IStateMainService private readonly stateMainService: IStateMainService
@IStateMainService private readonly stateMainService: IStateMainService,
@INativeHostMainService private readonly nativeHostMainService: INativeHostMainService
) {
super();

Expand Down Expand Up @@ -710,31 +712,55 @@ export class CodeWindow extends Disposable implements ICodeWindow {

// Process gone
else if (type === WindowError.PROCESS_GONE) {
let message: string;
if (!details) {
message = localize('appGone', "The window terminated unexpectedly");
} else {
message = localize('appGoneDetails', "The window terminated unexpectedly (reason: '{0}', code: '{1}')", details.reason, details.exitCode ?? '<unknown>');

// Windows: running as admin with AppLocker enabled is unsupported
// when sandbox: true.
// we cannot detect AppLocker use currently, but make a
// guess based on the reason and exit code.
if (isWindows && details?.reason === 'launch-failed' && details.exitCode === 18 && await this.nativeHostMainService.isAdmin(undefined)) {
await this.dialogMainService.showMessageBox({
title: this.productService.nameLong,
type: 'error',
buttons: [
mnemonicButtonLabel(localize({ key: 'close', comment: ['&& denotes a mnemonic'] }, "&&Close"))
],
message: localize('appGoneAdminMessage', "Running as administrator is not supported"),
detail: localize('appGoneAdminDetail', "Please try again without administrator privileges.", this.productService.nameLong),
noLink: true,
defaultId: 0
}, this._win);

await this.destroyWindow(false, false);
}

// Show Dialog
const result = await this.dialogMainService.showMessageBox({
title: this.productService.nameLong,
type: 'warning',
buttons: [
mnemonicButtonLabel(localize({ key: 'reopen', comment: ['&& denotes a mnemonic'] }, "&&Reopen")),
mnemonicButtonLabel(localize({ key: 'close', comment: ['&& denotes a mnemonic'] }, "&&Close"))
],
message,
detail: localize('appGoneDetail', "We are sorry for the inconvenience. You can reopen the window to continue where you left off."),
noLink: true,
defaultId: 0,
checkboxLabel: this._config?.workspace ? localize('doNotRestoreEditors', "Don't restore editors") : undefined
}, this._win);
// Any other crash: offer to restart
else {
let message: string;
if (!details) {
message = localize('appGone', "The window terminated unexpectedly");
} else {
message = localize('appGoneDetails', "The window terminated unexpectedly (reason: '{0}', code: '{1}')", details.reason, details.exitCode ?? '<unknown>');
}

// Handle choice
const reopen = result.response === 0;
await this.destroyWindow(reopen, result.checkboxChecked);
// Show Dialog
const result = await this.dialogMainService.showMessageBox({
title: this.productService.nameLong,
type: 'warning',
buttons: [
mnemonicButtonLabel(localize({ key: 'reopen', comment: ['&& denotes a mnemonic'] }, "&&Reopen")),
mnemonicButtonLabel(localize({ key: 'close', comment: ['&& denotes a mnemonic'] }, "&&Close"))
],
message,
detail: localize('appGoneDetail', "We are sorry for the inconvenience. You can reopen the window to continue where you left off."),
noLink: true,
defaultId: 0,
checkboxLabel: this._config?.workspace ? localize('doNotRestoreEditors', "Don't restore editors") : undefined
}, this._win);

// Handle choice
const reopen = result.response === 0;
await this.destroyWindow(reopen, result.checkboxChecked);
}
}
break;
}
Expand Down