Launch Configuration and Inputs
Overview
Startup input handling is split between small, testable main-process helpers. src/…/args.js normalizes command-line tokens into {opts, args} for launch and export behavior. parseDrawioArgs(argv) assumes user-supplied tokens begin at argv[2], seeds only options with explicit defaults, then walks the token stream once. Positional arguments are collected in order and may appear between flags; these are the input files or folders. Boolean flags become true only when present, so callers can distinguish absence from false. Value-bearing options consume the next non-flag token or use --flag=value; parsed values that return null or undefined fall back to that option's default when one exists. Page indexes and page ranges are converted from 1-based CLI input to 0-based values at parse time.
src/…/args.js keeps compatibility with the older commander.js behavior used by existing automation: single-dash short clusters such as -xa expand to booleans, and a value-bearing short option can take an attached suffix (-fpng, -q85) or the following token when it appears at the end of a cluster (-xf png). Unknown standalone flags are skipped, and the removed --enable-plugins flag is ignored rather than becoming a positional file. formatHelp(version) builds the help output from the same option definitions, while --disable-update and --no-silent-update are included only as help text because they are handled from process.argv before this parser runs.
src/…/url-params.js constructs launch-time URL parameters for editor windows. getUrlParamsFiles({exeDir, userDataDir, cwd, dev}) checks urlParams.json in the install directory first and the user data directory second. It only includes the working directory when dev is true, avoiding production launches where opening a diagram from the shell makes the diagram folder the process working directory. getUrlParams({defaults, state, files, readFile, log}) starts with default parameters, overlays scalar JSON values from each existing file in order, and then overlays state last. Missing files are silent; parse errors, non-object JSON, and read errors other than ENOENT are logged and skipped. Only string, number, and boolean values are copied, which prevents nested values such as __proto__ objects from changing the parameter object's prototype.
src/…/config-paths.js handles a narrower launch-time permission problem: local files named inside the renderer configuration, such as libraries, templates, and fonts. collectConfigPaths() is serialized into collectConfigPathsScript and run in the renderer with executeJavaScript, so it is written as a self-contained function. It reads only known path-carrying fields from Editor.config: templateFile, customTemplates URLs and previews, decoded defaultCustomLibraries, library URLs under libraries[].entries[].libs[], customFonts and defaultFonts fontUrl values, and url(...) references in fontCss. getLocalFilePath(url) then accepts only local file references: file:// URLs, Windows drive paths, UNC paths, and absolute paths; remote and relative URLs are ignored.
ConfigPathGrants in src/…/config-paths.js turns those configured local paths into per-window read grants. The main process registers an editor owner before the window loads, calls collect(owner) once when the renderer reports app-load-finished, and makes read-side IPC wait on waitForCollection(owner) so the configuration is sampled before any file content is sent into the renderer. For each collected local path, getEntries() resolves it, canonicalizes it with fs.realpathSync.native, and deduplicates by realpath. decide() adopts existing configured paths once for pre-grant installations via allowedConfigPathsMigrated, asks the user for unknown paths through the injected confirm(owner, entries), remembers allowed realpaths in the injected store under allowedConfigPaths, remembers denied paths only for the current session, and serializes concurrent decisions so one window's answer can satisfy another window waiting on the same file. A readable set includes both the configured resolved path and its canonical realpath, matching later read checks.
src/…/system-path.js provides safe launch-time discovery for Windows system binaries. getSystem32Path(file, env) uses SystemRoot, falls back to windir, and then to C:\Windows, but only accepts drive-rooted values such as C:\Windows. It rejects relative roots, drive-relative roots, root-only paths, and UNC roots that could resolve through the current working directory, then returns path.win32.join(root, 'System32', file). The tests in src/…/system-path.test.js cover this because Windows searches the working directory before PATH when a bare executable name is launched.
The owned tests pin these boundaries: src/…/cli-args.test.js covers defaults, validation fallback, combined short flags, positional ordering, and export option parsing; src/…/url-params.test.js covers file ordering, dev-only working-directory parameters, scalar-only merging, and state precedence; src/…/config-paths.test.js covers the renderer script, local-path extraction, migration, persisted grants, denials, concurrency, closed windows, symlinks, and mapped-drive canonicalization; src/…/system-path.test.js covers absolute System32 path construction.
Coupling
- If a CLI option is added or renamed in src/…/args.js, update both
OPTION_DEFSand the export/window code that consumes the resultingoptskey; the parser silently ignores unknown flags and only options withdefaultare initialized, so a missing definition can look like an absent flag rather than an error. - If command-line page selection semantics change in src/…/args.js, verify the export validation path that consumes
pageIndexandpageRange; these helpers intentionally convert 1-based input to 0-based values, and malformed inputs can becomeNaN, negative indexes, or short arrays for downstream rejection. - If URL parameter state keys change in the main process, update the
stateobject passed togetUrlParams()in src/…/url-params.js;stateis applied after every urlParams.json file so files cannot override main-process-controlled toggles. - If renderer configuration gains a new local path-carrying field, add it to
collectConfigPaths()in src/…/config-paths.js and add coverage in src/…/config-paths.test.js;ConfigPathGrantsonly grants reads for URLs collected by this allowlist, even if renderer code later routes the new field through read IPC. - If read authorization canonicalization changes outside this module, check
ConfigPathGrants.getRealpath()in src/…/config-paths.js; its comments state it must match the canonical path form checked by the main-process read side, and it intentionally adds both resolved and realpath forms to the readable set.
Risks
- src/…/config-paths.js reads
Editor.configfrom renderer state that any page script can mutate. IfConfigPathGrants.collect(owner)is called more than once per window or after file content is delivered, a diagram or library script could add local paths and gain read access; thestartedguard andwaitForCollection()ordering are the protections. - src/…/url-params.js intentionally excludes the working directory except when
devis true. IfgetUrlParamsFiles()starts readingcwdin production, opening a diagram from a folder containing urlParams.json could alter every editor window until quit, including parameters such asembedordev. - src/…/system-path.js exists for
GHSA-qg46-52fx-h7p8. If callers bypassgetSystem32Path()and launch Windows tools by bare name, Windows may resolve an executable from the diagram's working directory before the real System32 binary.