Enables ContextIsolation
This commit is contained in:
@@ -3,8 +3,9 @@
|
||||
|
||||
import { ipcRenderer as ipc } from 'electron';
|
||||
import * as semver from 'semver';
|
||||
import { mapValues, noop } from 'lodash';
|
||||
import { mapValues } from 'lodash';
|
||||
|
||||
import type { IPCType } from '../../window.d';
|
||||
import { parseIntWithFallback } from '../../util/parseIntWithFallback';
|
||||
import { UUIDKind } from '../../types/UUID';
|
||||
import { ThemeType } from '../../types/Util';
|
||||
@@ -22,13 +23,16 @@ window.i18n = SignalContext.i18n;
|
||||
const { config } = window.SignalContext;
|
||||
|
||||
// Flags for testing
|
||||
window.GV2_ENABLE_SINGLE_CHANGE_PROCESSING = true;
|
||||
window.GV2_ENABLE_CHANGE_PROCESSING = true;
|
||||
window.GV2_ENABLE_STATE_PROCESSING = true;
|
||||
window.GV2_ENABLE_PRE_JOIN_FETCH = true;
|
||||
const Flags = {
|
||||
GV2_ENABLE_CHANGE_PROCESSING: true,
|
||||
GV2_ENABLE_PRE_JOIN_FETCH: true,
|
||||
GV2_ENABLE_SINGLE_CHANGE_PROCESSING: true,
|
||||
GV2_ENABLE_STATE_PROCESSING: true,
|
||||
GV2_MIGRATION_DISABLE_ADD: false,
|
||||
GV2_MIGRATION_DISABLE_INVITE: false,
|
||||
};
|
||||
|
||||
window.GV2_MIGRATION_DISABLE_ADD = false;
|
||||
window.GV2_MIGRATION_DISABLE_INVITE = false;
|
||||
window.Flags = Flags;
|
||||
|
||||
window.RETRY_DELAY = false;
|
||||
|
||||
@@ -55,9 +59,6 @@ window.getExpiration = () => {
|
||||
}
|
||||
return localBuildExpiration;
|
||||
};
|
||||
window.Accessibility = {
|
||||
reducedMotionSetting: Boolean(config.reducedMotionSetting),
|
||||
};
|
||||
window.getHostName = () => config.hostname;
|
||||
window.getServerTrustRoot = () => config.serverTrustRoot;
|
||||
window.getServerPublicParams = () => config.serverPublicParams;
|
||||
@@ -78,13 +79,78 @@ if (config.theme === 'light') {
|
||||
window.initialTheme = ThemeType.dark;
|
||||
}
|
||||
|
||||
window.getAutoLaunch = () => {
|
||||
return ipc.invoke('get-auto-launch');
|
||||
};
|
||||
window.setAutoLaunch = value => {
|
||||
return ipc.invoke('set-auto-launch', value);
|
||||
const IPC: IPCType = {
|
||||
addSetupMenuItems: () => ipc.send('add-setup-menu-items'),
|
||||
closeAbout: () => ipc.send('close-about'),
|
||||
crashReports: {
|
||||
getCount: () => ipc.invoke('crash-reports:get-count'),
|
||||
upload: () => ipc.invoke('crash-reports:upload'),
|
||||
erase: () => ipc.invoke('crash-reports:erase'),
|
||||
},
|
||||
drawAttention: () => {
|
||||
log.info('draw attention');
|
||||
ipc.send('draw-attention');
|
||||
},
|
||||
getAutoLaunch: () => ipc.invoke('get-auto-launch'),
|
||||
getBuiltInImages: () =>
|
||||
new Promise((resolve, reject) => {
|
||||
ipc.once('get-success-built-in-images', (_event, error, value) => {
|
||||
if (error) {
|
||||
return reject(new Error(error));
|
||||
}
|
||||
|
||||
return resolve(value);
|
||||
});
|
||||
ipc.send('get-built-in-images');
|
||||
}),
|
||||
getMediaPermissions: () => ipc.invoke('settings:get:mediaPermissions'),
|
||||
getMediaCameraPermissions: () =>
|
||||
ipc.invoke('settings:get:mediaCameraPermissions'),
|
||||
logAppLoadedEvent: ({ processedCount }) =>
|
||||
ipc.send('signal-app-loaded', {
|
||||
preloadTime: window.preloadEndTime - window.preloadStartTime,
|
||||
connectTime: preloadConnectTime - window.preloadEndTime,
|
||||
processedCount,
|
||||
}),
|
||||
readyForUpdates: () => ipc.send('ready-for-updates'),
|
||||
removeSetupMenuItems: () => ipc.send('remove-setup-menu-items'),
|
||||
restart: () => {
|
||||
log.info('restart');
|
||||
ipc.send('restart');
|
||||
},
|
||||
setAutoHideMenuBar: autoHide => ipc.send('set-auto-hide-menu-bar', autoHide),
|
||||
setAutoLaunch: value => ipc.invoke('set-auto-launch', value),
|
||||
setBadgeCount: count => ipc.send('set-badge-count', count),
|
||||
setMenuBarVisibility: visibility =>
|
||||
ipc.send('set-menu-bar-visibility', visibility),
|
||||
showDebugLog: () => {
|
||||
log.info('showDebugLog');
|
||||
ipc.send('show-debug-log');
|
||||
},
|
||||
showPermissionsPopup: (forCalling, forCamera) =>
|
||||
ipc.invoke('show-permissions-popup', forCalling, forCamera),
|
||||
showSettings: () => ipc.send('show-settings'),
|
||||
showWindow: () => {
|
||||
log.info('show window');
|
||||
ipc.send('show-window');
|
||||
},
|
||||
shutdown: () => {
|
||||
log.info('shutdown');
|
||||
ipc.send('shutdown');
|
||||
},
|
||||
titleBarDoubleClick: () => {
|
||||
ipc.send('title-bar-double-click');
|
||||
},
|
||||
updateSystemTraySetting: (
|
||||
systemTraySetting /* : Readonly<SystemTraySetting> */
|
||||
) => {
|
||||
void ipc.invoke('update-system-tray-setting', systemTraySetting);
|
||||
},
|
||||
updateTrayIcon: unreadCount => ipc.send('update-tray-icon', unreadCount),
|
||||
};
|
||||
|
||||
window.IPC = IPC;
|
||||
|
||||
window.isBeforeVersion = (toCheck, baseVersion) => {
|
||||
try {
|
||||
return semver.lt(toCheck, baseVersion);
|
||||
@@ -108,8 +174,6 @@ window.isAfterVersion = (toCheck, baseVersion) => {
|
||||
}
|
||||
};
|
||||
|
||||
window.setBadgeCount = count => ipc.send('set-badge-count', count);
|
||||
|
||||
let preloadConnectTime = 0;
|
||||
window.logAuthenticatedConnect = () => {
|
||||
if (preloadConnectTime === 0) {
|
||||
@@ -117,13 +181,6 @@ window.logAuthenticatedConnect = () => {
|
||||
}
|
||||
};
|
||||
|
||||
window.logAppLoadedEvent = ({ processedCount }) =>
|
||||
ipc.send('signal-app-loaded', {
|
||||
preloadTime: window.preloadEndTime - window.preloadStartTime,
|
||||
connectTime: preloadConnectTime - window.preloadEndTime,
|
||||
processedCount,
|
||||
});
|
||||
|
||||
// We never do these in our code, so we'll prevent it everywhere
|
||||
window.open = () => null;
|
||||
|
||||
@@ -133,50 +190,6 @@ if (!config.enableCI && config.environment !== 'test') {
|
||||
window.eval = global.eval = () => null;
|
||||
}
|
||||
|
||||
window.drawAttention = () => {
|
||||
log.info('draw attention');
|
||||
ipc.send('draw-attention');
|
||||
};
|
||||
window.showWindow = () => {
|
||||
log.info('show window');
|
||||
ipc.send('show-window');
|
||||
};
|
||||
|
||||
window.titleBarDoubleClick = () => {
|
||||
ipc.send('title-bar-double-click');
|
||||
};
|
||||
|
||||
window.setAutoHideMenuBar = autoHide =>
|
||||
ipc.send('set-auto-hide-menu-bar', autoHide);
|
||||
|
||||
window.setMenuBarVisibility = visibility =>
|
||||
ipc.send('set-menu-bar-visibility', visibility);
|
||||
|
||||
window.updateSystemTraySetting = (
|
||||
systemTraySetting /* : Readonly<SystemTraySetting> */
|
||||
) => {
|
||||
void ipc.invoke('update-system-tray-setting', systemTraySetting);
|
||||
};
|
||||
|
||||
window.restart = () => {
|
||||
log.info('restart');
|
||||
ipc.send('restart');
|
||||
};
|
||||
window.shutdown = () => {
|
||||
log.info('shutdown');
|
||||
ipc.send('shutdown');
|
||||
};
|
||||
window.showDebugLog = () => {
|
||||
log.info('showDebugLog');
|
||||
ipc.send('show-debug-log');
|
||||
};
|
||||
|
||||
window.closeAbout = () => ipc.send('close-about');
|
||||
window.readyForUpdates = () => ipc.send('ready-for-updates');
|
||||
|
||||
window.updateTrayIcon = unreadCount =>
|
||||
ipc.send('update-tray-icon', unreadCount);
|
||||
|
||||
ipc.on('additional-log-data-request', async event => {
|
||||
const ourConversation = window.ConversationController.getOurConversation();
|
||||
const ourCapabilities = ourConversation
|
||||
@@ -238,10 +251,14 @@ ipc.on('power-channel:lock-screen', () => {
|
||||
});
|
||||
|
||||
ipc.on('window:set-window-stats', (_event, stats) => {
|
||||
if (!window.Whisper.events) {
|
||||
if (!window.reduxActions) {
|
||||
return;
|
||||
}
|
||||
window.Whisper.events.trigger('setWindowStats', stats);
|
||||
|
||||
window.reduxActions.user.userChanged({
|
||||
isMainWindowMaximized: stats.isMaximized,
|
||||
isMainWindowFullScreen: stats.isFullScreen,
|
||||
});
|
||||
});
|
||||
|
||||
ipc.on('window:set-menu-options', (_event, options) => {
|
||||
@@ -253,28 +270,8 @@ ipc.on('window:set-menu-options', (_event, options) => {
|
||||
|
||||
window.sendChallengeRequest = request => ipc.send('challenge:request', request);
|
||||
|
||||
{
|
||||
let isFullScreen = Boolean(config.isMainWindowFullScreen);
|
||||
let isMaximized = Boolean(config.isMainWindowMaximized);
|
||||
|
||||
window.isFullScreen = () => isFullScreen;
|
||||
window.isMaximized = () => isMaximized;
|
||||
// This is later overwritten.
|
||||
window.onFullScreenChange = noop;
|
||||
|
||||
ipc.on('window:set-window-stats', (_event, stats) => {
|
||||
isFullScreen = Boolean(stats.isFullScreen);
|
||||
isMaximized = Boolean(stats.isMaximized);
|
||||
window.onFullScreenChange(isFullScreen, isMaximized);
|
||||
});
|
||||
}
|
||||
|
||||
// Settings-related events
|
||||
|
||||
window.showSettings = () => ipc.send('show-settings');
|
||||
window.showPermissionsPopup = (forCalling, forCamera) =>
|
||||
ipc.invoke('show-permissions-popup', forCalling, forCamera);
|
||||
|
||||
ipc.on('show-keyboard-shortcuts', () => {
|
||||
window.Events.showKeyboardShortcuts();
|
||||
});
|
||||
@@ -285,18 +282,6 @@ ipc.on('remove-dark-overlay', () => {
|
||||
window.Events.removeDarkOverlay();
|
||||
});
|
||||
|
||||
window.getBuiltInImages = () =>
|
||||
new Promise((resolve, reject) => {
|
||||
ipc.once('get-success-built-in-images', (_event, error, value) => {
|
||||
if (error) {
|
||||
return reject(new Error(error));
|
||||
}
|
||||
|
||||
return resolve(value);
|
||||
});
|
||||
ipc.send('get-built-in-images');
|
||||
});
|
||||
|
||||
ipc.on('delete-all-data', async () => {
|
||||
const { deleteAllData } = window.Events;
|
||||
if (!deleteAllData) {
|
||||
@@ -373,6 +358,3 @@ ipc.on('show-release-notes', () => {
|
||||
showReleaseNotes();
|
||||
}
|
||||
});
|
||||
|
||||
window.addSetupMenuItems = () => ipc.send('add-setup-menu-items');
|
||||
window.removeSetupMenuItems = () => ipc.send('remove-setup-menu-items');
|
||||
|
@@ -9,7 +9,6 @@ import * as moment from 'moment';
|
||||
import 'moment/min/locales.min';
|
||||
|
||||
import { textsecure } from '../../textsecure';
|
||||
import { imageToBlurHash } from '../../util/imageToBlurHash';
|
||||
import * as Attachments from '../attachments';
|
||||
import { setup } from '../../signal';
|
||||
import { addSensitivePath } from '../../util/privacy';
|
||||
@@ -38,7 +37,6 @@ window.WebAPI = window.textsecure.WebAPI.initialize({
|
||||
version: config.version,
|
||||
});
|
||||
|
||||
window.imageToBlurHash = imageToBlurHash;
|
||||
window.libphonenumberInstance = PhoneNumberUtil.getInstance();
|
||||
window.libphonenumberFormat = PhoneNumberFormat;
|
||||
|
||||
@@ -56,12 +54,14 @@ moment.updateLocale(locale, {
|
||||
moment.locale(locale);
|
||||
|
||||
const userDataPath = SignalContext.getPath('userData');
|
||||
window.baseAttachmentsPath = Attachments.getPath(userDataPath);
|
||||
window.baseStickersPath = Attachments.getStickersPath(userDataPath);
|
||||
window.baseTempPath = Attachments.getTempPath(userDataPath);
|
||||
window.baseDraftPath = Attachments.getDraftPath(userDataPath);
|
||||
window.BasePaths = {
|
||||
attachments: Attachments.getPath(userDataPath),
|
||||
draft: Attachments.getDraftPath(userDataPath),
|
||||
stickers: Attachments.getStickersPath(userDataPath),
|
||||
temp: Attachments.getTempPath(userDataPath),
|
||||
};
|
||||
|
||||
addSensitivePath(window.baseAttachmentsPath);
|
||||
addSensitivePath(window.BasePaths.attachments);
|
||||
if (config.crashDumpsPath) {
|
||||
addSensitivePath(config.crashDumpsPath);
|
||||
}
|
||||
|
@@ -13,6 +13,6 @@ if (config.environment === 'test') {
|
||||
}
|
||||
if (config.enableCI) {
|
||||
console.log('Importing CI infrastructure...');
|
||||
const { CI } = require('../../CI');
|
||||
window.CI = new CI(window.getTitle());
|
||||
const { getCI } = require('../../CI');
|
||||
window.Signal.CI = getCI(window.getTitle());
|
||||
}
|
||||
|
@@ -1,13 +1,23 @@
|
||||
// Copyright 2017 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { clone } from 'lodash';
|
||||
import { contextBridge } from 'electron';
|
||||
|
||||
import * as log from '../../logging/log';
|
||||
import { SignalContext } from '../context';
|
||||
|
||||
import './phase1-ipc';
|
||||
import '../preload';
|
||||
import './phase2-dependencies';
|
||||
import './phase3-post-signal';
|
||||
import './phase4-test';
|
||||
import '../../backbone/reliable_trigger';
|
||||
|
||||
import { WebAudioRecorder } from '../../WebAudioRecorder';
|
||||
import { getSignalProtocolStore } from '../../SignalProtocolStore';
|
||||
import { start as startConversationController } from '../../ConversationController';
|
||||
import { MessageController } from '../../util/MessageController';
|
||||
|
||||
window.addEventListener('contextmenu', e => {
|
||||
const node = e.target as Element | null;
|
||||
@@ -27,3 +37,122 @@ window.addEventListener('contextmenu', e => {
|
||||
if (window.SignalContext.config.proxyUrl) {
|
||||
log.info('Using provided proxy url');
|
||||
}
|
||||
|
||||
const isTestElectron = process.env.TEST_QUIT_ON_COMPLETE;
|
||||
|
||||
window.Whisper.events = clone(window.Backbone.Events);
|
||||
MessageController.install();
|
||||
startConversationController();
|
||||
|
||||
if (isTestElectron) {
|
||||
window.getSignalProtocolStore = getSignalProtocolStore;
|
||||
} else {
|
||||
contextBridge.exposeInMainWorld('SignalContext', SignalContext);
|
||||
|
||||
contextBridge.exposeInMainWorld('Backbone', window.Backbone);
|
||||
|
||||
contextBridge.exposeInMainWorld('BasePaths', window.BasePaths);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'ConversationController',
|
||||
window.ConversationController
|
||||
);
|
||||
contextBridge.exposeInMainWorld('Events', window.Events);
|
||||
contextBridge.exposeInMainWorld('Flags', window.Flags);
|
||||
contextBridge.exposeInMainWorld('IPC', window.IPC);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'SignalProtocolStore',
|
||||
window.SignalProtocolStore
|
||||
);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'getSignalProtocolStore',
|
||||
getSignalProtocolStore
|
||||
);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'MessageController',
|
||||
window.MessageController
|
||||
);
|
||||
contextBridge.exposeInMainWorld('WebAudioRecorder', WebAudioRecorder);
|
||||
contextBridge.exposeInMainWorld('WebAPI', window.WebAPI);
|
||||
contextBridge.exposeInMainWorld('Whisper', window.Whisper);
|
||||
contextBridge.exposeInMainWorld('i18n', window.i18n);
|
||||
contextBridge.exposeInMainWorld('reduxActions', window.reduxActions);
|
||||
contextBridge.exposeInMainWorld('reduxStore', window.reduxStore);
|
||||
contextBridge.exposeInMainWorld('startApp', window.startApp);
|
||||
contextBridge.exposeInMainWorld('textsecure', window.textsecure);
|
||||
|
||||
// TODO DESKTOP-4801
|
||||
contextBridge.exposeInMainWorld('ROOT_PATH', window.ROOT_PATH);
|
||||
contextBridge.exposeInMainWorld('Signal', window.Signal);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'enterKeyboardMode',
|
||||
window.enterKeyboardMode
|
||||
);
|
||||
contextBridge.exposeInMainWorld('enterMouseMode', window.enterMouseMode);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'getAccountManager',
|
||||
window.getAccountManager
|
||||
);
|
||||
contextBridge.exposeInMainWorld('getAppInstance', window.getAppInstance);
|
||||
contextBridge.exposeInMainWorld('getBuildCreation', window.getBuildCreation);
|
||||
contextBridge.exposeInMainWorld('getConversations', window.getConversations);
|
||||
contextBridge.exposeInMainWorld('getEnvironment', window.getEnvironment);
|
||||
contextBridge.exposeInMainWorld('getExpiration', window.getExpiration);
|
||||
contextBridge.exposeInMainWorld('getHostName', window.getHostName);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'getInteractionMode',
|
||||
window.getInteractionMode
|
||||
);
|
||||
contextBridge.exposeInMainWorld('getLocale', window.getLocale);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'getServerPublicParams',
|
||||
window.getServerPublicParams
|
||||
);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'getServerTrustRoot',
|
||||
window.getServerTrustRoot
|
||||
);
|
||||
contextBridge.exposeInMainWorld('getSfuUrl', window.getSfuUrl);
|
||||
contextBridge.exposeInMainWorld('getSocketStatus', window.getSocketStatus);
|
||||
contextBridge.exposeInMainWorld('getSyncRequest', window.getSyncRequest);
|
||||
contextBridge.exposeInMainWorld('getTitle', window.getTitle);
|
||||
contextBridge.exposeInMainWorld('getVersion', window.getVersion);
|
||||
contextBridge.exposeInMainWorld('initialTheme', window.initialTheme);
|
||||
contextBridge.exposeInMainWorld('isAfterVersion', window.isAfterVersion);
|
||||
contextBridge.exposeInMainWorld('isBeforeVersion', window.isBeforeVersion);
|
||||
contextBridge.exposeInMainWorld('isBehindProxy', window.isBehindProxy);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'libphonenumberFormat',
|
||||
window.libphonenumberFormat
|
||||
);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'libphonenumberInstance',
|
||||
window.libphonenumberInstance
|
||||
);
|
||||
contextBridge.exposeInMainWorld('localeMessages', window.localeMessages);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'logAuthenticatedConnect',
|
||||
window.logAuthenticatedConnect
|
||||
);
|
||||
contextBridge.exposeInMainWorld('nodeSetImmediate', window.nodeSetImmediate);
|
||||
contextBridge.exposeInMainWorld('platform', window.platform);
|
||||
contextBridge.exposeInMainWorld('preloadedImages', window.preloadedImages);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'sendChallengeRequest',
|
||||
window.sendChallengeRequest
|
||||
);
|
||||
contextBridge.exposeInMainWorld('setImmediate', window.setImmediate);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'showKeyboardShortcuts',
|
||||
window.showKeyboardShortcuts
|
||||
);
|
||||
contextBridge.exposeInMainWorld('storage', window.storage);
|
||||
contextBridge.exposeInMainWorld('systemTheme', window.systemTheme);
|
||||
contextBridge.exposeInMainWorld(
|
||||
'waitForEmptyEventQueue',
|
||||
window.waitForEmptyEventQueue
|
||||
);
|
||||
|
||||
contextBridge.exposeInMainWorld('assert', window.assert);
|
||||
contextBridge.exposeInMainWorld('RETRY_DELAY', window.RETRY_DELAY);
|
||||
contextBridge.exposeInMainWorld('testUtilities', window.testUtilities);
|
||||
}
|
||||
|
@@ -1,8 +1,6 @@
|
||||
// Copyright 2017 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { ipcRenderer as ipc } from 'electron';
|
||||
|
||||
import { installCallback, installSetting } from '../util/preload';
|
||||
|
||||
// ChatColorPicker redux hookups
|
||||
@@ -71,14 +69,3 @@ installCallback('getAvailableIODevices');
|
||||
installSetting('preferredAudioInputDevice');
|
||||
installSetting('preferredAudioOutputDevice');
|
||||
installSetting('preferredVideoInputDevice');
|
||||
|
||||
window.getMediaPermissions = () => ipc.invoke('settings:get:mediaPermissions');
|
||||
|
||||
window.getMediaCameraPermissions = () =>
|
||||
ipc.invoke('settings:get:mediaCameraPermissions');
|
||||
|
||||
window.crashReports = {
|
||||
getCount: () => ipc.invoke('crash-reports:get-count'),
|
||||
upload: () => ipc.invoke('crash-reports:upload'),
|
||||
erase: () => ipc.invoke('crash-reports:erase'),
|
||||
};
|
||||
|
Reference in New Issue
Block a user