Lesson 6 of 9 · 26m
The Known Attack Surface: XSS, Navigation Abuse, and Supply Chain
Electron's worst incidents follow predictable chains — renderer injection, weak bridge design, navigation escape, dependency compromise, then code execution.
Electron security failures are rarely exotic. They are chain attacks: markdown renders unsanitized HTML, injected script reaches a broad preload API, preload exposes openPath, and now a chat message opens a shell or writes a startup item. Your job as the senior engineer is to break chains early, not argue about whether any one link is exploitable today.
The canonical chain
user-controlled content
-> rendered as HTML or exploitable markdown
-> JavaScript executes in renderer
-> broad IPC/preload capability is reachable
-> filesystem, shell, protocol, or update primitive is exposed
-> local privilege execution / persistence / data theftEvery layer should assume the previous one fails. Sanitize content even if markdown "shouldn't" contain HTML. Keep preload narrow even if sanitization is perfect. Validate paths even if only trusted callers "should" invoke the channel.
Sanitization belongs at the sink
Rendering markdown or rich text? Treat output as hostile HTML:
import DOMPurify from "dompurify";
const clean = DOMPurify.sanitize(renderedHtml, {
USE_PROFILES: { html: true },
FORBID_TAGS: ["style", "form", "input"],
FORBID_ATTR: ["srcdoc"],
});
container.innerHTML = clean;Allow-lists beat deny-lists. URLs inside sanitized output still need scheme checks: javascript:, data: in navigation contexts, and custom protocol handlers have different consequences. React escaping helps, but dangerouslySetInnerHTML tells you exactly where the boundary is — audit those call sites relentlessly.
Custom protocols and deep links are input
Registering myapp:// means other apps and web pages can cause your application to parse attacker-controlled strings. Validate host, path, query, and expected state transitions. Deep-link authentication callbacks are especially sensitive: bind state/nonce values, use short lifetimes, and never execute paths directly from URL parameters.
Dependencies are native-code supply chain
Electron applications bundle Chromium, Node, native modules, and your JavaScript dependency tree. A malicious package update can execute during install, build, preload, or runtime. Pin versions, review lockfile diffs, disable lifecycle scripts where possible, and use npm ci in release builds. Native modules deserve extra scrutiny because they bypass Chromium sandbox assumptions once loaded into Node contexts.
Chromium CVEs are operational reality
Electron embeds a browser engine. Browser engines have memory-corruption vulnerabilities. That means version currency is a security control, not a maintenance nicety. Track Electron releases, subscribe to security advisories, and define how quickly you can ship a patch. If your update mechanism is broken, every Chromium advisory becomes a permanent liability.
Field notes
- Search code for
innerHTML,dangerouslySetInnerHTML,openPath,exec, and broadipcRendererexposure during review. - A feature that previews user files is a renderer exploit delivery mechanism; sandbox the preview pipeline.
- Treat crash dumps and logs as sensitive — they often contain URLs, document fragments, and tokens.
- Red-team the update and deep-link paths; attackers chain them more often than defenders test them.
Was this lesson helpful?