Title: [262989] branches/safari-609-branch
Revision
262989
Author
[email protected]
Date
2020-06-12 17:06:38 -0700 (Fri, 12 Jun 2020)

Log Message

Cherry-pick r262707. rdar://problem/64226888

    File URLs with hostnames are misleading
    https://bugs.webkit.org/show_bug.cgi?id=212739
    <rdar://problem/63754917>

    Reviewed by Alex Christensen.

    Source/WebCore:

    Showing a file URL like file://example.org/test is misleading to users.
    To prevent this, we just do a redirection to the same file URL with an empty host.
    Remove the port at the same time.
    Covered by added API test.

    * loader/DocumentLoader.cpp:
    (WebCore::DocumentLoader::willSendRequest):

    Tools:

    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
    * TestWebKitAPI/Tests/WebKit/open-window-with-file-url-with-host.html: Added.
    * TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm:
    (TEST):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@262707 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-609-branch/Source/WebCore/ChangeLog (262988 => 262989)


--- branches/safari-609-branch/Source/WebCore/ChangeLog	2020-06-13 00:06:33 UTC (rev 262988)
+++ branches/safari-609-branch/Source/WebCore/ChangeLog	2020-06-13 00:06:38 UTC (rev 262989)
@@ -1,3 +1,49 @@
+2020-06-12  Alan Coon  <[email protected]>
+
+        Cherry-pick r262707. rdar://problem/64226888
+
+    File URLs with hostnames are misleading
+    https://bugs.webkit.org/show_bug.cgi?id=212739
+    <rdar://problem/63754917>
+    
+    Reviewed by Alex Christensen.
+    
+    Source/WebCore:
+    
+    Showing a file URL like file://example.org/test is misleading to users.
+    To prevent this, we just do a redirection to the same file URL with an empty host.
+    Remove the port at the same time.
+    Covered by added API test.
+    
+    * loader/DocumentLoader.cpp:
+    (WebCore::DocumentLoader::willSendRequest):
+    
+    Tools:
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/WebKit/open-window-with-file-url-with-host.html: Added.
+    * TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm:
+    (TEST):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@262707 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-06-08  Youenn Fablet  <[email protected]>
+
+            File URLs with hostnames are misleading
+            https://bugs.webkit.org/show_bug.cgi?id=212739
+            <rdar://problem/63754917>
+
+            Reviewed by Alex Christensen.
+
+            Showing a file URL like file://example.org/test is misleading to users.
+            To prevent this, we just do a redirection to the same file URL with an empty host.
+            Remove the port at the same time.
+            Covered by added API test.
+
+            * loader/DocumentLoader.cpp:
+            (WebCore::DocumentLoader::willSendRequest):
+
 2020-06-11  Alan Coon  <[email protected]>
 
         Cherry-pick r261217. rdar://problem/62978240

Modified: branches/safari-609-branch/Source/WebCore/loader/DocumentLoader.cpp (262988 => 262989)


--- branches/safari-609-branch/Source/WebCore/loader/DocumentLoader.cpp	2020-06-13 00:06:33 UTC (rev 262988)
+++ branches/safari-609-branch/Source/WebCore/loader/DocumentLoader.cpp	2020-06-13 00:06:38 UTC (rev 262989)
@@ -647,6 +647,12 @@
         }
     }
 
+    if (!newRequest.url().host().isEmpty() && SecurityOrigin::shouldIgnoreHost(newRequest.url())) {
+        auto url = ""
+        url.setHostAndPort({ });
+        newRequest.setURL(WTFMove(url));
+    }
+
 #if ENABLE(CONTENT_FILTERING)
     if (m_contentFilter && !m_contentFilter->continueAfterWillSendRequest(newRequest, redirectResponse))
         return completionHandler(WTFMove(newRequest));

Modified: branches/safari-609-branch/Tools/ChangeLog (262988 => 262989)


--- branches/safari-609-branch/Tools/ChangeLog	2020-06-13 00:06:33 UTC (rev 262988)
+++ branches/safari-609-branch/Tools/ChangeLog	2020-06-13 00:06:38 UTC (rev 262989)
@@ -1,3 +1,46 @@
+2020-06-12  Alan Coon  <[email protected]>
+
+        Cherry-pick r262707. rdar://problem/64226888
+
+    File URLs with hostnames are misleading
+    https://bugs.webkit.org/show_bug.cgi?id=212739
+    <rdar://problem/63754917>
+    
+    Reviewed by Alex Christensen.
+    
+    Source/WebCore:
+    
+    Showing a file URL like file://example.org/test is misleading to users.
+    To prevent this, we just do a redirection to the same file URL with an empty host.
+    Remove the port at the same time.
+    Covered by added API test.
+    
+    * loader/DocumentLoader.cpp:
+    (WebCore::DocumentLoader::willSendRequest):
+    
+    Tools:
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/WebKit/open-window-with-file-url-with-host.html: Added.
+    * TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm:
+    (TEST):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@262707 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-06-08  Youenn Fablet  <[email protected]>
+
+            File URLs with hostnames are misleading
+            https://bugs.webkit.org/show_bug.cgi?id=212739
+            <rdar://problem/63754917>
+
+            Reviewed by Alex Christensen.
+
+            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+            * TestWebKitAPI/Tests/WebKit/open-window-with-file-url-with-host.html: Added.
+            * TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm:
+            (TEST):
+
 2020-06-12  Ryan Haddad  <[email protected]>
 
         Cherry-pick r261243. rdar://problem/61953702

Modified: branches/safari-609-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (262988 => 262989)


--- branches/safari-609-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-06-13 00:06:33 UTC (rev 262988)
+++ branches/safari-609-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-06-13 00:06:38 UTC (rev 262989)
@@ -222,6 +222,7 @@
 		4135FB852011FABF00332139 /* libWebCoreTestSupport.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4135FB862011FABF00332139 /* libWebCoreTestSupport.dylib */; };
 		414AD6862285D1C000777F2D /* StorageQuota.mm in Sources */ = {isa = PBXBuildFile; fileRef = 414AD6852285D1B000777F2D /* StorageQuota.mm */; };
 		41661C662355E85E00D33C27 /* getUserMedia-webaudio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 41661C652355D98B00D33C27 /* getUserMedia-webaudio.html */; };
+		41848F4424891879000E2588 /* open-window-with-file-url-with-host.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 41848F4324891815000E2588 /* open-window-with-file-url-with-host.html */; };
 		41882F0321010C0D002FF288 /* ProcessPreWarming.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41882F0221010A70002FF288 /* ProcessPreWarming.mm */; };
 		44077BB123144B5000179E2D /* DataDetectorsTestIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44077BB0231449D200179E2D /* DataDetectorsTestIOS.mm */; };
 		4433A396208044140091ED57 /* SynchronousTimeoutTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4433A395208044130091ED57 /* SynchronousTimeoutTests.mm */; };
@@ -1408,6 +1409,7 @@
 				CEA6CF2819CCF69D0064F5A7 /* open-and-close-window.html in Copy Resources */,
 				7CCB99231D3B4A46003922F6 /* open-multiple-external-url.html in Copy Resources */,
 				468BC45522653A1000A36C96 /* open-window-then-write-to-it.html in Copy Resources */,
+				41848F4424891879000E2588 /* open-window-with-file-url-with-host.html in Copy Resources */,
 				931C281E22BC579A001D98C4 /* opendatabase-always-exists.html in Copy Resources */,
 				290A9BB91735F63800D71BBC /* OpenNewWindow.html in Copy Resources */,
 				0F340779230382870060A1A0 /* overflow-scroll.html in Copy Resources */,
@@ -1766,6 +1768,7 @@
 		4135FB862011FABF00332139 /* libWebCoreTestSupport.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; path = libWebCoreTestSupport.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
 		414AD6852285D1B000777F2D /* StorageQuota.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = StorageQuota.mm; sourceTree = "<group>"; };
 		41661C652355D98B00D33C27 /* getUserMedia-webaudio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "getUserMedia-webaudio.html"; sourceTree = "<group>"; };
+		41848F4324891815000E2588 /* open-window-with-file-url-with-host.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "open-window-with-file-url-with-host.html"; sourceTree = "<group>"; };
 		41882F0221010A70002FF288 /* ProcessPreWarming.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProcessPreWarming.mm; sourceTree = "<group>"; };
 		41973B5C1AF22875006C7B36 /* SharedBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedBuffer.cpp; sourceTree = "<group>"; };
 		44077BB0231449D200179E2D /* DataDetectorsTestIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataDetectorsTestIOS.mm; sourceTree = "<group>"; };
@@ -3900,6 +3903,7 @@
 				4A410F4D19AF7BEF002EBAB6 /* ondevicechange.html */,
 				CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */,
 				468BC454226539C800A36C96 /* open-window-then-write-to-it.html */,
+				41848F4324891815000E2588 /* open-window-with-file-url-with-host.html */,
 				83148B08202AC76800BADE99 /* override-builtins-test.html */,
 				0EBBCC651FFF9DCE00FA42AB /* pop-up-check.html */,
 				F6FDDDD514241C48004F1729 /* push-state.html */,

Added: branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKit/open-window-with-file-url-with-host.html (0 => 262989)


--- branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKit/open-window-with-file-url-with-host.html	                        (rev 0)
+++ branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKit/open-window-with-file-url-with-host.html	2020-06-13 00:06:38 UTC (rev 262989)
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script>
+    if (location.hash !== "#test")
+        window.open("file://example.org" + location.pathname + "#test", "_self");
+</script>
+</body>
+</html>

Modified: branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm (262988 => 262989)


--- branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm	2020-06-13 00:06:33 UTC (rev 262988)
+++ branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm	2020-06-13 00:06:38 UTC (rev 262989)
@@ -319,3 +319,23 @@
 
     EXPECT_TRUE([[[openedWebView _mainFrameURL] absoluteString] isEqualToString:[[webView URL] absoluteString]]);
 }
+
+TEST(WebKit, OpenFileURLWithHost)
+{
+    resetToConsistentState();
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto uiDelegate = adoptNS([[OpenWindowThenDocumentOpenUIDelegate alloc] init]);
+    [webView setUIDelegate:uiDelegate.get()];
+    [webView configuration].preferences._javascript_CanOpenWindowsAutomatically = YES;
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"open-window-with-file-url-with-host" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+
+    while (![[[webView URL] absoluteString] hasSuffix:@"#test"])
+        TestWebKitAPI::Util::spinRunLoop();
+
+    while (![[[webView URL] absoluteString] hasPrefix:@"file:///"])
+        TestWebKitAPI::Util::spinRunLoop();
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to