From 67f0b1e5ec421722cf33d1b3ee4a410b251b5aed 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 +++++++++-- 1 file changed, 9 insertions(+), 2 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..7def5358da5a6 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'; 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; }