ELECTRON-485 (Add throttle of 1 sec for activate, bringToFront and setLocale to prevent DoS attacks) (#414)

- Add throttle of 1 sec for activate, bringToFront and setLocale to prevent DoS attacks
- Skip resize Spectron test case for Mac
This commit is contained in:
Kiran Niranjan
2018-07-09 13:29:47 +05:30
committed by Vishwas Shashidhar
parent cc39f43ee7
commit a18f3eb64c
2 changed files with 35 additions and 18 deletions

View File

@@ -77,6 +77,28 @@ local.ipcRenderer.on('on-page-load', () => {
snackBar = new SnackBar();
});
const throttledActivate = throttle(1000, function(windowName) {
local.ipcRenderer.send(apiName, {
cmd: apiCmds.activate,
windowName: windowName
});
});
const throttledBringToFront = throttle(1000, function(windowName, reason) {
local.ipcRenderer.send(apiName, {
cmd: apiCmds.bringToFront,
windowName: windowName,
reason: reason
});
});
const throttledSetLocale = throttle(1000, function(locale) {
local.ipcRenderer.send(apiName, {
cmd: apiCmds.setLocale,
locale,
});
});
// Gathers renderer process memory
setInterval(() => {
const memory = process.getProcessMemoryInfo();
@@ -170,10 +192,9 @@ function createAPI() {
* @param {String} windowName Name of window. Note: main window name is 'main'
*/
activate: function(windowName) {
local.ipcRenderer.send(apiName, {
cmd: apiCmds.activate,
windowName: windowName
});
if (typeof windowName === 'string') {
throttledActivate(windowName);
}
},
/**
@@ -182,11 +203,9 @@ function createAPI() {
* @param {String} reason, The reason for which the window is to be activated
*/
bringToFront: function(windowName, reason) {
local.ipcRenderer.send(apiName, {
cmd: apiCmds.bringToFront,
windowName: windowName,
reason: reason
});
if (typeof windowName === 'string') {
throttledBringToFront(windowName, reason);
}
},
/**
@@ -318,10 +337,9 @@ function createAPI() {
* Ex: en-US, ja-JP
*/
setLocale: function (locale) {
local.ipcRenderer.send(apiName, {
cmd: apiCmds.setLocale,
locale,
});
if (typeof locale === 'string') {
throttledSetLocale(locale);
}
}
};