Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Electron 15 #377

Merged
merged 9 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"@types/yargs": "^16.0.0",
"@yarnpkg/lockfile": "~1.1.0",
"css-loader": "~5.1.1",
"electron": "^14.0.0",
"electron": "^15.0.0",
"electron-builder": "^22.11.11",
"file-loader": "~6.2.0",
"fs-extra": "~9.1.0",
Expand Down
9 changes: 6 additions & 3 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,13 @@ app.on('ready', () => {
});

app.on("web-contents-created", (_event: any, webContents: WebContents) => {
// Prevent navigation
// Prevent navigation to local links
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krassowski do you have any concerns on these changes? any concerns navigating to external websites?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I am concerned. Wouldn't this lead to a context leak? Why is this change needed, again?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

during my testing, external domain urls were opened in popup windows and that is safe, so I thought we could enable it back. but if you think there are cases that require blocking external urls then I can update it to block. The original motivation for this change was the issue I mentioned in earlier comments: After switching to Classic notebooks and clicking on a notebook opens a blank window

webContents.on('will-navigate', (event: Event, navigationUrl) => {
console.warn(`Navigation is not allowed; attempted navigation to: ${navigationUrl}`);
event.preventDefault();
const jlabBaseUrl = `http://localhost:${appConfig.jlabPort}/`;
if (navigationUrl.startsWith(jlabBaseUrl) && navigationUrl.indexOf('#') !== -1) {
console.warn(`Navigation is not allowed; attempted navigation to: ${navigationUrl}`);
event.preventDefault();
}
});

// handle page's beforeunload prompt natively
Expand Down
39 changes: 39 additions & 0 deletions src/main/preload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// atob implementation below is modified from node.js source
// (https://github.com/nodejs/node/blob/master/lib/buffer.js)
// and copyright below is for it

// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

window.atob = (input): string => {
const kBase64Digits =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';

// remove whitespace
input = `${input}`.replace(/\s/g, "");
for (let n = 0; n < input.length; n++) {
if (!kBase64Digits.includes(input[n])) {
throw new DOMException('Invalid character', 'InvalidCharacterError');
}
}

return Buffer.from(input, 'base64').toString('latin1');
}
3 changes: 2 additions & 1 deletion src/main/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ class JupyterLabSession {
title: 'JupyterLab',
webPreferences: {
nodeIntegration: true,
contextIsolation: false
contextIsolation: false,
preload: path.join(__dirname, './preload.js'),
}
});

Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.6.tgz#d5e0706cf8c6acd8c6032f8d54070af261bbbb2f"
integrity sha512-ws57AidsDvREKrZKYffXddNkyaF14iHNHm8VQnZH6t99E8gczjNN0GpvcGny0imC80yQ0tHz1xVUKk/KFQSUyA==

"@electron/get@^1.0.1":
"@electron/get@^1.13.0":
version "1.13.1"
resolved "https://registry.yarnpkg.com/@electron/get/-/get-1.13.1.tgz#42a0aa62fd1189638bd966e23effaebb16108368"
integrity sha512-U5vkXDZ9DwXtkPqlB45tfYnnYBN8PePp1z/XDCupnSpdrxT8/ThCv9WCwPLf9oqiSGZTkH6dx2jDUPuoXpjkcA==
Expand Down Expand Up @@ -3364,12 +3364,12 @@ electron-to-chromium@^1.4.17:
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.24.tgz#9cf8a92d5729c480ee47ff0aa5555f57467ae2fa"
integrity sha512-erwx5r69B/WFfFuF2jcNN0817BfDBdC4765kQ6WltOMuwsimlQo3JTEq0Cle+wpHralwdeX3OfAtw/mHxPK0Wg==

electron@^14.0.0:
version "14.2.3"
resolved "https://registry.yarnpkg.com/electron/-/electron-14.2.3.tgz#3facf572c57cefe8ce80154ad3e63f937784644b"
integrity sha512-7wBqvzUKhK1tw544w3+F8J7NajnqURGC4pH3VFTiBHU5ayiI/oaTTXJxyFLZ54zsR7xwon/3dYEVjIm2i68+Zg==
electron@^15.0.0:
version "15.3.4"
resolved "https://registry.yarnpkg.com/electron/-/electron-15.3.4.tgz#811e8872f4500b88ad49e005cbe8f93e10676f6d"
integrity sha512-GLTE+UEKw1pJehkgpLgXtsHhYqSPp6skSNY1bxnY3dDYBrsPlP3nTEO9YQY2p4eHk+uxFVTXOVy5afcu9fIZ9A==
dependencies:
"@electron/get" "^1.0.1"
"@electron/get" "^1.13.0"
"@types/node" "^14.6.2"
extract-zip "^1.0.3"

Expand Down