fix: validate external URLs before opening#28
Conversation
|
Warning Review limit reached
More reviews will be available in 48 minutes and 22 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR adds URL validation to prevent unsafe external links from being opened in the Electron application. A ChangesExternal URL Validation
Sequence DiagramsequenceDiagram
participant IPC as IPC Handler
participant WinNav as Window Navigation
participant Validator as validateExternalUrl
participant Shell as shell.openExternal
IPC->>Validator: validate url
alt URL is safe
Validator-->>IPC: return validated URL
IPC->>Shell: openExternal(url)
else URL is unsafe
Validator-->>IPC: return null
IPC-->>IPC: log warning, return false
end
WinNav->>Validator: validate url
alt URL is safe
Validator-->>WinNav: return validated URL
WinNav->>Shell: openExternal(url)
else URL is unsafe
Validator-->>WinNav: return null
WinNav-->>WinNav: log warning, deny open
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@electron/main.js`:
- Around line 170-178: The setWindowOpenHandler callback currently calls
shell.openExternal(safeUrl) without handling its returned Promise; update the
handler in mainWindow.webContents.setWindowOpenHandler so that when
validateExternalUrl(url) returns a safeUrl you call
shell.openExternal(safeUrl).catch(err => logger.error(...)) (or equivalent) to
swallow/log errors and avoid unhandled promise rejections; keep the existing
deny return and log the error with context (include the URL and error) in the
catch callback.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 14303baa-8231-4fdb-b798-0d6f54183696
📒 Files selected for processing (2)
electron/ipc/handlers.jselectron/main.js
Summary
http:,https:, andmailto:URLs.Problem
Renderer-provided URLs were passed directly to Electron
shell.openExternal, allowing unsafe or unintended schemes to reach the host OS.Solution
Added a centralized main-process URL validator and reject malformed or unknown-scheme URLs before calling
shell.openExternal.Verification
Summary by CodeRabbit