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

[DevTools] upgrade electron to latest version & security improvements #26337

Merged
merged 3 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 8 additions & 34 deletions packages/react-devtools/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,28 +156,11 @@
</div>
</div>
<script>
const fs = require('fs');
let options;
let useHttps = false;
// window.api is defined in preload.js
const {electron, readEnv, ip, getDevTools} = window.api;
const {options, useHttps, host, protocol, port} = readEnv();

try {
if (process.env.KEY && process.env.CERT) {
options = {
key: fs.readFileSync(process.env.KEY),
cert: fs.readFileSync(process.env.CERT)
};
useHttps = true;
}
} catch (err) {
console.error('Failed to process SSL options - ', err);
options = undefined;
}

const {clipboard} = require("electron");
const host = process.env.HOST || 'localhost';
const protocol = useHttps ? 'https' : 'http';
const port = Number(process.env.PORT || 8097);
const localIp = require("ip").address();
const localIp = ip.address();
const defaultPort = (port === 443 && useHttps) || (port === 80 && !useHttps);
const server = defaultPort ? `${protocol}://${host}` : `${protocol}://${host}:${port}`;
const serverIp = defaultPort ? `${protocol}://${localIp}` : `${protocol}://${localIp}:${port}`;
Expand All @@ -193,7 +176,7 @@
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
clipboard.writeText(event.target.textContent);
electron.clipboard.writeText(event.target.textContent);

const $promptDiv = $("#box-content-prompt");
const $confirmationDiv = $("#box-content-confirmation");
Expand Down Expand Up @@ -221,7 +204,7 @@
const link = $('#rn-help-link');
link.addEventListener('click', event => {
event.preventDefault();
require('electron').shell.openExternal(link.href);
electron.shell.openExternal(link.href);
});

const $localhost = $("#localhost");
Expand All @@ -241,17 +224,8 @@
// Initially attach the listeners
attachListeners();

let devtools;
try {
devtools = require("react-devtools-core/standalone").default;
} catch (err) {
alert(
err.toString() +
"\n\nDid you run `yarn` and `yarn run build` in packages/react-devtools-core?"
);
}
window.devtools = devtools;
window.server = devtools
window.devtools = getDevTools();
window.server = window.devtools
.setContentDOMNode(document.getElementById("container"))
.setDisconnectedCallback(attachListeners)
.setStatusListener(function(status) {
Expand Down
6 changes: 4 additions & 2 deletions packages/react-devtools/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ app.on('ready', function () {
frame: false,
//titleBarStyle: 'customButtonsOnHover',
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
contextIsolation: true, // protect against prototype pollution
enableRemoteModule: false, // turn off remote
sandbox: false, // allow preload script to access file system
preload: join(__dirname, 'preload.js'), // use a preload script to expose node globals
},
});

Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"dependencies": {
"cross-spawn": "^5.0.1",
"electron": "^11.1.0",
"electron": "^23.1.2",
"ip": "^1.1.4",
"minimist": "^1.2.3",
"react-devtools-core": "4.27.2",
Expand Down
41 changes: 41 additions & 0 deletions packages/react-devtools/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const {clipboard, shell, contextBridge} = require('electron');
const fs = require('fs');
const {address} = require('ip');

// Expose protected methods so that render process does not need unsafe node integration
contextBridge.exposeInMainWorld('api', {
electron: {clipboard, shell},
ip: {address},
getDevTools() {
let devtools;
try {
devtools = require('react-devtools-core/standalone').default;
} catch (err) {
alert(
err.toString() +
'\n\nDid you run `yarn` and `yarn run build` in packages/react-devtools-core?',
);
}
return devtools;
},
readEnv() {
let options;
let useHttps = false;
try {
if (process.env.KEY && process.env.CERT) {
options = {
key: fs.readFileSync(process.env.KEY),
cert: fs.readFileSync(process.env.CERT),
};
useHttps = true;
}
} catch (err) {
console.error('Failed to process SSL options - ', err);
options = undefined;
}
const host = process.env.HOST || 'localhost';
const protocol = useHttps ? 'https' : 'http';
const port = +process.env.PORT || 8097;
return {options, useHttps, host, protocol, port};
},
});