aboutsummaryrefslogtreecommitdiffstats
path: root/src/models
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-07-24 02:23:48 +0200
committerLibravatar GitHub <noreply@github.com>2021-07-24 02:23:48 +0200
commit9c3c441941ad5060ec2db89b805a958a914547f3 (patch)
treea4224d7bd2576797b14a2ffa1d25ba6e167351ae /src/models
parentUpdate submodules, browserslist data updates and linter fixes [skip ci] (diff)
downloadferdium-app-9c3c441941ad5060ec2db89b805a958a914547f3.tar.gz
ferdium-app-9c3c441941ad5060ec2db89b805a958a914547f3.tar.zst
ferdium-app-9c3c441941ad5060ec2db89b805a958a914547f3.zip
Recipe context isolation (#1456)
* Enable service contextIsolation * Enable contextIsolation on the service webviews * Expose a new API window.ferdi in the service main world to allow calling back into the service isolated world * Expose a new IPC message inject-js-unsafe from the service isolated world to execute Javascript in the service main world (i.e., run code without context isolation). While the name contains the "unsafe" suffix to show the lack of context isolation, this should mostly be safe, as no nodejs APIs are available in the injected code. * Refactor the Notifications shim into a part in the isolated world that handles displaying and modifying notifications, and a shim in the main world for the Notifications class. The two communicate via the window.ferdi endpoint and a Promise object can be used to detect notification clicks. * Refactor the screen sharing shim into a part in the isolated world that enumerated shareable screens and windows and a shim in the main world that displays the media selector and completes the media selection promise. * Expose the injectJSUnsafe API to recipes to inject javascript code into the main world without context isolation. * Expose setBadge to the main world The window.ferdi.setBadge API can be used to update the service badge from injected unsafe Javascript * Safer script injection into the service main world Make sure that we don't try to serialize stray objects back from the main world to the isolated world by always surrounding the script to be executed by an anonymous function. * Always read recipe assets as utf8 * Remove window.log from recipes We didn't use it anywhere and its behavior was confusing in production mode. * Inject multiple unsafe scripts at the same time * Find in page without remote module Remove the @electron/remote dependency from the find in page (Ctrl+F) functionality. The remote webContents is replaced with Electron IPC. Synchronous IPC messages are handled in the main Electron process, because the renderer process cannot reply to IPC messages synchronously. * Update to latest contextIsolation recipes * Fixing issue with missing 'fs' functions. Co-authored-by: Vijay A <avijayr@protonmail.com>
Diffstat (limited to 'src/models')
-rw-r--r--src/models/Service.js21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/models/Service.js b/src/models/Service.js
index 74e100ea4..36b310da1 100644
--- a/src/models/Service.js
+++ b/src/models/Service.js
@@ -275,11 +275,17 @@ export default class Service {
275 debug(this.name, 'modifyRequestHeaders is not defined in the recipe'); 275 debug(this.name, 'modifyRequestHeaders is not defined in the recipe');
276 } 276 }
277 277
278 this.webview.addEventListener('ipc-message', e => handleIPCMessage({ 278 this.webview.addEventListener('ipc-message', async (e) => {
279 serviceId: this.id, 279 if (e.channel === 'inject-js-unsafe') {
280 channel: e.channel, 280 await Promise.all(e.args.map(script => this.webview.executeJavaScript(`"use strict"; (() => { ${script} })();`)));
281 args: e.args, 281 } else {
282 })); 282 handleIPCMessage({
283 serviceId: this.id,
284 channel: e.channel,
285 args: e.args,
286 });
287 }
288 });
283 289
284 this.webview.addEventListener('new-window', (event, url, frameName, options) => { 290 this.webview.addEventListener('new-window', (event, url, frameName, options) => {
285 debug('new-window', event, url, frameName, options); 291 debug('new-window', event, url, frameName, options);
@@ -334,6 +340,11 @@ export default class Service {
334 this.hasCrashed = true; 340 this.hasCrashed = true;
335 }); 341 });
336 342
343 this.webview.addEventListener('found-in-page', ({ result }) => {
344 debug('Found in page', result);
345 this.webview.send('found-in-page', result);
346 });
347
337 webviewWebContents.on('login', (event, request, authInfo, callback) => { 348 webviewWebContents.on('login', (event, request, authInfo, callback) => {
338 // const authCallback = callback; 349 // const authCallback = callback;
339 debug('browser login event', authInfo); 350 debug('browser login event', authInfo);