You are currently viewing Unpack and Audit an Electron App: Extract asar Archives, Read IPC Channels and Spot Injection Points

Unpack and Audit an Electron App: Extract asar Archives, Read IPC Channels and Spot Injection Points

  • Post author:
  • Post published:
  • Post category:Security
📋 Key Takeaways
  • To unpack and audit an Electron app, extract app.asar with npx @electron/asar extract, grep the output for ipcMain.handle and ipcMain.on to map the IPC surface, then trace every channel for renderer-controlled arguments reaching privileged sinks.
  • Electron collapses two runtimes into one process tree: a Chromium renderer that renders untrusted content, and a Node.js main process with full operating-system privileges.
  • Only audit applications you own or have explicit written authorization to test.
  • Packaged Electron apps bundle their JavaScript source into an asar archive—a tar-like archive format Electron reads directly from disk without extraction.
9 min read · 1,706 words
Educational & Ethical Use Only — This article is provided for educational and ethical cybersecurity research purposes only. The techniques described should only be used on systems you own or have explicit permission to test. Always follow responsible disclosure and the laws applicable to you. Mitigations are included so engineers can harden real systems.
Concept flowThe Electron app audit flow
  1. 📦app.asar ArchiveLocate app.asar in install resources; entry point lives in packa
  2. 📂Extracted SourceExtract with npx @electron/asar; focus on entry, preload, render
  3. 🗺️IPC Channel MapGrep ipcMain/ipcRenderer/contextBridge to enumerate the privileg
  4. 🧵Injection TracesTrace renderer-controlled args to exec, openExternal, fs sinks
  5. 🛡️Config FindingsFlag nodeIntegration:true, contextIsolation:false, webSecurity:f

In Electron, a JS config flag is the privilege boundary—slipped discipline turns XSS into OS command execution.

Security· 9 min read

🔎 Last updated · Editorial policy · Report an error

TL;DR: What You Find When You Audit an Electron App

To unpack and audit an Electron app, extract app.asar with npx @electron/asar extract, grep the output for ipcMain.handle and ipcMain.on to map the IPC surface, then trace every channel for renderer-controlled arguments reaching privileged sinks. Flag nodeIntegration: true, contextIsolation: false, and webSecurity: false as immediate, high-severity findings.

Why Electron Apps Are Attack Surface

Electron collapses two runtimes into one process tree: a Chromium renderer that renders untrusted content, and a Node.js main process with full operating-system privileges. Traditional desktop application testing has a well-established playbook—binary analysis, memory corruption, privilege boundary review. Auditing an Electron application throws most of that out the window. Here, the privilege boundary is not enforced by the OS; it’s enforced by a handful of JavaScript configuration flags and developer discipline. When that discipline slips, a renderer-side XSS isn’t a content-spoofing nuisance—it’s a pivot to OS-level command execution. Electron’s own security team has acknowledged this repeatedly in their official security tutorial, and OWASP maintains a dedicated cheat sheet for exactly this class of bug.

This article walks you through a complete, hands-on audit: unpacking the archive, mapping the IPC surface, auditing window configuration, tracing injection paths, and confirming findings dynamically.

Lab Setup: Picking a Target App and Tools

Only audit applications you own or have explicit written authorization to test. For practice, use a deliberately vulnerable target rather than a production app:

  • OWASP Electron Security resources — the OWASP Electron Security Cheat Sheet links to vulnerable sample apps and enumerates the misconfigurations you’ll learn to find.
  • DVWA-style Electron samples — several intentionally vulnerable Electron apps exist on GitHub; search for “vulnerable electron app” and verify the repo explicitly states it’s for security training.
  • Your own build — packaging your own app and auditing it is the highest-fidelity practice.

You’ll need:

  • Node.js and npm (v16+) — verify with node -v and npx -v
  • A text editor or IDE with global search
  • The target application installed locally, so you can locate its install path

Locating the asar Archive and Identifying the Entry Point

Packaged Electron apps bundle their JavaScript source into an asar archive—a tar-like archive format Electron reads directly from disk without extraction. The location varies by platform:

  • Windows: C:\Program Files\AppName\resources\app.asar (or the app’s install directory under %LOCALAPPDATA%)
  • macOS: /Applications/AppName.app/Contents/Resources/app.asar
  • Linux: /opt/AppName/resources/app.asar or /usr/lib/AppName/resources/app.asar

Open package.json inside the archive (see next section) and read the main field—that’s the entry point script the main process executes. Then locate every new BrowserWindow() call; those constructors define each window’s security posture.

Extracting app.asar with npx @electron/asar

The official tool is @electron/asar (maintained under the Electron GitHub organization, successor to the original asar package). No global install required:

npx @electron/asar list app.asar | head -50
npx @electron/asar extract app.asar app-src

asar list dumps the archive contents—useful for a quick inventory before committing to extraction. asar extract writes everything into app-src/. The operation is strictly read-only on the original archive; nothing in the installed application is modified. A typical extraction yields:

app-src/
├── package.json
├── main.js
├── preload/
│   ├── main-preload.js
│   └── settings-preload.js
├── renderer/
│   ├── index.html
│   ├── app.bundle.js
│   └── assets/
└── node_modules/

Ignore node_modules on the first pass. Focus on the entry point, preload scripts, and renderer bundles—those are where your findings live.

Mapping IPC Channels: ipcMain, ipcRenderer, and preload Scripts

IPC is the bridge between the sandboxed renderer and the privileged main process. Every channel is a potential attack surface, so enumerate all of them:

grep -rn "ipcMain.handle\|ipcMain.on" app-src/ --include="*.js"
grep -rn "ipcRenderer.send\|ipcRenderer.invoke\|ipcRenderer.sendSync" app-src/ --include="*.js"

Also grep preload scripts for contextBridge.exposeInMainWorld—every exposed API is a documented, intentional privilege grant:

grep -rn "contextBridge\|exposeInMainWorld" app-src/preload/

Build a channel table. For each channel, record:

Channel Direction Handler Location Argument Flow Risk Notes
run-command renderer → main main.js:142 String passed to child_process.exec Command injection
open-url renderer → main main.js:88 String passed to shell.openExternal Arbitrary scheme/file handler
read-file renderer → main main.js:201 Path passed to fs.readFile Path traversal

If a preload script exposes something like ipcRenderer.sendTo or the raw ipcRenderer object via contextBridge, stop—compromised renderers can then invoke every registered channel without going through your curated API.

Auditing the BrowserWindow Security Configuration

Search for every webPreferences block:

grep -rn "webPreferences" app-src/ --include="*.js"

Four flags matter. Vulnerable configuration:

new BrowserWindow({
  webPreferences: {
    nodeIntegration: true,        // Node.js APIs in the renderer
    contextIsolation: false,      // preload and page share a context
    sandbox: false,               // Chromium sandbox disabled
    webSecurity: false            // same-origin policy disabled
  }
});

Hardened configuration:

new BrowserWindow({
  webPreferences: {
    nodeIntegration: false,
    contextIsolation: true,
    sandbox: true,
    webSecurity: true,
    preload: path.join(__dirname, 'preload/main-preload.js')
  }
});

contextIsolation has been enabled by default since Electron 12 (released March 2021), and the renderer sandbox became default in Electron 20 (August 2022). If you see these flags explicitly disabled, someone made a deliberate decision to weaken defaults—treat it as a finding requiring justification. The Electron security docs recommend an additional hardening checklist, and CISA’s Secure by Design guidance pushes vendors toward exactly these safe-by-default configurations.

Spotting Injection Points: XSS to RCE Paths

This is the core of the audit: trace untrusted input from the renderer to a dangerous sink in the main process. Common sources:

  • URL query parameters parsed at load (new URL(window.location.href).searchParams)
  • Content loaded over loadURL or loadFile with interpolated paths
  • Remote web content if the window loads external sites
  • Files opened via protocol handlers or drag-and-drop

Common sinks on the main-process side:

// Command injection
ipcMain.handle('run-command', (e, cmd) => child_process.exec(cmd));   // fatal

// Arbitrary URL/scheme execution
ipcMain.handle('open-url', (e, url) => shell.openExternal(url));      // fatal without allowlist

// Path traversal
ipcMain.handle('read-file', (e, p) => fs.readFile(p));                // reads any file

The escalation chain: renderer XSS → attacker controls ipcRenderer (or the exposed bridge API if overloaded) → invokes run-command → main process executes exec() with attacker input → OS-level code execution. With contextIsolation: false, the attacker’s JavaScript runs in the same context as the preload script, enabling direct prototype pollution of exposed APIs and classic Electron injection—overwriting Function.prototype to hijack privileged calls.

Dynamic Checks: DevTools, Console Confirmation, and Fuzzing IPC

Static findings need dynamic confirmation. Launch the app with the remote debugging port:

./AppName --remote-debugging-port=9222

Then open http://localhost:9222 in Chrome, or connect DevTools directly. From the console in the renderer context:

// Confirm nodeIntegration
typeof require           // 'function' = vulnerable

// Confirm contextIsolation
window.electronAPI       // exposed bridge present = isolation working
require                  // undefined with proper isolation

// Craft an IPC payload against the run-command channel
await window.electronAPI.runCommand('id')       // if bridge exposes it
require('electron').ipcRenderer.invoke('run-command', 'touch /tmp/pwned')

If /tmp/pwned appears, you've confirmed renderer-to-OS execution. Fuzz systematically: for each documented channel, send type-confused payloads (arrays where strings are expected, objects with __proto__ keys, path traversal sequences like ../../etc/passwd) and observe main-process behavior via console logging or a debugger attached to the main process.

Reporting and Concrete Fixes

Map every finding to a concrete remediation:

  • contextIsolation: false / nodeIntegration: true → enable contextIsolation: true and sandbox: true; expose only vetted functions through contextBridge.exposeInMainWorld. This is the single most impactful fix.
  • Unvalidated IPC arguments → validate every handler input with schema validation (zod, Ajv) and reject on mismatch. Never pass raw strings to sinks.
  • child_process.exec with user input → replace with execFile against an allowlisted binary, passing user data as argument arrays—never through a shell.
  • shell.openExternal without filtering → allowlist only https: URLs to known domains; reject file:, smb:, and custom schemes.
  • fs operations with user paths → use path.normalize plus path.resolve, then verify the resolved path starts with the intended base directory.
  • No CSP → add a strict Content-Security-Policy header/meta tag: default-src 'self'; script-src 'self'. This kills the XSS entry point that starts the whole chain.

The OWASP Electron Security Cheat Sheet covers each of these in depth and is the reference your report should cite.

Blue-Team Checklist and Further Reading

Reusable audit checklist:

  • [ ] Extracted app.asar and inventoried entry points and preload scripts
  • [ ] Enumerated all ipcMain.handle/on channels with argument flow
  • [ ] Verified contextIsolation, sandbox, nodeIntegration, webSecurity on every BrowserWindow
  • [ ] Checked that preload exposes only curated APIs, never raw ipcRenderer
  • [ ] Confirmed all IPC inputs are schema-validated
  • [ ] Verified shell.openExternal and exec sinks are allowlisted
  • [ ] Confirmed a strict CSP is enforced
  • [ ] Dynamically validated findings via DevTools

Further reading:

Frequently Asked Questions

Only audit applications you own or have explicit written authorization to test. Reverse engineering clauses in end-user license agreements vary by jurisdiction and vendor, so cover your authorization scope in writing before you start. For skill-building, stick to deliberately vulnerable training apps and CTF targets, which are published for exactly this purpose.

Does extracting app.asar modify the application?

No. asar extract writes to a new folder you specify; the original archive is untouched and the application continues to function normally. If you need to modify and test changes, you can repack with npx @electron/asar pack app-src app.asar—but do this only on copies you control.

What is the single most impactful Electron security fix?

Enable contextIsolation (default since Electron 12) and the renderer sandbox (default since Electron 20). Together they keep Node.js APIs out of the renderer entirely, breaking the XSS-to-RCE chain at its first link.

Why is webSecurity: false dangerous?

It disables the same-origin policy and CORS enforcement for that window. Remote content loaded in that window can then read local files via file://, fetch cross-origin resources freely, and exfiltrate data—effectively handing a browser-based attacker local file read.

Can an Electron app be secure if it loads remote content?

Yes—if you combine contextIsolation with a strict CSP, validate every IPC handler input, and normalize/allowlist any URLs before passing them to loadURL or shell.openExternal. The architecture is safe when the privilege boundary is enforced rather than assumed.

Hmmnm
Published by Hmmnm

Hands-on cybersecurity tutorials, CVE breakdowns, and guided learning paths — written and lab-tested by the Hmmnm team.

Keep going — the structured way
This post is one step. The learning paths chain the next ones for you, with progress tracking and no account needed.
Follow a learning path →

Check your understanding

1. Why does renderer-side XSS in an Electron app carry higher severity than in a typical web app?

2. During an audit, what is the primary purpose of grepping for ipcMain.handle and ipcMain.on?

3. Which combination of flags represents an immediate, high-severity finding?

4. A preload script exposes the raw ipcRenderer object via contextBridge. Why does this matter?

Your answers stay in this browser only.