|
| 1 | +# Electron evil feature patcher |
| 2 | + |
| 3 | +Patches Electron to remove certain features from it, such as debugging flags, that can be used for evil. |
| 4 | + |
| 5 | +## Motivation |
| 6 | + |
| 7 | +Electron has great debugging support! Unfortunately this can be used not only while developing an app, but also after you built and packaged it. This way your app can be started in an unexpected way, for example, an attacker may want to pass `--inspect-brk` and execute code as if it was done by your app. |
| 8 | + |
| 9 | +Is this a concern in Electron? Yes and no. If your app is not dealing with secrets or if it's not codesigned, it's not an issue at all. However, if you would like to limit the code run under the identity of your app, it can be an issue. |
| 10 | + |
| 11 | +This is being addressed in Electron in form of so-called "fuses", run-time toggles that can be switched on and off: https://github.com/electron/electron/pull/24241. These features should be eventually "fuses" but I'm too lazy to contribute to Electron because the patches we need are located in interesting, hard-to-reach pieces of code, for example in node.js or Chromium. This is not fun to change! In this sense this solution, or should I say this dirty hack, is a short-lived thing. |
| 12 | + |
| 13 | +## Goals |
| 14 | + |
| 15 | +- disable certain feature flags |
| 16 | +- test on all supported operating systems |
| 17 | +- have it right now, not in a year |
| 18 | + |
| 19 | +## Non-goals |
| 20 | + |
| 21 | +- do it all in a nice way |
| 22 | +- support other features |
| 23 | +- provide a long-term solution |
| 24 | +- patch old Electron versions |
| 25 | + |
| 26 | +## Removed capabilities |
| 27 | + |
| 28 | +- [`--inspect-brk`](https://www.electronjs.org/docs/api/command-line-switches#--inspect-brkhostport) |
| 29 | +- [`--inspect-brk-node`](https://github.com/nodejs/node/blob/master/src/node_options.cc#L263) |
| 30 | +- [`--inspect-port`](https://www.electronjs.org/docs/api/command-line-switches#--inspect-porthostport) |
| 31 | +- [`--inspect`](https://www.electronjs.org/docs/api/command-line-switches#--inspecthostport) |
| 32 | +- [`--inspect-publish-uid`](https://www.electronjs.org/docs/api/command-line-switches#--inspect-publish-uidstderrhttp) |
| 33 | +- [`--remote-debugging-port`](https://www.electronjs.org/docs/api/command-line-switches#--remote-debugging-portport) |
| 34 | +- [`--js-flags`](https://www.electronjs.org/docs/api/command-line-switches#--js-flagsflags) |
| 35 | +- [`SIGUSR1`](https://nodejs.org/fr/docs/guides/debugging-getting-started/#enable-inspector) |
| 36 | +- [`ELECTRON_RUN_AS_NODE`](https://www.electronjs.org/docs/api/environment-variables#electron_run_as_node) |
| 37 | + |
| 38 | +## Usage |
| 39 | + |
| 40 | +Using the command line: |
| 41 | +```sh |
| 42 | +node electron-evil-feature-patcher your-app-path os |
| 43 | +``` |
| 44 | + |
| 45 | +For example: |
| 46 | +```sh |
| 47 | +node electron-evil-feature-patcher my.app darwin |
| 48 | +``` |
| 49 | + |
| 50 | +Using node.js: |
| 51 | +```js |
| 52 | +const patch = require('electron-evil-feature-patcher'); |
| 53 | +patch({ path: 'your-app-path', platfor: 'platform' }); |
| 54 | +``` |
| 55 | + |
| 56 | +For example: |
| 57 | +```js |
| 58 | +patch({ path: 'my.app', platform: process.platform }); |
| 59 | +``` |
| 60 | + |
| 61 | +Patching is done in-place, no backup is made. Second attempt to patch will result in an error. |
| 62 | + |
| 63 | +## License |
| 64 | + |
| 65 | +MIT |
0 commit comments