Allow desktop markdown links to open local files and editor schemes#1698
Allow desktop markdown links to open local files and editor schemes#1698hhharryyyyy wants to merge 1 commit intopingdotgg:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Needs human review This PR expands the desktop app's ability to open links from markdown content - adding support for local file paths, file:// URLs, and editor protocol schemes (vscode, zed, obsidian, etc.). While the implementation includes an allowlist and validation, expanding what protocols and paths can be opened has security implications that warrant human review. You can customize Macroscope's approvability policy. Learn more. |
Summary
http(s)zed://,obsidian://,vscode://,cursor://, andwindsurf://Problem
The Electron main process currently only accepts
http:andhttps:URLs for bothdesktop:open-externalandsetWindowOpenHandler. That blocks markdown file links and custom editor links before macOS can route them to the user's default app.Verification
bun fmtbun lintbun typecheckcd apps/desktop && bun run test src/openTarget.test.tsNote
Medium Risk
Moderate risk because it changes which URLs/paths the Electron main process will open (including local filesystem paths) and alters the sanitization/validation logic guarding
shell.openExternal/shell.openPath. Scope is limited and covered by new unit tests, but incorrect parsing could still enable unintended target opens.Overview
Desktop link opening is expanded beyond
http(s)by introducinggetSafeOpenTargetto resolve a URL/string into either a localpath(includingfile://and~/…with:line/#…suffix stripping) or anexternalURL restricted to an allowlist of schemes (e.g.vscode://,zed://,obsidian://,cursor://,windsurf://).The main process now routes both
desktop:open-externalIPC requests andsetWindowOpenHandlerpopups through a sharedopenSafeTargethelper that usesshell.openPathfor local paths,shell.openExternalfor allowed external schemes, and adds structured success/failure logging.Written by Cursor Bugbot for commit c049c60. This will update automatically on new commits. Configure here.
Note
Allow desktop markdown links to open local files and editor scheme URLs
DesktopOpenTargetdiscriminated union andgetSafeOpenTargetin openTarget.ts to classify user-provided strings as either local filesystem paths (shell.openPath) or external URLs (shell.openExternal).http/httpsto include editor and app schemes:vscode:,vscode-insiders:,cursor:,windsurf:,zed:, andobsidian:.stripLocationSuffixFromLocalPathto normalize paths by expanding~, stripping hash/query fragments, and removing:line[:col]suffixes when the base path exists.OPEN_EXTERNAL_CHANNELIPC handler andsetWindowOpenHandlerin main.ts to use the new routing logic, replacing the previoushttp/https-onlygetSafeExternalUrlapproach.file://URLs now open viashell.openPathinstead of being rejected; the protocol allowlist now includes non-web schemes.Macroscope summarized c049c60.