From b9b7d2c95d723bd1b27889f44e15c6ea177f8b4d Mon Sep 17 00:00:00 2001 From: Thomas Hirschberger <47733292+Tom-Hirschberger@users.noreply.github.com> Date: Mon, 7 Nov 2022 07:42:27 +0100 Subject: [PATCH] Add option to remove "x-frame-options" and "content-security-policy" response headers (#2963) Many users like me do have the problem that they want to embed other sites to their mirror by "iframe". As some developers set the "x-frame-options" and "content-security-policy" for security reasons these sites can not be embedded. Electron provides the "webview" element additionally to "iframe" which allows to embed these sites although. The main difference is that a new process is started which handles the "webview" element. BUT: As the "webview" process needs to be started and is isolated "webview" is slower and the elements can not be accessed from the embedding website. As an alternative i implemented a small callback function in electron.js which removes the response headers that forbid the embedding. The removing can be controlled with the new config options: * ignoreXOriginHeader * ignoreContentSecurityPolicy --- CHANGELOG.md | 1 + js/electron.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 516e499a..1effbc2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Special thanks to: @rejas, @sdetweil, @MagMar94 - Added css class names "today" and "tomorrow" for default calendar - Added Collaboration.md - Added new github action for dependency review (#2862) +- Added config options "ignoreXOriginHeader" and "ignoreContentSecurityPolicy" ### Removed diff --git a/js/electron.js b/js/electron.js index ffa48e6a..ac58657c 100644 --- a/js/electron.js +++ b/js/electron.js @@ -103,6 +103,20 @@ function createWindow() { }, 1000); }); } + + //remove response headers that prevent sites of being embedded into iframes if configured + mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => { + let curHeaders = details.responseHeaders; + if (config["ignoreXOriginHeader"] || false) { + curHeaders = Object.fromEntries(Object.entries(curHeaders).filter((header) => !/x-frame-options/i.test(header[0]))); + } + + if (config["ignoreContentSecurityPolicy"] || false) { + curHeaders = Object.fromEntries(Object.entries(curHeaders).filter((header) => !/content-security-policy/i.test(header[0]))); + } + + callback({ responseHeaders: curHeaders }); + }); } // This method will be called when Electron has finished