Block file:// navigation to executables in preview pane#356
Merged
Conversation
Addresses CVE-2019-12138 (directory traversal to arbitrary program execution) and CVE-2019-12173 (RCE via file:// URI to .app bundles, auto-clicked via JavaScript). Adds MPURLSecurityPolicy utility class with two guards: - isExecutableOrAppBundleAtURL: detects executables/bundles via UTI conformance (CoreServices) with POSIX executable bit fallback - url:isWithinScopeOfBaseURL: checks if a target URL is within the document's directory tree after resolving symlinks and path traversal Guards applied at two call sites in MPDocument.m: - decidePolicyForNavigationAction: blocks JS-triggered file:// navigations outside document scope or to executables - openOrCreateFileForUrl: blocks user-clicked links to executables with a warning alert Related to #351
URLByResolvingSymlinksInPath uses realpath() internally, which fails when the final path component doesn't exist — leaving intermediate symlinks unresolved. Resolve the parent directory separately so that symlink escapes like docs/evil-link/payload (where evil-link points outside scope) are caught even when payload doesn't exist on disk. Related to #351
Contributor
Code Coverage ReportCurrent Coverage: 57.52% Coverage Details (Summary) |
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
MPURLSecurityPolicyutility class with UTI-based detection of executables/bundles and symlink-aware scope checkingdecidePolicyForNavigationAction:to block JS-triggeredfile://navigations outside document scope or to executablesopenOrCreateFileForUrl:to block user-clicked links to executables with a warning alertRelated Issue
Related to #351
Manual Testing Plan
<a href="file:///Applications/Calculator.app">click</a>— clicking should show a "Blocked: Link target is an executable" alert<script>window.location='file:///Applications/Calculator.app'</script>— no app should launch, blocked silently with NSLogfile://links to.mdfiles in the same directory should continue to workhttps://links should continue to open in the default browserDesign Notes
NSWorkspace typeOfFile:+UTTypeConformsTo()against six dangerous UTI types, with POSIX executable bit fallback for scripts without registered UTIsrealpath()(used byURLByResolvingSymlinksInPath) fails when the final component doesn't existfile://links intentionally skip the scope check — only executables are blocked. Opening local documents from Markdown links is a legitimate use case.