Files
react/packages/react-devtools/preload.js
Ruslan Lesiutin 3730b40e9b chore[react-devtools]: ip => internal-ip (#29772)
## Summary

There was an attempt to upgrade `ip` to 2.0.1 to mitigate CVE in
https://github.com/facebook/react/pull/29725#issuecomment-2150389616,
but there actually another one CVE in version `2.0.1`. Instead, migrate
to `internal-ip`, which similarly small package that we can use

Note: not upgrading to version 7+, because they are pure ESM.

## How did you test this change?

Validated that standalone version of RDT works and connects to the app.
2024-06-05 19:58:12 +01:00

42 lines
1.2 KiB
JavaScript

const {clipboard, shell, contextBridge} = require('electron');
const fs = require('fs');
const internalIP = require('internal-ip');
// Expose protected methods so that render process does not need unsafe node integration
contextBridge.exposeInMainWorld('api', {
electron: {clipboard, shell},
ip: {address: internalIP.v4.sync},
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};
},
});