Skip to content

fix: validate external URLs before opening#28

Merged
AboMeezO merged 3 commits into
mainfrom
fix/open-external-url-validation
Jun 13, 2026
Merged

fix: validate external URLs before opening#28
AboMeezO merged 3 commits into
mainfrom
fix/open-external-url-validation

Conversation

@AboMeezO

@AboMeezO AboMeezO commented Jun 13, 2026

Copy link
Copy Markdown
Member

Summary

  • Restrict external URL opening to http:, https:, and mailto: URLs.
  • Reuse the same validation for renderer IPC requests and window-open events.

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

  • npm run typecheck
  • npm run lint
  • npm run build:web

Summary by CodeRabbit

  • Bug Fixes
    • External URL validation has been implemented across the application. Only HTTP, HTTPS, and mailto protocols are permitted when opening external links. Requests using other URL schemes are blocked and logged. Malformed or unsupported URLs cannot be processed or executed. This ensures safer handling of all external link operations.

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@AboMeezO, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 94aa8d68-f1d2-4846-a9d2-d4fab59f4ed2

📥 Commits

Reviewing files that changed from the base of the PR and between e056044 and bd7993b.

📒 Files selected for processing (2)
  • electron/main.js
  • src/pages/settings/AboutSection.jsx
📝 Walkthrough

Walkthrough

This PR adds URL validation to prevent unsafe external links from being opened in the Electron application. A validateExternalUrl function with a protocol allowlist is introduced and integrated into both the IPC handler and window navigation handler, blocking disallowed URLs before they reach shell.openExternal.

Changes

External URL Validation

Layer / File(s) Summary
URL validator definition
electron/ipc/handlers.js
validateExternalUrl function validates URLs against a protocol allowlist (http:, https:, mailto:) and returns null for invalid or disallowed inputs.
IPC handler validation
electron/ipc/handlers.js
The app:openExternal IPC handler now validates URLs via validateExternalUrl, logging a warning and returning false for unsafe URLs before calling shell.openExternal.
Window navigation validation
electron/main.js
Imports validateExternalUrl and updates setWindowOpenHandler to validate requested URLs, blocking unsafe ones while allowing safe URLs to open externally.

Sequence Diagram

sequenceDiagram
  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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A validator stands guard at the gate,
Checking each URL, making it safe,
IPC and windows both bow to the rules—
Only the protocol-blessed URLs escape! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: validate external URLs before opening' directly describes the main change—adding URL validation before opening external links. It accurately reflects the primary security improvement across both IPC handlers and window-open events.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/open-external-url-validation

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1c12e3c and e056044.

📒 Files selected for processing (2)
  • electron/ipc/handlers.js
  • electron/main.js

Comment thread electron/main.js
@AboMeezO
AboMeezO merged commit cfdb17d into main Jun 13, 2026
2 of 3 checks passed
@AboMeezO
AboMeezO deleted the fix/open-external-url-validation branch June 13, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant