fix(electron): refuse every spelling of the engine's own launch switches, and bound an .asar app by its archive
Closed
KD
8h ago+84+84+01234567890123456789-11-11-01234567890123456789
What
app.launchArgumentsandelectron.launch({ launchArguments })refuse the switches the engine owns in every spelling Chromium accepts: one dash as well as two (-remote-debugging-port=9222), with whitespace around them (-user-data-dir=...), a slash and any letter case on Windows (/USER-DATA-DIR=...), and Node's other inspector switches (--inspect-port,--inspect-wait,--inspect-brk-node,--debug-port). Each fails withINVALID_CONFIGat config load, orINVALID_ARGUMENTfromlaunch().- A packaged app declared by its
.asararchive (app.appPath: '.../app.asar') is bound to that archive when the main process does not report its path. A window that shows a file next to the archive is no longer observed, traced, or recorded.
Why
- Chromium trims each argument and reads
-remote-debugging-portand, on Windows,/REMOTE-DEBUGGING-PORTas the same switch as--remote-debugging-port, but the check matched only the exact two-dash spelling. One of these switches got past it, opened a second debugging endpoint the engine does not own, and could break the launch. Node's other inspector switches got past it the same way. - The file bound treated a declared
.asaras a plain file and used its parent folder (Resources/) as the app's directory, so pages next to the archive counted as the app's own.
How it works
ownedArgumenttrims the argument, takes the switch name after--,-, or (onwin32)/, lowercases it onwin32the way Chromium'sAppendSwitchNativedoes, and checks it against the full list of owned switches (packages/electron/src/options.ts:67-79). Other platforms keep the exact-case match, since Chromium reads--USER-DATA-DIRthere as a different switch. Its callers (validateAppinengine.ts, andcheckLaunchArgumentsandcheckLaunchOptionsinoptions.ts) call it through an arrow function, soArray.mapdoes not pass an index as the newplatformparameter.appDirectorytakes a declared path ending in.asaras the bound itself, before it checks the disk (packages/electron/src/file-bound.ts:34-36).- A new integration test drives the bound end to end: an observation, a trace screen, and the recorder's frame gate on the app's own page and on a file outside it (
packages/electron/tests/integration/launch.test.ts:331).
Verified
Ran it locally: yes, on macOS (Apple Silicon) with Electron 45.5.0.
- This branch passes the Electron package's unit and integration tests, the Electron testbed run through the built CLI (
pnpm --filter @e2e-dev/electron-testbed test), andpnpm check. The testbed andpnpm checkran before the whitespace and letter-case matching inownedArgument; for that change, the unit project (114 tests),tests/integration/launch.test.ts(38 tests), typecheck, and oxlint ran at this head. - main against this branch: this branch's tests run against
origin/main'spackages/electron/src. These tests fail there and pass here:
| Suite | Test | main | this PR |
|---|---|---|---|
| unit | resolveOptions refuses unknown keys and values of the wrong shape at config load | fails | passes |
| unit | appDirectory is the archive an app path names, as Electron reports it, not the package it sits in | fails | passes |
- Benchmark:
pnpm bench:ab --suite electron-testbed(main against this branch) is still running; its table replaces this line when it finishes. - Video: none attached. The change is in what the engine reads and when it acts, which the tests above pin down; a recording would show the same window either way.
- Local macOS runs, on both sides, started Electron with
-ApplePersistenceIgnoreState YESfrom #2500, applied without committing it. Without it, an Electron the tests killed makes macOS ask to reopen its windows, and the next launch waits out its timeout. The Linux and Windows CI jobs do not need it.
Fresh-context review (Codex gpt-6.2-sol, read-only, on this branch's diff):
- Fixed: the file bound test now stops the recorder in a
finally, so a failing assertion leaves no ffmpeg running. - Fixed: added the changeset.
- Dismissed: the test asserts the recorder's frame gate (
allowed) rather than decoded frames. Both capture paths go through that gate (packages/electron/src/video.ts:83and:138), and checking frames would mean decoding the video.
Bot review: an owned switch with whitespace around it, and an uppercase one on Windows, got past ownedArgument. Both are fixed, with unit tests, after checking base/command_line.cc: AppendSwitchesAndArguments trims each argument, and AppendSwitchNative lowercases the name on Windows only.
š¤ Generated with Claude Code
Summary by CodeRabbit
- Bug Fixes
- Electron launch arguments now consistently reject engine-managed Chromium and Node inspector switches, including supported single-dash and Windows slash-prefixed forms.
- Packaged applications using an
.asarpath now use that archive path as the app directory, even when it is not a directory on disk. - Pages outside the app directory remain locatable, but are not observed or included in tracing and recording.
- Documentation
- Updated launch-argument guidance to list engine-managed switches and their accepted prefixes.