Changeset 262707 in webkit


Ignore:
Timestamp:
Jun 8, 2020 4:33:16 AM (4 years ago)
Author:
youenn@apple.com
Message:

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):

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r262704 r262707  
     12020-06-08  Youenn Fablet  <youenn@apple.com>
     2
     3        File URLs with hostnames are misleading
     4        https://bugs.webkit.org/show_bug.cgi?id=212739
     5        <rdar://problem/63754917>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Showing a file URL like file://example.org/test is misleading to users.
     10        To prevent this, we just do a redirection to the same file URL with an empty host.
     11        Remove the port at the same time.
     12        Covered by added API test.
     13
     14        * loader/DocumentLoader.cpp:
     15        (WebCore::DocumentLoader::willSendRequest):
     16
    1172020-06-08  Rob Buis  <rbuis@igalia.com>
    218
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r262704 r262707  
    655655    }
    656656
     657    if (!newRequest.url().host().isEmpty() && SecurityOrigin::shouldIgnoreHost(newRequest.url())) {
     658        auto url = newRequest.url();
     659        url.setHostAndPort({ });
     660        newRequest.setURL(WTFMove(url));
     661    }
     662
    657663#if ENABLE(CONTENT_FILTERING)
    658664    if (m_contentFilter && !m_contentFilter->continueAfterWillSendRequest(newRequest, redirectResponse))
  • trunk/Tools/ChangeLog

    r262696 r262707  
     12020-06-08  Youenn Fablet  <youenn@apple.com>
     2
     3        File URLs with hostnames are misleading
     4        https://bugs.webkit.org/show_bug.cgi?id=212739
     5        <rdar://problem/63754917>
     6
     7        Reviewed by Alex Christensen.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WebKit/open-window-with-file-url-with-host.html: Added.
     11        * TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm:
     12        (TEST):
     13
    1142020-06-07  Caio Lima  <ticaiolima@gmail.com>
    215
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r262507 r262707  
    231231                414AD6862285D1C000777F2D /* StorageQuota.mm in Sources */ = {isa = PBXBuildFile; fileRef = 414AD6852285D1B000777F2D /* StorageQuota.mm */; };
    232232                41661C662355E85E00D33C27 /* getUserMedia-webaudio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 41661C652355D98B00D33C27 /* getUserMedia-webaudio.html */; };
     233                41848F4424891879000E2588 /* open-window-with-file-url-with-host.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 41848F4324891815000E2588 /* open-window-with-file-url-with-host.html */; };
    233234                41882F0321010C0D002FF288 /* ProcessPreWarming.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41882F0221010A70002FF288 /* ProcessPreWarming.mm */; };
    234235                44077BB123144B5000179E2D /* DataDetectorsTestIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44077BB0231449D200179E2D /* DataDetectorsTestIOS.mm */; };
     
    14921493                                7CCB99231D3B4A46003922F6 /* open-multiple-external-url.html in Copy Resources */,
    14931494                                468BC45522653A1000A36C96 /* open-window-then-write-to-it.html in Copy Resources */,
     1495                                41848F4424891879000E2588 /* open-window-with-file-url-with-host.html in Copy Resources */,
    14941496                                931C281E22BC579A001D98C4 /* opendatabase-always-exists.html in Copy Resources */,
    14951497                                290A9BB91735F63800D71BBC /* OpenNewWindow.html in Copy Resources */,
     
    18791881                414AD6852285D1B000777F2D /* StorageQuota.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = StorageQuota.mm; sourceTree = "<group>"; };
    18801882                41661C652355D98B00D33C27 /* getUserMedia-webaudio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "getUserMedia-webaudio.html"; sourceTree = "<group>"; };
     1883                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>"; };
    18811884                41882F0221010A70002FF288 /* ProcessPreWarming.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProcessPreWarming.mm; sourceTree = "<group>"; };
    18821885                41973B5C1AF22875006C7B36 /* SharedBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedBuffer.cpp; sourceTree = "<group>"; };
     
    41494152                                CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */,
    41504153                                468BC454226539C800A36C96 /* open-window-then-write-to-it.html */,
     4154                                41848F4324891815000E2588 /* open-window-with-file-url-with-host.html */,
    41514155                                83148B08202AC76800BADE99 /* override-builtins-test.html */,
    41524156                                0EBBCC651FFF9DCE00FA42AB /* pop-up-check.html */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/OpenAndCloseWindow.mm

    r260366 r262707  
    320320    EXPECT_TRUE([[[openedWebView _mainFrameURL] absoluteString] isEqualToString:[[webView URL] absoluteString]]);
    321321}
     322
     323TEST(WebKit, OpenFileURLWithHost)
     324{
     325    resetToConsistentState();
     326
     327    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
     328
     329    auto uiDelegate = adoptNS([[OpenWindowThenDocumentOpenUIDelegate alloc] init]);
     330    [webView setUIDelegate:uiDelegate.get()];
     331    [webView configuration].preferences.javaScriptCanOpenWindowsAutomatically = YES;
     332
     333    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"open-window-with-file-url-with-host" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     334    [webView loadRequest:request];
     335
     336    while (![[[webView URL] absoluteString] hasSuffix:@"#test"])
     337        TestWebKitAPI::Util::spinRunLoop();
     338
     339    while (![[[webView URL] absoluteString] hasPrefix:@"file:///"])
     340        TestWebKitAPI::Util::spinRunLoop();
     341}
Note: See TracChangeset for help on using the changeset viewer.