Skip to content

Commit e35b3ed

Browse files
committed
fix(ScreenSharingTracker) use a preload script
- Enable context isolation for this window - Add a preload script - Disable unnecessary Node integration - Sanitize query parameter handling
1 parent bed42c5 commit e35b3ed

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

screensharing/main.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const { exec } = require('child_process');
33
const electron = require('electron');
44
const os = require('os');
5+
const path = require('path');
56

67
const { SCREEN_SHARE_EVENTS_CHANNEL, SCREEN_SHARE_EVENTS, SCREEN_SHARE_GET_SOURCES, TRACKER_SIZE } = require('./constants');
78
const { isMac } = require('./utils');
@@ -95,7 +96,8 @@ class ScreenShareMainHook {
9596
}
9697

9798
// Display always on top screen sharing tracker window in the center bottom of the screen.
98-
let display = electron.screen.getPrimaryDisplay();
99+
const display = electron.screen.getPrimaryDisplay();
100+
99101
this._screenShareTracker = new electron.BrowserWindow({
100102
height: TRACKER_SIZE.height,
101103
width: TRACKER_SIZE.width,
@@ -112,10 +114,9 @@ class ScreenShareMainHook {
112114
frame: false,
113115
show: false,
114116
webPreferences: {
115-
// TODO: these 3 should be removed.
116-
contextIsolation: false,
117-
enableRemoteModule: true,
118-
nodeIntegration: true
117+
contextIsolation: true,
118+
nodeIntegration: false,
119+
preload: path.resolve(__dirname, './preload.js')
119120
}
120121
});
121122

screensharing/preload.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { contextBridge, ipcRenderer } = require('electron');
2+
3+
const { SCREEN_SHARE_EVENTS_CHANNEL, SCREEN_SHARE_EVENTS } = require('./constants');
4+
5+
contextBridge.exposeInMainWorld('JitsiScreenSharingTracker', {
6+
EVENTS: SCREEN_SHARE_EVENTS,
7+
sendEvent: ev => {
8+
if (Object.values(SCREEN_SHARE_EVENTS).includes(ev)) {
9+
ipcRenderer.send(SCREEN_SHARE_EVENTS_CHANNEL, {
10+
data: {
11+
name: ev
12+
}
13+
});
14+
}
15+
}
16+
});
Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,22 @@
1-
const { ipcRenderer } = require('electron');
2-
const querystring = require('querystring');
3-
4-
const { SCREEN_SHARE_EVENTS_CHANNEL, SCREEN_SHARE_EVENTS } = require('./constants');
5-
61
const screenShareStop = document.getElementById("screen-share-marker-stop");
72
const screenShareMinimize = document.getElementById("screen-share-marker-minimize");
83
const sharingIdentity = document.getElementById("sharing-identity");
94

10-
sharingIdentity.innerHTML = querystring.parse(global.location.search)['?sharingIdentity'];
5+
sharingIdentity.innerText = new URL(window.location).searchParams.get('sharingIdentity');
6+
7+
const { EVENTS, sendEvent } = window.JitsiScreenSharingTracker;
118

129
/**
1310
* Minimize the window.
1411
*/
1512
screenShareMinimize.addEventListener("click", function() {
16-
ipcRenderer.send(SCREEN_SHARE_EVENTS_CHANNEL, {
17-
data: {
18-
name: SCREEN_SHARE_EVENTS.HIDE_TRACKER
19-
}
20-
});
13+
sendEvent(EVENTS.HIDE_TRACKER);
2114
});
2215

2316
/**
2417
* When the user clicks the stop button, send a message that will eventually be processed by
2518
* {@link ScreenShareRenderHook} which will toggle the screen sharing session using the jitsi-meet api.
2619
*/
2720
screenShareStop.addEventListener("click", function() {
28-
ipcRenderer.send(SCREEN_SHARE_EVENTS_CHANNEL, {
29-
data: {
30-
name: SCREEN_SHARE_EVENTS.STOP_SCREEN_SHARE
31-
}
32-
});
21+
sendEvent(EVENTS.STOP_SCREEN_SHARE);
3322
});
34-

0 commit comments

Comments
 (0)