Skip to content

Commit

Permalink
Lookalike character sanitization should only apply to main resource URLs
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=257134

Reviewed by Aditya Keerthi.

Make a slight adjustment to lookalike character sanitization, so that it only applies when loading
main resources.

* Source/WebCore/loader/FrameLoader.cpp:
(WebCore::FrameLoader::updateRequestAndAddExtraFields):
* Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h:
* Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm:
(-[TestNavigationDelegate _webView:didChangeLookalikeCharactersFromURL:toURL:]):

Also, add a new callback on `TestNavigationDelegate`, which we'll adopt in a new API test.

Canonical link: https://commits.webkit.org/264357@main
  • Loading branch information
whsieh committed May 22, 2023
1 parent dfd97e6 commit 25df569
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Source/WebCore/loader/FrameLoader.cpp
Expand Up @@ -3140,7 +3140,7 @@ void FrameLoader::updateRequestAndAddExtraFields(ResourceRequest& request, IsMai
if (shouldUpdate == ShouldUpdateAppInitiatedValue::Yes && localFrame->loader().documentLoader())
request.setIsAppInitiated(localFrame->loader().documentLoader()->lastNavigationWasAppInitiated());

if (page)
if (page && isMainResource)
request.setURL(page->chrome().client().sanitizeLookalikeCharacters(request.url(), LookalikeCharacterSanitizationTrigger::Navigation));
}

Expand Down
1 change: 1 addition & 0 deletions Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h
Expand Up @@ -42,6 +42,7 @@
@property (nonatomic, copy) void (^webContentProcessDidTerminate)(WKWebView *);
@property (nonatomic, copy) void (^didReceiveAuthenticationChallenge)(WKWebView *, NSURLAuthenticationChallenge *, void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *));
@property (nonatomic, copy) void (^contentRuleListPerformedAction)(WKWebView *, NSString *, _WKContentRuleListAction *, NSURL *);
@property (nonatomic, copy) void (^didChangeLookalikeCharactersFromURL)(WKWebView *, NSURL *, NSURL *);

- (void)allowAnyTLSCertificate;
- (void)waitForDidStartProvisionalNavigation;
Expand Down
6 changes: 6 additions & 0 deletions Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm
Expand Up @@ -191,6 +191,12 @@ - (void)_webView:(WKWebView *)webView contentRuleListWithIdentifier:(NSString *)
_contentRuleListPerformedAction(webView, identifier, action, url);
}

- (void)_webView:(WKWebView *)webView didChangeLookalikeCharactersFromURL:(NSURL *)originalURL toURL:(NSURL *)adjustedURL
{
if (_didChangeLookalikeCharactersFromURL)
_didChangeLookalikeCharactersFromURL(webView, originalURL, adjustedURL);
}

@end

@implementation WKWebView (TestWebKitAPIExtras)
Expand Down

0 comments on commit 25df569

Please sign in to comment.