[MM-59543] Disallow use of file: protocol in the app, remove all references to it, add mattermost-desktop: protocol to read local files (#3095)
This commit is contained in:
@@ -12,7 +12,6 @@ import {DownloadsDropdownMenuView} from './downloadsDropdownMenuView';
|
||||
|
||||
jest.mock('main/utils', () => ({
|
||||
getLocalPreload: (file) => file,
|
||||
getLocalURLString: (file) => file,
|
||||
}));
|
||||
jest.mock('electron', () => {
|
||||
class NotificationMock {
|
||||
|
@@ -27,7 +27,7 @@ import {
|
||||
TAB_BAR_HEIGHT,
|
||||
} from 'common/utils/constants';
|
||||
import downloadsManager from 'main/downloadsManager';
|
||||
import {getLocalPreload, getLocalURLString} from 'main/utils';
|
||||
import {getLocalPreload} from 'main/utils';
|
||||
import MainWindow from 'main/windows/mainWindow';
|
||||
|
||||
import type {CoordinatesToJsonType, DownloadedItem, DownloadsMenuOpenEventPayload} from 'types/downloads';
|
||||
@@ -75,7 +75,7 @@ export class DownloadsDropdownMenuView {
|
||||
// @ts-ignore
|
||||
transparent: true,
|
||||
}});
|
||||
this.view.webContents.loadURL(getLocalURLString('downloadsDropdownMenu.html'));
|
||||
this.view.webContents.loadURL('mattermost-desktop://renderer/downloadsDropdownMenu.html');
|
||||
MainWindow.get()?.addBrowserView(this.view);
|
||||
};
|
||||
|
||||
|
@@ -12,7 +12,6 @@ import {DownloadsDropdownView} from './downloadsDropdownView';
|
||||
|
||||
jest.mock('main/utils', () => ({
|
||||
getLocalPreload: (file) => file,
|
||||
getLocalURLString: (file) => file,
|
||||
}));
|
||||
jest.mock('fs', () => ({
|
||||
existsSync: jest.fn().mockReturnValue(false),
|
||||
|
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import type {IpcMainEvent, IpcMainInvokeEvent} from 'electron';
|
||||
import type {IpcMainEvent} from 'electron';
|
||||
import {BrowserView, ipcMain} from 'electron';
|
||||
|
||||
import {
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
REQUEST_DOWNLOADS_DROPDOWN_INFO,
|
||||
UPDATE_DOWNLOADS_DROPDOWN,
|
||||
UPDATE_DOWNLOADS_DROPDOWN_MENU_ITEM,
|
||||
GET_DOWNLOADED_IMAGE_THUMBNAIL_LOCATION,
|
||||
DOWNLOADS_DROPDOWN_OPEN_FILE,
|
||||
MAIN_WINDOW_CREATED,
|
||||
MAIN_WINDOW_RESIZED,
|
||||
@@ -22,7 +21,7 @@ import Config from 'common/config';
|
||||
import {Logger} from 'common/log';
|
||||
import {TAB_BAR_HEIGHT, DOWNLOADS_DROPDOWN_WIDTH, DOWNLOADS_DROPDOWN_HEIGHT, DOWNLOADS_DROPDOWN_FULL_WIDTH} from 'common/utils/constants';
|
||||
import downloadsManager from 'main/downloadsManager';
|
||||
import {getLocalPreload, getLocalURLString} from 'main/utils';
|
||||
import {getLocalPreload} from 'main/utils';
|
||||
import MainWindow from 'main/windows/mainWindow';
|
||||
|
||||
import type {DownloadedItem} from 'types/downloads';
|
||||
@@ -47,7 +46,6 @@ export class DownloadsDropdownView {
|
||||
ipcMain.on(DOWNLOADS_DROPDOWN_OPEN_FILE, this.openFile);
|
||||
ipcMain.on(UPDATE_DOWNLOADS_DROPDOWN, this.updateDownloadsDropdown);
|
||||
ipcMain.on(UPDATE_DOWNLOADS_DROPDOWN_MENU_ITEM, this.updateDownloadsDropdownMenuItem);
|
||||
ipcMain.handle(GET_DOWNLOADED_IMAGE_THUMBNAIL_LOCATION, this.getDownloadImageThumbnailLocation);
|
||||
}
|
||||
|
||||
init = () => {
|
||||
@@ -67,7 +65,7 @@ export class DownloadsDropdownView {
|
||||
transparent: true,
|
||||
}});
|
||||
|
||||
this.view.webContents.loadURL(getLocalURLString('downloadsDropdown.html'));
|
||||
this.view.webContents.loadURL('mattermost-desktop://renderer/downloadsDropdown.html');
|
||||
this.view.webContents.session.webRequest.onHeadersReceived(downloadsManager.webRequestOnHeadersReceivedHandler);
|
||||
MainWindow.get()?.addBrowserView(this.view);
|
||||
};
|
||||
@@ -183,10 +181,6 @@ export class DownloadsDropdownView {
|
||||
this.view?.setBounds(this.bounds);
|
||||
}
|
||||
};
|
||||
|
||||
private getDownloadImageThumbnailLocation = (event: IpcMainInvokeEvent, location: string) => {
|
||||
return location;
|
||||
};
|
||||
}
|
||||
|
||||
const downloadsDropdownView = new DownloadsDropdownView();
|
||||
|
@@ -5,7 +5,7 @@ import {BrowserView, app, ipcMain} from 'electron';
|
||||
|
||||
import {DARK_MODE_CHANGE, LOADING_SCREEN_ANIMATION_FINISHED, MAIN_WINDOW_RESIZED, TOGGLE_LOADING_SCREEN_VISIBILITY} from 'common/communication';
|
||||
import {Logger} from 'common/log';
|
||||
import {getLocalPreload, getLocalURLString, getWindowBoundaries} from 'main/utils';
|
||||
import {getLocalPreload, getWindowBoundaries} from 'main/utils';
|
||||
import MainWindow from 'main/windows/mainWindow';
|
||||
|
||||
enum LoadingScreenState {
|
||||
@@ -85,7 +85,7 @@ export class LoadingScreen {
|
||||
// @ts-ignore
|
||||
transparent: true,
|
||||
}});
|
||||
const localURL = getLocalURLString('loadingScreen.html');
|
||||
const localURL = 'mattermost-desktop://renderer/loadingScreen.html';
|
||||
this.view.webContents.loadURL(localURL);
|
||||
};
|
||||
|
||||
|
@@ -12,7 +12,6 @@ jest.mock('app/serverViewState', () => ({}));
|
||||
|
||||
jest.mock('main/utils', () => ({
|
||||
getLocalPreload: (file) => file,
|
||||
getLocalURLString: (file) => file,
|
||||
}));
|
||||
|
||||
jest.mock('electron', () => ({
|
||||
|
@@ -22,7 +22,7 @@ import Config from 'common/config';
|
||||
import {Logger} from 'common/log';
|
||||
import ServerManager from 'common/servers/serverManager';
|
||||
import {TAB_BAR_HEIGHT, THREE_DOT_MENU_WIDTH, THREE_DOT_MENU_WIDTH_MAC, MENU_SHADOW_WIDTH} from 'common/utils/constants';
|
||||
import {getLocalPreload, getLocalURLString} from 'main/utils';
|
||||
import {getLocalPreload} from 'main/utils';
|
||||
|
||||
import type {UniqueServer} from 'types/config';
|
||||
|
||||
@@ -83,7 +83,7 @@ export class ServerDropdownView {
|
||||
// @ts-ignore
|
||||
transparent: true,
|
||||
}});
|
||||
this.view.webContents.loadURL(getLocalURLString('dropdown.html'));
|
||||
this.view.webContents.loadURL('mattermost-desktop://renderer/dropdown.html');
|
||||
|
||||
this.setOrderedServers();
|
||||
this.windowBounds = MainWindow.getBounds();
|
||||
|
@@ -52,7 +52,7 @@ import LoadingScreen from './loadingScreen';
|
||||
import {MattermostBrowserView} from './MattermostBrowserView';
|
||||
import modalManager from './modalManager';
|
||||
|
||||
import {getLocalURLString, getLocalPreload, getAdjustedWindowBoundaries, shouldHaveBackBar} from '../utils';
|
||||
import {getLocalPreload, getAdjustedWindowBoundaries, shouldHaveBackBar} from '../utils';
|
||||
|
||||
const log = new Logger('ViewManager');
|
||||
const URL_VIEW_DURATION = 10 * SECOND;
|
||||
@@ -354,8 +354,7 @@ export class ViewManager {
|
||||
// @ts-ignore
|
||||
transparent: true,
|
||||
}});
|
||||
const query = new Map([['url', urlString]]);
|
||||
const localURL = getLocalURLString('urlView.html', query);
|
||||
const localURL = `mattermost-desktop://renderer/urlView.html?url=${encodeURIComponent(urlString)}`;
|
||||
urlView.webContents.loadURL(localURL);
|
||||
MainWindow.get()?.addBrowserView(urlView);
|
||||
const boundaries = this.views.get(this.currentView || '')?.getBounds() ?? MainWindow.getBounds();
|
||||
|
Reference in New Issue
Block a user