Security · Electron
Hardening an Electron app that can delete your files
The trust boundaries in DiskGrove: a sandboxed renderer, a main process that checks everything, previews that never execute, and an honest list of what none of it can stop.
Two things to protect
A disk analyzer is an unusual app to secure. It runs with your filesystem permissions, it can delete anything you can, and its preview pane parses whatever files happen to be on your disk, including ones someone else made.
So DiskGrove has two jobs beyond being useful: protect your files from mistakes, its own or yours, and protect your machine from crafted file content. Electron makes both easy to get wrong, because by default a web page and Node.js are a short hop apart.
A renderer that can't touch the disk
All filesystem access lives in the main process. The renderer, where React and every file parser run, is sandboxed with context isolation on and Node integration off. It reaches the main process only through a narrow, typed API exposed by the preload script.
webPreferences: {
preload, // the narrow, typed API
sandbox: true,
contextIsolation: true,
nodeIntegration: false,
}That boundary is a rule for contributors too: filesystem access belongs in the main process, renderer arguments are validated there, and file-action confirmation and identity checks stay at that boundary.
Every IPC call is checked twice
A message arriving over IPC is not trusted because it came from "our" window. Each handler first checks the sender: the window, that the message came from the top-level frame, and that the frame is showing the app's own document. Only then are the arguments validated.
Scans and filesystem operations also cannot overlap through IPC, so a delete can never race a scan that is rebuilding the tree it was chosen from.
Closing the doors to the web
DiskGrove has no reason to talk to the internet, so it doesn't let anything try:
- navigation, popups and
<webview>are denied; - every web permission is denied except sanitized clipboard writes, which Copy path uses;
- production builds inject a Content Security Policy and block HTTP, HTTPS and WebSocket requests in the Electron session.
Development is the exception: it runs against a local Vite server with no CSP and no request blocking, which is why development builds don't carry the same guarantees as packaged releases.
Deleting a file, carefully
Opening and deleting both go through a native dialog shown by the main process, with Cancel as the default button. A web-style confirm inside the renderer would be one compromised script away from clicking itself.
Before acting, the main process checks that the path belongs to the current scan, then rechecks the file's identity and its ancestors, and refuses to traverse symbolic links or junctions. A scanned link can itself be deleted without touching its target, and file actions through linked directories are refused outright: scan the target directly to manage those files.
Previewing untrusted files
The preview pane is where hostile input meets the app, so it gets the tightest rules:
- it reads only regular files in the current scan, after the same identity check, and at most 16 MiB per request;
- images, video and audio stream through a private
diskgrove-media:scheme served withnosniffand a CSP that blocks scripts; - PDFs render with PDF.js in a worker, with XFA forms disabled;
- Word, Excel, PowerPoint and ZIP files are parsed in the renderer and shown as text and tables. Their contents never become HTML or script.
Files the app writes
Exports are an attack surface people forget. HTML reports escape every value and carry their own CSP. CSV cells that start with a formula-like prefix are escaped, so a file named =HYPERLINK(...) can't turn into a live formula when the report is opened in a spreadsheet.
Reports and settings are written to an exclusive temporary file and renamed into place, with POSIX mode 0600 (on Windows they inherit the destination folder's ACLs), and settings writes are serialized so two saves can't interleave.
Locking the binary itself
Electron fuses are flipped at packaging time: the generic Node runtime (RunAsNode), NODE_OPTIONS and command-line inspection are disabled, code loads only from the ASAR archive, and embedded ASAR integrity checks are enabled where Electron supports them.
One subtlety for anyone auditing: Vite bundles every npm package the renderer uses, so they are all devDependencies but still ship in the app. npm audit --omit=dev would miss them, so the project audits everything.
What none of this can stop
A security model is only useful if it says where it ends. DiskGrove's SECURITY.md lists the limits plainly, and they are worth repeating:
- Identity checks are not atomic with file actions, so a local process writing at the same moment can still race them.
- Opening a file hands it to its OS handler, which can execute a program.
- Previews parse untrusted content with PDF.js and Chromium's image and media decoders. A flaw there could be reached by selecting a crafted file; the sandbox limits what it could do.
- On Linux systems without unprivileged user namespaces, the AppImage starts with
--no-sandbox, as other Electron AppImages do. Context isolation, the preload boundary and IPC validation still apply, and the.debkeeps the sandbox by installingchrome-sandboxsetuid root and, on Ubuntu 24.04 and later, an AppArmor profile. - Releases are not code-signed, so the operating system cannot verify the publisher.
- Security
- Electron
- DiskGrove