[Security] Unvalidated `switches` passthrough: `remote-debugging-port` opens an unauthenticated CDP server → session takeover and arbitrary local file read
Summary
nightmare's documented switches option forwards arbitrary Chromium
command-line switches to the Electron main process with no filtering whatsoever.
Passing switches: { 'remote-debugging-port': '9222' } makes the Electron
process start a Chrome DevTools Protocol (CDP) HTTP + WebSocket server on
127.0.0.1:9222 with no authentication of any kind.
Any local process can then connect to that endpoint and gain full control of the
automation session: arbitrary JavaScript execution in the renderer, navigation
to file:// URLs to read arbitrary local files, and visible takeover of the
window.
Affected version / environment
- nightmare 3.0.2 (latest release) — the vulnerable code is unchanged on master
- Electron 2.0.18 (Chromium 61)
- Tested on Windows 11 Enterprise (10.0.26200), Node.js v24.14.1
- PoC runs entirely against
127.0.0.1; no external systems involved
Root cause
lib/nightmare.js, lines 100–102 — user-supplied switches are forwarded verbatim:
if (options.switches) {
electronArgs.switches = options.switches
}lib/runner.js, lines 44–49 — they are appended to the Chromium command line
with no allow-list or deny-list:
var switches = processArgs.switches
if (switches) {
for (let i in switches) {
app.commandLine.appendSwitch(i, switches[i])
}
}switches is a public, documented option (README "switches" section, linking
Electron's list of Chrome command-line switches). Nothing warns that certain
switches silently start an unauthenticated remote-control server. Electron's own
documentation states that remote-debugging-port must not be enabled in
production.
Trigger
const Nightmare = require('nightmare')
Nightmare({ show: true, switches: { 'remote-debugging-port': '9222' } })
.goto('https://example.com/')
.wait(1000)
.end()
.then()This can reach production unintentionally: applications that build nightmare options from configuration files, or developers who copy a debugging switch into a script and forget to remove it. From that moment, the CDP endpoint stays open for the lifetime of the process.
Attack (any local process, no credentials)
GET http://127.0.0.1:9222/json— lists the page target and fingerprints the browser;GET /json/versionreportsElectron/2.0.18/Chrome/61.- Connect to the target's
webSocketDebuggerUrl. Runtime.evaluate— execute arbitrary JavaScript in the session.Page.navigatetofile:///URLs and read the contents back viaRuntime.evaluate(document.documentElement.innerText) — arbitrary local file read under the user's account.- Inject content into the live window — visible session takeover.
Observed output (PoC, abridged)
[1] FINGERPRINT Electron/2.0.18 (Chrome/61.0.3163.100)
[2] WS CONNECTED ws://127.0.0.1:9222/devtools/page/<uuid>
[3] READ win.ini ; for 16-bit app support
[fonts] ...
[4] READ hosts # Copyright (c) 1993-2009 Microsoft Corp. ...
[5] READ secret db_password=P@ssw0rd-2026 api_key=sk-live-9f8e7d6c5b4a
[6] INJECT victim window replaced with "PWNED VIA UNAUTHENTICATED CDP"Files read in the demo: C:\Windows\win.ini,
C:\Windows\System32\drivers\etc\hosts, and a sample file containing database
and API credentials. The victim window visibly displayed the injected banner.
Scope (stated honestly)
- What an attacker gets: arbitrary JavaScript execution in the renderer of the automation session, arbitrary local file read under the user's account, and full takeover of the session/page (including any authenticated content the automation is working on).
- What an attacker does not get: OS-level command execution. nightmare sets
nodeIntegration: false, and the CDP session controls the renderer, not the Electron main process. This is renderer takeover, not host RCE.
Impact
Any local process — including low-value malware already running on the machine — can, with zero authentication, take over the nightmare session and read arbitrary local files. Because nightmare sessions are routinely pointed at authenticated intranet portals, the impact compounds. Severity: High.
Suggested fix
Filter the switches option: reject (or at minimum warn loudly about) switches
that start unauthenticated debug/control servers — remote-debugging-port,
remote-debugging-address, inspect, inspect-brk, js-flags, etc. A
deny-list is the pragmatic minimum; an allow-list (proxy switches, GPU
switches, …) is safer. Also document that switches is passed through to
Chromium verbatim.
CVE request
I would like to request a CVE identifier for this vulnerability. I'm happy to coordinate on the advisory, the disclosure timeline, and credit — and to keep the full write-up private until then if you prefer. If I don't hear back within 90 days (or if this repository remains unresponsive), I intend to request a CVE ID through GitHub's CNA / MITRE's CNA-of-last-resort process and publish the details. Please let me know your preference.
Source: segment-boneyard/nightmare