---
title: "Electron context-isolation RCE via internal code"
section: "Network Services"
sectionSlug: "network-services-pentesting"
sourcePath: "src/network-services-pentesting/pentesting-web/electron-desktop-apps/electron-contextisolation-rce-via-electron-internal-code.md"
sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/network-services-pentesting/pentesting-web/electron-desktop-apps/electron-contextisolation-rce-via-electron-internal-code.md"
sha: "188de82beb54e70956b2952367a0af91d26758b8"
isIndex: false
modified: true
license: "CC-BY-NC-4.0"
---
# Electron context-isolation RCE via internal code
These are **historical exploitation patterns** for Electron applications that ran untrusted renderer content without context isolation. Context isolation has been enabled by default since Electron 12 and remains a recommended security setting.[[1]](#references) Exact internals differ by Electron and Node.js version, so reproduce a chain against the target application's bundled versions.
## Example 1: overriding `Function.prototype.call`
This example comes from Masato Kinugawa's CureCon presentation.[[2]](#references)
In the affected historical Electron build, internal ASAR code registered a process `exit` listener. Because page code and Electron's internal code shared JavaScript prototypes when context isolation was disabled, renderer code could replace `Function.prototype.call` before the internal listener ran.[[2]](#references)[[3]](#references)
```javascript
process.on("exit", function () {
for (let p in cachedArchives) {
if (!hasProp.call(cachedArchives, p)) continue
cachedArchives[p].destroy()
}
})
```

The listener was dispatched through Node.js's event machinery. The original page linked a stale `bin/events.js` path; the same historical commit's live source is under `lib/events.js`.[[5]](#references)

In this path, `self` is Node.js's process object:

The historical process object exposed a path to `require`:
```text
process.mainModule.require
```
Because the listener dispatcher invoked the handler with the process object, overriding `call` could recover that object and execute a native command:
```html
```
## Example 2: prototype pollution
The ElectroVolt presentation demonstrates another historical chain that obtains a `require` object through prototype pollution.[[4]](#references)
Leak:
Exploit:
## References
- [1] [Electron documentation - Context isolation](https://www.electronjs.org/docs/latest/tutorial/context-isolation)
- [2] [Electron: Abusing the lack of context isolation - CureCon](https://speakerdeck.com/masatokinugawa/electron-abusing-the-lack-of-context-isolation-curecon-en?slide=41)
- [3] [Electron historical source - lib/common/asar.js](https://github.com/electron/electron/blob/664c184fcb98bb5b4b6b569553e7f7339d3ba4c5/lib/common/asar.js#L30-L36)
- [4] [ElectroVolt: Pwning Popular Desktop Apps While Uncovering New Attack Surface on Electron](https://www.youtube.com/watch?v=Tzo8ucHA5xw&list=PLH15HpR5qRsVKcKwvIl-AzGfRqKyx--zq&index=81)
- [5] [Node.js historical source - `lib/events.js` listener dispatch](https://github.com/nodejs/node/blob/8a44289089a08b7b19fa3c4651b5f1f5d1edd71b/lib/events.js#L156-L231)