mirror of
https://github.com/finos/SymphonyElectron.git
synced 2026-08-17 16:35:00 -05:00
ELECTRON-508 (Fix security issue with getSource and getSources) (#384)
- Fix security issue with getSource and getSources - Change method to get desktop sources - Fix lint issues
This commit is contained in:
committed by
Vishwas Shashidhar
parent
0a5c5ab193
commit
7ae769df7e
@@ -12,7 +12,7 @@
|
||||
// renderer process, this will have to do. See github issue posted here to
|
||||
// electron: https://github.com/electron/electron/issues/9312
|
||||
|
||||
const { ipcRenderer, remote } = require('electron');
|
||||
const { ipcRenderer, remote, desktopCapturer } = require('electron');
|
||||
const apiEnums = require('../enums/api.js');
|
||||
const apiCmds = apiEnums.cmds;
|
||||
const apiName = apiEnums.apiName;
|
||||
@@ -43,8 +43,10 @@ function isValid(options) {
|
||||
*/
|
||||
function getSource(options, callback) {
|
||||
let captureScreen, captureWindow, id;
|
||||
let sourceTypes = [];
|
||||
if (!isValid(options)) {
|
||||
return callback(new Error('Invalid options'));
|
||||
callback(new Error('Invalid options'));
|
||||
return;
|
||||
}
|
||||
captureWindow = includes.call(options.types, 'window');
|
||||
captureScreen = includes.call(options.types, 'screen');
|
||||
@@ -68,14 +70,24 @@ function getSource(options, callback) {
|
||||
captureWindow = remote.systemPreferences.isAeroGlassEnabled();
|
||||
}
|
||||
|
||||
id = getNextId();
|
||||
ipcRenderer.send('ELECTRON_BROWSER_DESKTOP_CAPTURER_GET_SOURCES', captureWindow, captureScreen, updatedOptions.thumbnailSize, id);
|
||||
if (captureWindow) {
|
||||
sourceTypes.push('window');
|
||||
}
|
||||
if (captureScreen) {
|
||||
sourceTypes.push('screen');
|
||||
}
|
||||
|
||||
return ipcRenderer.once('ELECTRON_RENDERER_DESKTOP_CAPTURER_RESULT_' + id, function(event, sources) {
|
||||
id = getNextId();
|
||||
desktopCapturer.getSources({ types: sourceTypes, thumbnailSize: updatedOptions.thumbnailSize }, (event, sources) => {
|
||||
const updatedSources = sources.map(source => {
|
||||
return Object.assign({}, source, {
|
||||
thumbnail: source.thumbnail.toDataURL()
|
||||
});
|
||||
});
|
||||
|
||||
ipcRenderer.send(apiName, {
|
||||
cmd: apiCmds.openScreenPickerWindow,
|
||||
sources: sources,
|
||||
sources: updatedSources,
|
||||
id: id
|
||||
});
|
||||
|
||||
|
||||
@@ -12,16 +12,11 @@
|
||||
// renderer process, this will have to do. See github issue posted here to
|
||||
// electron: https://github.com/electron/electron/issues/9312
|
||||
|
||||
const { ipcRenderer, remote } = require('electron');
|
||||
const { remote, desktopCapturer } = require('electron');
|
||||
const { isWindowsOS } = require('../utils/misc');
|
||||
|
||||
let nextId = 0;
|
||||
let includes = [].includes;
|
||||
|
||||
function getNextId() {
|
||||
return ++nextId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the options and their types are valid
|
||||
* @param options |options.type| can not be empty and has to include 'window' or 'screen'.
|
||||
@@ -38,9 +33,11 @@ function isValid(options) {
|
||||
* @returns {*}
|
||||
*/
|
||||
function getSources(options, callback) {
|
||||
let captureScreen, captureWindow, id;
|
||||
let captureScreen, captureWindow;
|
||||
let sourceTypes = [];
|
||||
if (!isValid(options)) {
|
||||
return callback(new Error('Invalid options'));
|
||||
callback(new Error('Invalid options'));
|
||||
return;
|
||||
}
|
||||
captureWindow = includes.call(options.types, 'window');
|
||||
captureScreen = includes.call(options.types, 'screen');
|
||||
@@ -63,11 +60,14 @@ function getSources(options, callback) {
|
||||
*/
|
||||
captureWindow = remote.systemPreferences.isAeroGlassEnabled();
|
||||
}
|
||||
if (captureWindow) {
|
||||
sourceTypes.push('window');
|
||||
}
|
||||
if (captureScreen) {
|
||||
sourceTypes.push('screen');
|
||||
}
|
||||
|
||||
id = getNextId();
|
||||
ipcRenderer.send('ELECTRON_BROWSER_DESKTOP_CAPTURER_GET_SOURCES', captureWindow, captureScreen, updatedOptions.thumbnailSize, id);
|
||||
|
||||
return ipcRenderer.once('ELECTRON_RENDERER_DESKTOP_CAPTURER_RESULT_' + id, function(event, sources) {
|
||||
desktopCapturer.getSources({ types: sourceTypes, thumbnailSize: updatedOptions.thumbnailSize }, (event, sources) => {
|
||||
let source;
|
||||
callback(null, (function() {
|
||||
let i, len, results;
|
||||
@@ -77,7 +77,7 @@ function getSources(options, callback) {
|
||||
results.push({
|
||||
id: source.id,
|
||||
name: source.name,
|
||||
thumbnail: source.thumbnail
|
||||
thumbnail: source.thumbnail.toDataURL()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user