Repository navigation
fix(swift,extract): harden WebView security, concurrency, Readwise, and Readability - #3
Merged
Conversation
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
Hardens TwoUp's Swift host, WebView boundaries, Readwise integration, and article extraction pipeline while extracting pure testable helpers into
Core.swift:Core.swift):normalizeURL(_:)validateshttp/httpsschemes and rejects non-host strings (bare words like"hello"or CLI flags like"en") while allowing valid domains,localhost, IPv4, and bracketed IPv6.parseLaunchURL(arguments:)skips macOS LaunchServices / defaults flag pairs (-AppleLanguages en,-NS*,-psn_*) and accepts only valid URLs.isAllowedExternalURL(_:)strictly allowlistshttp,https, andmailtobefore handing links toNSWorkspace.shared.open.readwiseEndpointURL(path:queryItems:),readwiseUpdateURL(docID:), andreadwiseReaderBaseURL()eliminate all Readwise URL force-unwraps (!) and reject path traversal / percent-encodedocID.matchesExpectedReaderURL(_:expected:),slimDoc(_:),jsonLiteral(_:), andthemeWindowAppearance(theme:).main.swift):-warn-concurrencywarnings (@MainActoronKeychain,readwiseRequestusingasync/awaitURLSession.shared.data(for:),@MainActorWKNavigationDelegatedecision handler,Task { @MainActor in ... }workspace observer,MainActor.assumeIsolatedentry point).readerWKNavigationDelegateto only allow TwoUp's ownloadHTMLStringloads and cancel unexpected navigations; checksmessage.webView === readerandmessage.frameInfo.isMainFrameinWKScriptMessageHandler.loaderwithWKWebsiteDataStore.nonPersistent().NSAppleScriptcalls ingrabBrowserTab()off the main thread (Task.detached) after rendering the loading screen.stopLoader()inshowStart()andopenDoc(), checksevaluateJavaScripterrors inextract(), removes deadextractingset and unusedhtmlError, addsqueueFetchTokento drop stale queue responses, and checksOSStatus+kSecAttrAccessibleAfterFirstUnlockThisDeviceOnlyinKeychain.set.TwoUpMainWindow), fullscreen preference (defaulting to fullscreen on first run), minimum window size (640x480),queueLocationpreference, View menu Zoom items (⌘+/⌘-/⌘0),focusUrlon⌘L,article.dir/D.dir, and theme/appearance chrome sync (drawsBackground = false).WKUserContentControllerretain cycle withWeakScriptMessageHandlerandapplicationWillTerminatecleanup.Resources/Readability.js,Resources/extract.js):Resources/Readability.jsto@mozilla/readability@0.6.0(fixing the JSON-LD@graphthis.REGEXPSbug) with version/source header.#hashanchor/footnote links when parsing browser-grabbed HTML, promotes lazy<picture><source data-srcset>and<img>attributes, and returnsdir: article.dir || "".Verification
swiftc -typecheck -swift-version 5 -warn-concurrency Core.swift main.swift— 0 warningsnode --check Resources/extract.js && node --check Resources/Readability.js— passed./build.sh --build-only— passed (build/TwoUp.appbuilt cleanly)codesign --verify --deep --strict build/TwoUp.app— passedCore.swift(URL normalization, CLI flags, external scheme allowlist, Readwise URL safety,slimDoc,jsonLiteral,themeWindowAppearance) — passed