Fix command injection risk in openBrowser#36
Open
ishaanxgupta wants to merge 1 commit intosupermemoryai:mainfrom
Open
Fix command injection risk in openBrowser#36ishaanxgupta wants to merge 1 commit intosupermemoryai:mainfrom
ishaanxgupta wants to merge 1 commit intosupermemoryai:mainfrom
Conversation
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.
Fixed a potential command injection vulnerability in src/lib/auth.js within the openBrowser function. Added a try-catch block to parse the provided url and verify that the protocol is exactly 'http:' or 'https:' before executing any commands to open it.
If left unfixed, execFile could potentially be exploited by passing a malicious URL or a URL with a dangerous protocol scheme (e.g., file://, javascript:, or specific shell-executable patterns), which could lead to arbitrary command execution on the user's machine (Windows explorer.exe, macOS open, or Linux xdg-open).
The fix uses the native JavaScript URL constructor to safely parse the provided URL string before attempting to open it in the browser. If parsing throws an error, or if the parsed URL’s protocol is anything other than http: or https:, the function immediately logs a warning with console.warn and returns early. This prevents invalid or unsupported URLs from being passed to execFile, reducing the risk of unexpected behavior and ensuring that no child process is launched unless the URL is well-formed and uses an allowed web protocol.