fix(macos): handle nil URL/method/header values in url_scheme_handler#1744
Open
TranscriptionFactory wants to merge 1 commit into
Open
Conversation
WebKit can dispatch a custom-scheme task whose NSURLRequest has a nil
URL, absoluteString, or HTTPMethod, and whose allHTTPHeaderFields
contains a key with a nil value. start_task currently unwraps all four,
which aborts across the FFI boundary (SIGABRT) instead of propagating
the failure back to Swift.
Replace each unwrap with a defensive branch:
- Nil URL or absoluteString: log via tracing and return without
dispatching the task.
- Nil HTTPMethod: log and fall back to "GET", matching NSURLRequest's
default.
- Nil header value: skip that header instead of aborting the request.
Happy-path behavior is unchanged.
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
url_scheme_handler::start_taskunwraps four values that WebKit may legitimately return as nil:request.URL()(L91)url.absoluteString()(L93)request.HTTPMethod()(L99)all_headers.valueForKey(¤t_header)(L130)When any of these is nil, the unwrap aborts inside an Objective-C callback invoked across the FFI boundary, producing a
SIGABRTwith no recovery path. In our downstream Tauri app, opening a graph view reliably triggered this — WebKit was synthesizing a custom-scheme request without a URL on the navigation path, and the unwrap turned an Option into a process abort.Change
Each of the four
unwrap()s becomes a defensive branch:URL/absoluteString: emit atracing::warn!(gated on thetracingfeature) andreturnfrom the task handler, dropping the malformed request rather than crashing the process.HTTPMethod: warn and fall back to"GET", which matchesNSURLRequest's default.A short comment near the URL handling explains the rationale.
Behavior
For well-formed requests (the common case), behavior is unchanged. For malformed requests, the task either completes with a degraded method/header set or terminates early, instead of aborting the process.
Test plan
cargo checkclean ondevprofile (macOS arm64) on this branch.cargo fmtapplied.I'm happy to add a unit test if there's an established pattern for mocking a
WKURLSchemeTaskwith nil values, but I didn't find one in the existingsrc/wkwebview/tests.