Add security validations and improve CDP event handling#1
Open
MarcosBrendonDePaula wants to merge 1 commit intomainfrom
Open
Add security validations and improve CDP event handling#1MarcosBrendonDePaula wants to merge 1 commit intomainfrom
MarcosBrendonDePaula wants to merge 1 commit intomainfrom
Conversation
… error handling - Complete stub implementations: onConsoleMessage, onNetworkRequest, openDevTools, closeDevTools, and runCommand now have working implementations using CDP APIs - Improve error handling: startBrowser throws descriptive errors instead of returning null, CDP commands have 30s timeout to prevent hanging promises - Fix type safety: remove loose [key: string]: any patterns, strongly type IPC API, BrowserInfo, ExtraOptions, and Bun API declarations - Add macOS browser support: darwin platform with paths for Chrome, Chrome Canary, Chromium, Edge, Firefox, and Firefox Nightly - Fix memory management: CDP close() clears pending reply callbacks and message listeners, add clearBrowserCache() to reset path detection cache - Add input validation: URL protocol allowlist (http/https/file), file path traversal prevention, command execution allowlist, sensitive env var blocking https://claude.ai/code/session_01PDJSn9vYhTxyaWDaKweBAG
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.
Summary
This PR enhances security by adding input validation for sensitive operations and improves the Chrome DevTools Protocol (CDP) event monitoring system. It also adds macOS support, better error handling, and type safety improvements across the codebase.
Key Changes
Security Enhancements
validateUrl()to restrict navigation to http://, https://, and file:// protocols onlyvalidateFilePath()to block path traversal attacks (e.g., "../../etc/passwd") in file operationsvalidateEnvKey()to block access to sensitive environment variables (AWS_*, tokens, secrets, passwords, private keys)runCommand()restricting execution to safe commands (ls, cat, git, npm, node, etc.)CDP Event Monitoring Improvements
onConsoleMessage()andonNetworkRequest()to return unsubscribe functions viaCDPEventSubscriptioninterfaceConsoleMessageandNetworkRequestexported interfaces for type-safe event handlingbrowser.cdp.onEvent()callback registration for CDP event streamingPlatform Support
Platformtype to include 'darwin'Type Safety & Error Handling
IPCApiinterface for better type definitionsFluxDesktopWindowinterface with proper CDP event callback supportreadJSONFile()returnsunknowninstead ofany)Bun.file().sizetype fromPromise<number>tonumberDevTools Management
openDevTools()andcloseDevTools()with proper CDP Inspector domain support and F12 key fallbackUtility Functions
clearBrowserCache()export to reset cached browser paths at runtimerunCommand()implementation using Node.js child_process spawn with proper stdout/stderr handlingnavigate()andgetEnv()functionsMemory & Resource Management
Notable Implementation Details
CDP_TIMEOUT_MSconstanthttps://claude.ai/code/session_01PDJSn9vYhTxyaWDaKweBAG