fix: Validate external URL schemes before opening#2494
Merged
charlesvien merged 1 commit intoJun 5, 2026
Conversation
Contributor
What T-Rex did
Artifacts24-case URL safety test output
Generated URL validation edge-case test
24-case URL safety test output: all pass
URL safety test script (TypeScript)
Reviews (1): Last reviewed commit: "Validate external URL schemes before ope..." | Re-trigger Greptile |
Gilbert09
added a commit
that referenced
this pull request
Jun 5, 2026
Port the desktop hardening from #2494 to the mobile app: before handing a URL to `Linking.openURL` / `WebBrowser.openBrowserAsync`, validate its scheme against the shared allowlist (`http:`/`https:`/`mailto:`) so tampered or attacker-supplied URLs from markdown, chat, signal reports, or MCP app content can't trigger unsafe schemes (`file:`, `data:`, `javascript:`, custom deep-links, etc.). - Add `openExternalUrl(url)` helper in `apps/mobile/src/lib` that gates `Linking.openURL` behind `@posthog/shared`'s `isSafeExternalUrl` and keeps the existing silent no-op on failure. - Route the untrusted Linking call sites through it: MarkdownText, MarkdownImage, GithubRefChip, PostHogRefChip, SignalCard, SuggestedReviewers, PrStatusBadge, and the MCP template docs link. - Gate the MCP app bridge `WebBrowser.openBrowserAsync` behind `isSafeExternalUrl`. - Add unit tests covering the allow/deny matrix and that a rejected URL never reaches `Linking.openURL`. The test also exercises `isSafeExternalUrl` inside the mobile package to confirm it resolves and runs there. RN 0.81's `URL` extracts schemes via regex in its `protocol` getter, so no polyfill fallback is needed. Generated-By: PostHog Code Task-Id: 4fe18724-3034-4b84-8924-5b52a4b933fe
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.

Problem
URLs were passed straight to the main openExternal handler with no scheme check, so a tampered value could launch file://, smb://, or custom app-handler schemes via shell.openExternal.
Changes
How did you test this?
Manually
Automatic notifications