Repository navigation
fix(desktop): confirm before opening executable link targets (code execution) - #4843
Conversation
Add a pure extension-based check (and the backing extension list) for files the OS shell would execute as code — Windows Script Host scripts (js, vbs, wsf, hta…), native executables/installers, batch, PowerShell, and shortcut/ registry/JVM launchers. Case-insensitive; no filesystem access so it can gate a decision before the file is opened. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Clicking a markdown link to a co-located local file called shell.openPath with no safety check. On Windows a link like `[open](./update.js)` next to an untrusted document ran the script through wscript.exe with no prompt, giving silent code execution. Guard the non-markdown local-file branch of mt::format-link-click with isDangerousExecutableFile and show a warning dialog (default Cancel) before opening; the file is only handed to the OS shell if the user confirms. Fixes #3575 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Thanks for tackling this — the fix is clean and well-tested. Three points from review: 1. Trailing-dot / trailing-space filenames bypass the guard but still execute on Windows
Windows strips trailing dots/spaces from the final path component during Suggest trimming trailing dots/spaces before extracting the extension, e.g.: const ext = path.extname(filepath.replace(/[ .]+$/, '')).slice(1).toLowerCase()2. The guard is Windows-only — the same silent-exec path is open on macOS/LinuxThe vulnerable code path (
So 3. Dialog strings should go through i18nThe new |
Two gaps from review: - Trailing dot/space bypass: `update.js.` and `<./update.js >` (an angle- bracket link skips the space rejection) reach the guard with an extension of `.` / `js ` that isn't listed, yet Windows strips trailing dots/spaces during ShellExecute and still runs `update.js`. Trim trailing `[ .]+` before reading the extension. - Windows-only coverage: the vulnerable shell.openPath path is cross-platform, so add macOS (`command`, `app`) and Linux (`desktop`, `appimage`, `run`) launchers — `[x](./run.command)` / `./launch.desktop` reproduced #3575 off Windows. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add dialog.unsafeFileTitle / unsafeFileMessage / unsafeFileDetail ({name})
and dialog.openAnyway to the ten locale files so the #3575 confirmation
dialog is localized (getTranslation returns the raw key when one is missing).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
) Route the dialog title/message/detail and buttons through t('dialog.…') instead of hardcoded English, matching the other dialogs in this file. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Thanks for the thorough review — all three addressed: 1. Trailing dot/space bypass. const ext = path.extname(filepath.replace(/[ .]+$/, '')).slice(1).toLowerCase()Added tests for 2. Cross-platform coverage. Extended the list beyond Windows to macOS ( 3. i18n. The dialog now goes through Split into three atomic commits (guard hardening / i18n keys / dialog localization). Full desktop unit suite (714) + typecheck + lint green locally. |
Problem
Fixes #3575
Clicking a normal markdown link that points at a co-located local file executed the file with no confirmation. On Windows, a malicious note could ship a payload beside it:
Clicking the link ran
mt::format-link-click→shell.openPath('update.js')→wscript.exeexecuted the script with no prompt — silent code execution just from opening a document and clicking a link.Root cause
packages/desktop/src/main/menu/actions/file.ts(mt::format-link-click): for a local, non-markdown target the handler calledshell.openPath(pathname)unconditionally.shell.openPathhands the file to the OS default handler, which for.js/.vbs/.wsf/.bat/.exe/… means run it.Fix
isDangerousExecutableFile(+DANGEROUS_EXECUTABLE_EXTENSIONS) incommon/filesystem/paths.ts— flags OS-executable extensions (WSH scripts, native executables/installers, batch, PowerShell, shortcut/registry/JVM launchers). Case-insensitive, no filesystem access, so it can gate the decision before opening.shell.openPathif the user explicitly confirms. Markdown files, images, PDFs and other normal documents are unaffected.Tests
test/unit/specs/dangerous-executable-file.spec.tscovers the guard (WSH/native/PowerShell/shortcut extensions, case-insensitivity, absolute paths, and negative cases for docs/images/markdown/no-extension).The confirmation dialog wiring is verified by the unit-tested guard; the dialog itself is a thin Electron
showMessageBoxcall.🤖 Generated with Claude Code