From 1755e26111a3d26d945173a6ba6dfc8f2ebdedf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Mar=C3=A9chal?= Date: Tue, 8 Jun 2021 12:49:07 -0400 Subject: [PATCH] mini-browser: use secure host pattern on electron There is little use to configure how the mini-browser should serve files on Electron, as using different origins should always work. --- .../browser/environment/mini-browser-environment.ts | 11 +++++++++-- .../mini-browser/src/browser/mini-browser-guard.ts | 5 ++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/mini-browser/src/browser/environment/mini-browser-environment.ts b/packages/mini-browser/src/browser/environment/mini-browser-environment.ts index 874f43a14bff9..cbbc0885d5200 100644 --- a/packages/mini-browser/src/browser/environment/mini-browser-environment.ts +++ b/packages/mini-browser/src/browser/environment/mini-browser-environment.ts @@ -16,6 +16,7 @@ import { Endpoint, FrontendApplicationContribution } from '@theia/core/lib/browser'; import { EnvVariablesServer } from '@theia/core/lib/common/env-variables'; +import { environment } from '@theia/core/shared/@theia/application-package/lib/environment'; import { inject, injectable, optional, postConstruct } from '@theia/core/shared/inversify'; import { v4 } from 'uuid'; import { MiniBrowserEndpoint } from '../../common/mini-browser-endpoint'; @@ -42,8 +43,7 @@ export class MiniBrowserEnvironment implements FrontendApplicationContribution { @postConstruct() protected postConstruct(): void { - this._hostPatternPromise = this.environment.getValue(MiniBrowserEndpoint.HOST_PATTERN_ENV) - .then(envVar => envVar?.value || MiniBrowserEndpoint.HOST_PATTERN_DEFAULT) + this._hostPatternPromise = this.getHostPattern() .then(pattern => this.miniBrowserConfiguration.hostPattern = pattern); if (this.miniBrowserGuard) { this._hostPatternPromise @@ -68,6 +68,13 @@ export class MiniBrowserEnvironment implements FrontendApplicationContribution { return this.getEndpoint(v4()); } + protected async getHostPattern(): Promise { + return environment.electron.is() + ? MiniBrowserEndpoint.HOST_PATTERN_DEFAULT + : this.environment.getValue(MiniBrowserEndpoint.HOST_PATTERN_ENV) + .then(envVar => envVar?.value || MiniBrowserEndpoint.HOST_PATTERN_DEFAULT); + } + protected getDefaultHostname(): string { return self.location.host; } diff --git a/packages/mini-browser/src/browser/mini-browser-guard.ts b/packages/mini-browser/src/browser/mini-browser-guard.ts index 00d0a024e7d6f..13466f4152179 100644 --- a/packages/mini-browser/src/browser/mini-browser-guard.ts +++ b/packages/mini-browser/src/browser/mini-browser-guard.ts @@ -86,12 +86,11 @@ export class MiniBrowserGuard { case 'Always Prevent': this.setMiniBrowserPreference('mini-browser.previewFile.preventUnsecure', 'alwaysPrevent'); case 'Prevent': - case undefined: + case undefined: // closed dialog throw this.preventOpeningLocation(location); case 'Always Open': - this.setMiniBrowserPreference('mini-browser.previewFile.preventUnsecure', 'alwaysPrevent'); + this.setMiniBrowserPreference('mini-browser.previewFile.preventUnsecure', 'alwaysOpen'); case 'Open': - return; } }