fix(protocol): validate commands and sanitize URIs in protocol handler#1812
Open
sebastiondev wants to merge 1 commit into
Open
fix(protocol): validate commands and sanitize URIs in protocol handler#1812sebastiondev wants to merge 1 commit into
sebastiondev wants to merge 1 commit into
Conversation
Validate commands invoked via mo://motrix:// protocol URLs by: - Restricting safe commands to be called without arguments - Validating URI arguments for new-task commands against allowlist - Blocking unrecognized commands from accepting arbitrary args This prevents attacker-crafted protocol URLs from passing untrusted arguments to sensitive application commands.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes an injection vulnerability (CWE-79 / CWE-77) in
ProtocolManager.jswhere craftedmo://ormotrix://protocol URLs can pass arbitrary, unsanitized arguments to application commands — including injectingjavascript:URIs into the renderer's "new task" dialog, leading to XSS, or invokingreveal-in-folderwith arbitrary file paths.The root cause is that
handleUrl()parses the URL pathname as a command name fromprotocolMapand passes the raw query string as arguments tosendCommandToAll()with no validation. SinceprotocolMapincludes commands likenew-task(which renders a URI in the UI) andreveal-in-folder(which opens paths on disk), an attacker can craft a link like:If the victim clicks this link (e.g., in a browser, email, or chat), Motrix opens and the malicious URI is injected directly into the renderer context.
Vulnerability Details
src/main/core/ProtocolManager.js,handleUrl()methodhandleUrl(url)→parse(query)→sendCommandToAll(command, args)→ renderer processes unsanitizedargs.uriProof of Concept
On macOS (after Motrix registers as protocol handler):
open "mo://new-task?uri=javascript:alert(document.cookie)"On Linux:
xdg-open "mo://new-task?uri=javascript:alert(document.cookie)"This opens Motrix's "new task" dialog with the
javascript:URI pre-filled. When the renderer processes this value, it executes in the Electron context.Similarly, path traversal via
reveal-in-folder:open "mo://reveal-in-folder?path=/etc/passwd"Fix Description
The fix introduces:
SAFE_COMMANDS) can be invoked without arguments; onlyARGS_ALLOWED_COMMANDScan receive parameters.new-task/new-bt-task, onlyhttp:,https:,ftp:,magnet:, andthunder:schemes are permitted. All other schemes (includingjavascript:,file:,data:) are rejected.urifield is passed through; other arbitrary query parameters are dropped.Commands like
reveal-in-folderare deliberately excluded from the allowed set since there's no safe way to validate arbitrary file paths from an external URL.Testing
mo://new-task?uri=https://example.com/file.zipstill works correctly (valid URI passes validation).mo://new-task?uri=javascript:alert(1)is rejected and logged as a warning.mo://task-list(no-arg safe command) still works.mo://reveal-in-folder?path=/tmpis now blocked.Adversarial Review
Before submitting, we considered whether existing mitigations prevent exploitation. Electron's
webSecurityand CSP settings don't help here because thejavascript:URI is injected as a value into the application's own task-creation flow, not loaded as a navigation target. The protocol handler has no existing validation —parse(query)feeds raw input directly tosendCommandToAll. The only precondition is the victim clicking a crafted link, which is trivially achievable via phishing.Related Issues
None found — this has not been previously reported.
Checklist:
Submitted by Sebastion — autonomous open-source security research from Foundation Machines. Free for public repos via the Sebastion AI GitHub App.