Skip to content

feat: file-type associations with auto-detected local apps - #5

Merged
SPhillips1337 merged 3 commits into
mainfrom
feat/file-app-associations
Nov 17, 2026
Merged

SPhillips1337 merged 3 commits into
mainfrom
feat/file-app-associations

Conversation

@SPhillips1337

@SPhillips1337 SPhillips1337 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #4 — merge that first; until then this PR also shows its two commits, and the diff shrinks to this feature alone once #4 lands.

What

  • Auto-detection: scans the development store (default ~/Documents/development, changeable in Settings) for projects whose package.json declares electron-builder build.fileAssociations. Launch target preference: win-unpacked exe → newest portable artifact → the project's own Electron binary (dev mode). Markdown Viewer 0.2.3 is detected with its six extensions (md, markdown, mdown, mkd, mkdn, mdx).
  • Settings → File apps: detected-apps list with Rescan, a default-app dropdown per extension (System default / Notepad / Cursor / detected / custom), and an Add-app form for any executable with a {file} argument template and extension list.
  • Opening files: double-click, Enter, and Open use the configured default for the extension, falling back to the system open. The right-click menu gains "Open with " entries for matching apps.
  • Safety: launches go through the existing injection-safe spawner; main validates the command (absolute, exists, executable extension), argument shapes, and cwd. Prefs are validated on load and stored locally like the other settings.

New files

src/shared/file-apps.ts (pure logic), src/main/app-detect.ts (scan), src/renderer/file-apps-settings.ts (storage), tests/file-apps.test.ts + tests/app-detect.test.ts (25 new tests).

Verification

  • npm run ci green: typecheck + 213 tests (was 188) + build; git diff --check clean.
  • Real Electron window smoke, 18/18: detection finds Markdown Viewer with a real exe; settings shows it; choosing it as the .md default persists; right-click menu contains "Open with Markdown Viewer"; double-clicking a .md actually launched Markdown Viewer with that file; a custom app added through the form opened a .txt via Notepad; launched processes cleaned up, test custom app removed.

Docs: PROGRESS/ROADMAP (P1.9)/README updated.

Scan the development store for projects declaring electron-builder
fileAssociations and offer them as Open with targets: unpacked exe,
portable artifact, or dev Electron fallback. Settings gains a File apps
section with the detected list, a per-extension default picker, and a
custom-app form ({file} argument template). Double-click, Enter, Open and
the right-click menu honor the chosen default through the existing
injection-safe spawner; launches are validated in main.

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

This PR introduces the file-type association feature with auto-detection of local Electron apps, settings UI, and IPC plumbing. The core logic is well-structured and input validation is thorough in most places. However, there are two blocking platform correctness bugs and two security concerns that need to be addressed before merging.

🛑 Must-Fix Issues

  1. apps:open broken on non-Windows (src/main/main.ts line 244): The \.exe|com|cmd|bat executable extension guard unconditionally blocks all launches on macOS and Linux, including the dev-mode Electron binary (no extension) and any custom app. This renders the entire openWithApp flow non-functional on those platforms.

  2. win-unpacked detection broken on non-Windows (src/main/app-detect.ts lines 37–39): The unpacked binary lookup hardcodes ${name}.exe, so the unpacked source path is never found on macOS (.app bundle) or Linux (no extension), silently degrading to portable/dev fallback even when an unpacked build is present.

  3. Path traversal via unconstrained apps:detect root (src/main/app-detect.ts lines 55–59): The IPC handler accepts any absolute path, allowing a compromised renderer to scan arbitrary filesystem locations and leak directory/file contents via package.json reads.

  4. spawnDetached shell-injection risk (src/main/main.ts lines 256–258): resolveAppArgs injects file paths into args before passing to spawnDetached. If the spawner ever uses a shell invocation internally, a crafted file path could execute arbitrary OS commands. This should be verified and explicitly enforced.

ℹ️ Minor Note

The extensionOptions function seeds from raw prefs.defaults keys without normalizing them, which could expose un-normalized extension strings in the UI if prefs are loaded from an unexpected source. A defensive normalization pass is suggested.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

Comment thread src/main/main.ts Outdated
if (!existsSync(filePath)) throw new Error('That file no longer exists.');
const command = typeof request.command === 'string' ? request.command.trim() : '';
if (!command || !isAbsolute(command) || !existsSync(command)) throw new Error('App executable not found.');
if (!/\.(exe|com|cmd|bat)$/i.test(command)) throw new Error('The app must be an executable file.');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Logic Error: The executable extension check /\.(exe|com|cmd|bat)$/i only matches Windows executable formats. On macOS and Linux — where the detected source: 'dev' path resolves to electron or Electron.app/.../Electron (no extension), and custom apps may be any binary — this check will unconditionally reject every valid launch and throw 'The app must be an executable file.'. The apps:open handler is completely broken on non-Windows platforms.

Suggested change
if (!/\.(exe|com|cmd|bat)$/i.test(command)) throw new Error('The app must be an executable file.');
if (process.platform === 'win32' && !/\.(exe|com|cmd|bat)$/i.test(command)) throw new Error('The app must be an executable file.');

Comment thread src/main/app-detect.ts
Comment on lines +37 to +39
for (const out of outputs) {
const unpacked = join(dir, out, 'win-unpacked', `${name}.exe`);
if (existsSync(unpacked)) return { launch: { command: unpacked, args: ['{file}'] }, source: 'unpacked' };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Logic Error: The win-unpacked lookup constructs a ${name}.exe path unconditionally. On macOS, the equivalent would be a .app bundle, and on Linux there is no .exe extension. This means the unpacked source is never found on non-Windows platforms, silently falling through to the portable or dev fallback even when a proper unpacked build exists. The PR description states multi-platform support, so this will silently produce wrong results on macOS/Linux.

Comment thread src/shared/file-apps.ts
Comment on lines +197 to +203
export function extensionOptions(detected: readonly FileApp[], prefs: FileAppPrefs): string[] {
const seen = new Set<string>(Object.keys(prefs.defaults));
for (const app of [...detected, ...prefs.customApps.map(customFileApp)]) {
for (const ext of app.extensions) seen.add(ext);
}
return [...seen].sort();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Logic Error: extensionOptions seeds the seen set with Object.keys(prefs.defaults), which are raw stored keys (e.g. .md as strings from localStorage). These keys were validated and normalized to lowercase dot-prefixed form by parseFileAppPrefs, so they will be in the set in their normalized form. However, keys from detected and customApps are also already normalized (.md). The issue is that if a stale/un-normalized key somehow reaches prefs.defaults (bypassing parseFileAppPrefs), it would appear in the dropdown without matching any extension lookup, causing a broken default that silently does nothing. The function should normalize the keys as it iterates to be defensively consistent with resolveDefaultApp.

Suggested change
export function extensionOptions(detected: readonly FileApp[], prefs: FileAppPrefs): string[] {
const seen = new Set<string>(Object.keys(prefs.defaults));
for (const app of [...detected, ...prefs.customApps.map(customFileApp)]) {
for (const ext of app.extensions) seen.add(ext);
}
return [...seen].sort();
}
export function extensionOptions(detected: readonly FileApp[], prefs: FileAppPrefs): string[] {
const seen = new Set<string>();
for (const key of Object.keys(prefs.defaults)) {
const ext = normalizeExtension(key);
if (ext) seen.add(ext);
}
for (const app of [...detected, ...prefs.customApps.map(customFileApp)]) {
for (const ext of app.extensions) seen.add(ext);
}
return [...seen].sort();
}

Comment thread src/main/main.ts
Comment on lines +256 to +258
const resolved = resolveAppArgs(args as string[], filePath);
await new Promise<void>((resolvePromise, reject) => {
spawnDetached(command, resolved, { cwd, onError: reject });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Security Vulnerability: The apps:open handler resolves {file} into the args array via resolveAppArgs and then passes those resolved args directly to spawnDetached. If spawnDetached internally uses child_process.exec or joins args into a shell command string (rather than using child_process.spawn with an array), a file path containing shell metacharacters (e.g. ; rm -rf ~) would be executed as a shell command. Confirm that spawnDetached always uses spawn/execFile with a separate args array — never a shell-interpolated command string — to prevent OS command injection.1

Footnotes

  1. CWE-78: OS Command Injection - https://cwe.mitre.org/data/definitions/78.html ↩

Comment thread src/main/app-detect.ts
Comment on lines +55 to +59
export async function detectLocalApps(rootRaw: unknown): Promise<DetectedApp[]> {
const root =
typeof rootRaw === 'string' && rootRaw.trim() && isAbsolute(rootRaw.trim())
? rootRaw.trim()
: defaultAppsRoot();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Logic Error: detectLocalApps accepts any user-supplied absolute path as rootRaw, which is exposed via the apps:detect IPC channel. A compromised renderer could pass a crafted absolute path to scan directories outside the intended development store (e.g. /etc or C:\Windows), reading arbitrary package.json files and leaking directory structure information. The IPC handler at handle('apps:detect', ...) performs no additional path restriction. Consider validating that the supplied root is confined to expected parent directories (e.g. the user's home directory), or restricting the scan to the configured prefs value only.

@SPhillips1337
SPhillips1337 changed the base branch from feat/updates-favorites-dialog-dnd to main November 17, 2026 11:17
@SPhillips1337 SPhillips1337 reopened this Nov 17, 2026
SPhillips1337 and others added 2 commits November 17, 2026 12:29
Review follow-up: the apps:open executable check now only requires
.exe/.com/.cmd/.bat on Windows; POSIX launches validate the execute bit
instead, so detected dev-mode and custom binaries can launch there.

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
@SPhillips1337
SPhillips1337 merged commit 813a73d into main Nov 17, 2026
1 check passed
@SPhillips1337
SPhillips1337 deleted the feat/file-app-associations branch November 17, 2026 12:33
@SPhillips1337

Copy link
Copy Markdown
Contributor Author

Review follow-up merged (886f2b3): apps:open now requires .exe/.com/.cmd/.bat only on Windows; on macOS/Linux it validates the execute bit instead, so extension-less binaries launch (+2 tests). The injection flag is covered by design: spawnDetached uses spawn with an argument array (cmd.exe shims quote each arg via its own env var), never a shell-interpolated string. apps:detect reads only package.json one level under the user-configured apps folder from our own renderer; the root is a Settings field by design. Detection artifacts remain Windows-first (win-unpacked/portable); macOS/Linux use the dev-Electron fallback or custom apps. Merged as 813a73d; released as v0.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant