From 6c906d5da8b75614c9d7df3124868aa7df42658f Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Fri, 17 Sep 2021 18:12:58 -0400 Subject: [PATCH] Enables context isolation for loading window --- loading.html | 3 +-- main.js | 2 +- ts/util/lint/exceptions.json | 26 ++++++-------------------- ts/windows/loading/preload.ts | 18 +++++------------- ts/windows/loading/start.ts | 7 ++++--- 5 files changed, 17 insertions(+), 39 deletions(-) diff --git a/loading.html b/loading.html index 6ec35bd53..67762c5f5 100644 --- a/loading.html +++ b/loading.html @@ -19,9 +19,8 @@ -
+
- diff --git a/main.js b/main.js index 2b5e48822..eb977398c 100644 --- a/main.js +++ b/main.js @@ -1340,7 +1340,7 @@ app.on('ready', async () => { webPreferences: { ...defaultWebPrefs, nodeIntegration: false, - contextIsolation: false, + contextIsolation: true, preload: path.join(__dirname, 'ts', 'windows', 'loading', 'preload.js'), }, icon: windowIcon, diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json index fd03bbd56..1807b0052 100644 --- a/ts/util/lint/exceptions.json +++ b/ts/util/lint/exceptions.json @@ -14386,31 +14386,17 @@ "updated": "2021-09-15T21:07:50.995Z" }, { - "rule": "jQuery-$(", + "rule": "DOM-innerHTML", "path": "ts/windows/loading/start.js", - "line": "$(() => {", + "line": " message.innerHTML = window.SignalWindow.i18n('optimizingApplication');", "reasonCategory": "usageTrusted", - "updated": "2020-03-25T15:45:04.024Z" + "updated": "2021-09-17T21:02:59.414Z" }, { - "rule": "jQuery-$(", - "path": "ts/windows/loading/start.js", - "line": " $('.message').text(window.i18n('optimizingApplication'));", - "reasonCategory": "usageTrusted", - "updated": "2021-07-22T03:00:34.561Z" - }, - { - "rule": "jQuery-$(", + "rule": "DOM-innerHTML", "path": "ts/windows/loading/start.ts", - "line": " $('.message').text(window.i18n('optimizingApplication'));", + "line": " message.innerHTML = window.SignalWindow.i18n('optimizingApplication');", "reasonCategory": "usageTrusted", - "updated": "2020-03-25T15:45:04.024Z" - }, - { - "rule": "jQuery-$(", - "path": "ts/windows/loading/start.ts", - "line": "$(() => {", - "reasonCategory": "usageTrusted", - "updated": "2021-07-22T03:00:34.561Z" + "updated": "2021-09-17T21:02:59.414Z" } ] \ No newline at end of file diff --git a/ts/windows/loading/preload.ts b/ts/windows/loading/preload.ts index 40470c2a8..66aa95d90 100644 --- a/ts/windows/loading/preload.ts +++ b/ts/windows/loading/preload.ts @@ -1,19 +1,11 @@ // Copyright 2020-2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -import { ipcRenderer } from 'electron'; -import * as url from 'url'; -import * as i18n from '../../../js/modules/i18n'; -import { strictAssert } from '../../util/assert'; +import { contextBridge } from 'electron'; -const config = url.parse(window.location.toString(), true).query; +// It is important to call this as early as possible +import '../context'; -const { locale } = config; -strictAssert( - typeof locale === 'string', - 'Expected to be configured with a string locale' -); +import { SignalWindow } from '../configure'; -const localeMessages = ipcRenderer.sendSync('locale-data'); - -window.i18n = i18n.setup(locale, localeMessages); +contextBridge.exposeInMainWorld('SignalWindow', SignalWindow); diff --git a/ts/windows/loading/start.ts b/ts/windows/loading/start.ts index 6bc7c059e..3e1e184e2 100644 --- a/ts/windows/loading/start.ts +++ b/ts/windows/loading/start.ts @@ -1,6 +1,7 @@ // Copyright 2020-2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -$(() => { - $('.message').text(window.i18n('optimizingApplication')); -}); +const message = document.getElementById('message'); +if (message) { + message.innerHTML = window.SignalWindow.i18n('optimizingApplication'); +}