Skip to content

Commit

Permalink
Merge pull request sparkle-project#1728 from zorgiepoo/about-blank-fi…
Browse files Browse the repository at this point in the history
…x-2x

Ignore opening about:blank URLs (2.x)
  • Loading branch information
kornelski authored Jan 19, 2021
2 parents 7896b5a + 01d19ca commit 22af258
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Sparkle/SULegacyWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ - (void)webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame
- (void)webView:(WebView *)__unused sender decidePolicyForNavigationAction:(NSDictionary *)__unused actionInformation request:(NSURLRequest *)request frame:(WebFrame *)__unused frame decisionListener:(id<WebPolicyDecisionListener>)listener
{
NSURL *requestURL = request.URL;
BOOL safeURL = SUWebViewIsSafeURL(requestURL);
BOOL isAboutBlank = NO;
BOOL safeURL = SUWebViewIsSafeURL(requestURL, &isAboutBlank);

// Do not allow redirects to dangerous protocols such as file://
if (!safeURL) {
Expand All @@ -124,7 +125,7 @@ - (void)webView:(WebView *)__unused sender decidePolicyForNavigationAction:(NSDi

// Ensure we are finished loading
if (self.completionHandler == nil) {
if (requestURL) {
if (requestURL && !isAboutBlank) {
[[NSWorkspace sharedWorkspace] openURL:requestURL];
}

Expand Down
7 changes: 5 additions & 2 deletions Sparkle/SUWKWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati
{
NSURLRequest *request = navigationAction.request;
NSURL *requestURL = request.URL;
BOOL safeURL = SUWebViewIsSafeURL(requestURL);
BOOL isAboutBlank = NO;
BOOL safeURL = SUWebViewIsSafeURL(requestURL, &isAboutBlank);

// Do not allow redirects to dangerous protocols such as file://
if (!safeURL) {
Expand All @@ -222,7 +223,9 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati
} else {
// Ensure we're finished loading
if (self.completionHandler == nil) {
[[NSWorkspace sharedWorkspace] openURL:requestURL];
if (!isAboutBlank) {
[[NSWorkspace sharedWorkspace] openURL:requestURL];
}

decisionHandler(WKNavigationActionPolicyCancel);
} else {
Expand Down
2 changes: 1 addition & 1 deletion Sparkle/SUWebViewCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

NS_ASSUME_NONNULL_BEGIN

BOOL SUWebViewIsSafeURL(NSURL *url);
BOOL SUWebViewIsSafeURL(NSURL *url, BOOL *isAboutBlankURL);

NS_ASSUME_NONNULL_END
5 changes: 4 additions & 1 deletion Sparkle/SUWebViewCommon.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

#import "SUWebViewCommon.h"

BOOL SUWebViewIsSafeURL(NSURL *url)
BOOL SUWebViewIsSafeURL(NSURL *url, BOOL *isAboutBlankURL)
{
NSString *scheme = url.scheme;
BOOL isAboutBlank = [url.absoluteString isEqualToString:@"about:blank"];
BOOL whitelistedSafe = isAboutBlank || [@[@"http", @"https", @"macappstore", @"macappstores", @"itms-apps", @"itms-appss"] containsObject:scheme];

*isAboutBlankURL = isAboutBlank;

return whitelistedSafe;
}

0 comments on commit 22af258

Please sign in to comment.