⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 238562 in webkit


Ignore:
Timestamp:
Nov 27, 2018, 11:38:18 AM (8 years ago)
Author:
jiewen_tan@apple.com
Message:

Disallow loading webarchives as iframes
https://bugs.webkit.org/show_bug.cgi?id=191728
<rdar://problem/45524528>

Reviewed by Youenn Fablet.

Source/WebCore:

Disallow loading webarchives as iframes. We don't allow loading remote webarchives.
Now, this policy is hardened to disallow loading webarchives as iframes for local
documents as well.

To allow old tests still be able to run, a flag is added to always allow loading local
webarchives in document. The flag can be set via window.internals.

Tests: webarchive/loading/test-loading-archive-subresource.html

webarchive/loading/test-loading-top-archive.html

  • dom/Document.h:

(WebCore::Document::setAlwaysAllowLocalWebarchive):
(WebCore::Document::alwaysAllowLocalWebarchive):

  • loader/DocumentLoader.cpp:

(WebCore::disallowWebArchive):
(WebCore::DocumentLoader::continueAfterContentPolicy):
(WebCore::isRemoteWebArchive): Deleted.

  • testing/Internals.cpp:

(WebCore::Internals::setAlwaysAllowLocalWebarchive const):

  • testing/Internals.h:
  • testing/Internals.idl:

Source/WebKit:

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::unableToImplementPolicy):
Add a check to prevent null pointer dereference.

LayoutTests:

  • platform/mac-wk1/webarchive/loading/test-loading-archive-subresource-expected.txt: Added.
  • platform/mac/fast/loader/webarchive-encoding-respected.html:
  • webarchive/loading/cache-expired-subresource.html:
  • webarchive/loading/mainresource-null-mimetype-crash.html:
  • webarchive/loading/missing-data.html:
  • webarchive/loading/resources/test-loading-archive-main.webarchive: Copied from LayoutTests/webarchive/loading/test-loading-archive.html.
  • webarchive/loading/test-loading-archive-subresource-expected.txt: Added.
  • webarchive/loading/test-loading-archive-subresource-null-mimetype.html:
  • webarchive/loading/test-loading-archive-subresource.html: Copied from LayoutTests/webarchive/loading/test-loading-archive.html.
  • webarchive/loading/test-loading-archive.html:
  • webarchive/loading/test-loading-top-archive-expected.txt: Added.
  • webarchive/loading/test-loading-top-archive.html: Added.
Location:
trunk
Files:
7 added
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r238555 r238562  
     12018-11-16  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        Disallow loading webarchives as iframes
     4        https://bugs.webkit.org/show_bug.cgi?id=191728
     5        <rdar://problem/45524528>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        * platform/mac-wk1/webarchive/loading/test-loading-archive-subresource-expected.txt: Added.
     10        * platform/mac/fast/loader/webarchive-encoding-respected.html:
     11        * webarchive/loading/cache-expired-subresource.html:
     12        * webarchive/loading/mainresource-null-mimetype-crash.html:
     13        * webarchive/loading/missing-data.html:
     14        * webarchive/loading/resources/test-loading-archive-main.webarchive: Copied from LayoutTests/webarchive/loading/test-loading-archive.html.
     15        * webarchive/loading/test-loading-archive-subresource-expected.txt: Added.
     16        * webarchive/loading/test-loading-archive-subresource-null-mimetype.html:
     17        * webarchive/loading/test-loading-archive-subresource.html: Copied from LayoutTests/webarchive/loading/test-loading-archive.html.
     18        * webarchive/loading/test-loading-archive.html:
     19        * webarchive/loading/test-loading-top-archive-expected.txt: Added.
     20        * webarchive/loading/test-loading-top-archive.html: Added.
     21
    1222018-11-27  Per Arne Vollan  <pvollan@apple.com>
    223
  • trunk/LayoutTests/platform/mac/fast/loader/webarchive-encoding-respected.html

    r122687 r238562  
    44        testRunner.dumpChildFramesAsText();
    55}
     6if (window.internals)
     7    internals.setAlwaysAllowLocalWebarchive();
    68</script>
    79The webarchive in this iframe is utf-8 encoded and will only display properly if the webarchive's encoding is respected.<br>
  • trunk/LayoutTests/webarchive/loading/cache-expired-subresource.html

    r120521 r238562  
    55        testRunner.waitUntilDone();
    66    }
     7    if (window.internals)
     8        internals.setAlwaysAllowLocalWebarchive();
    79   
    810    function frameLoaded() {
  • trunk/LayoutTests/webarchive/loading/mainresource-null-mimetype-crash.html

    r217680 r238562  
    55        testRunner.waitUntilDone();
    66    }
     7    if (window.internals)
     8        internals.setAlwaysAllowLocalWebarchive();
    79    onload = function() {
    810        frame = document.createElement("iframe");
  • trunk/LayoutTests/webarchive/loading/missing-data.html

    r217680 r238562  
    44        testRunner.dumpAsText();
    55    }
    6 
     6    if (window.internals)
     7        internals.setAlwaysAllowLocalWebarchive();
    78    onload = function() {
    89        frame = document.createElement("iframe");
  • trunk/LayoutTests/webarchive/loading/test-loading-archive-subresource-null-mimetype.html

    r120521 r238562  
    66        testRunner.waitUntilDone();
    77    }
    8    
     8    if (window.internals)
     9        internals.setAlwaysAllowLocalWebarchive();
    910    function frameLoaded() {
    1011        if (window.testRunner)
  • trunk/LayoutTests/webarchive/loading/test-loading-archive-subresource.html

    r238561 r238562  
    22<script>
    33    if (window.testRunner) {
    4         testRunner.dumpResourceLoadCallbacks();
    54        testRunner.dumpAsText();
    65        testRunner.waitUntilDone();
    76    }
    8    
     7
    98    function frameLoaded() {
    109        if (window.testRunner)
    1110            testRunner.notifyDone();
    1211    }
     12    setTimeout(frameLoaded, 10);
    1313</script>
    1414<body>
    1515    <iframe onload="frameLoaded();" src="resources/helloworld.webarchive"></iframe>
    16     This tests that doing a "normal load" of a webarchive (not using loadArchive) does not cause a cancelled error to be called.
     16    This test assumes the webarchive is not loaded.
    1717</body>
    1818</html>
  • trunk/LayoutTests/webarchive/loading/test-loading-archive.html

    r120521 r238562  
    66        testRunner.waitUntilDone();
    77    }
    8    
     8    if (window.internals)
     9        internals.setAlwaysAllowLocalWebarchive();
    910    function frameLoaded() {
    1011        if (window.testRunner)
  • trunk/Source/WebCore/ChangeLog

    r238561 r238562  
     12018-11-16  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        Disallow loading webarchives as iframes
     4        https://bugs.webkit.org/show_bug.cgi?id=191728
     5        <rdar://problem/45524528>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        Disallow loading webarchives as iframes. We don't allow loading remote webarchives.
     10        Now, this policy is hardened to disallow loading webarchives as iframes for local
     11        documents as well.
     12
     13        To allow old tests still be able to run, a flag is added to always allow loading local
     14        webarchives in document. The flag can be set via window.internals.
     15
     16        Tests: webarchive/loading/test-loading-archive-subresource.html
     17               webarchive/loading/test-loading-top-archive.html
     18
     19        * dom/Document.h:
     20        (WebCore::Document::setAlwaysAllowLocalWebarchive):
     21        (WebCore::Document::alwaysAllowLocalWebarchive):
     22        * loader/DocumentLoader.cpp:
     23        (WebCore::disallowWebArchive):
     24        (WebCore::DocumentLoader::continueAfterContentPolicy):
     25        (WebCore::isRemoteWebArchive): Deleted.
     26        * testing/Internals.cpp:
     27        (WebCore::Internals::setAlwaysAllowLocalWebarchive const):
     28        * testing/Internals.h:
     29        * testing/Internals.idl:
     30
    1312018-11-27  Jer Noble  <jer.noble@apple.com>
    232
  • trunk/Source/WebCore/dom/Document.h

    r238001 r238562  
    15311531    void frameWasDisconnectedFromOwner();
    15321532
     1533    // Used in webarchive loading tests.
     1534    void setAlwaysAllowLocalWebarchive() { m_alwaysAllowLocalWebarchive = true; }
     1535    bool alwaysAllowLocalWebarchive() const { return m_alwaysAllowLocalWebarchive; }
     1536
    15331537protected:
    15341538    enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
     
    20702074
    20712075    bool m_isRunningUserScripts { false };
     2076
     2077    bool m_alwaysAllowLocalWebarchive { false };
    20722078};
    20732079
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r237266 r238562  
    842842}
    843843
    844 static bool isRemoteWebArchive(const DocumentLoader& documentLoader)
     844// Prevent web archives from loading if it is remote or it is not the main frame because they
     845// can claim to be from any domain and thus avoid cross-domain security checks (4120255, 45524528).
     846bool DocumentLoader::disallowWebArchive() const
    845847{
    846848    using MIMETypeHashSet = HashSet<String, ASCIICaseInsensitiveHash>;
     
    856858    };
    857859
    858     const ResourceResponse& response = documentLoader.response();
    859     String mimeType = response.mimeType();
     860    String mimeType = m_response.mimeType();
    860861    if (mimeType.isNull() || !webArchiveMIMETypes.get().contains(mimeType))
    861862        return false;
    862863
    863864#if USE(QUICK_LOOK)
    864     if (isQuickLookPreviewURL(response.url()))
     865    if (isQuickLookPreviewURL(m_response.url()))
    865866        return false;
    866867#endif
    867868
    868     return !documentLoader.substituteData().isValid() && !SchemeRegistry::shouldTreatURLSchemeAsLocal(documentLoader.request().url().protocol().toStringWithoutCopying());
     869    if (m_substituteData.isValid())
     870        return false;
     871
     872    if (!SchemeRegistry::shouldTreatURLSchemeAsLocal(m_request.url().protocol().toStringWithoutCopying()))
     873        return true;
     874
     875    if (!frame() || frame()->isMainFrame())
     876        return false;
     877
     878    // On purpose of maintaining existing tests.
     879    if (!frame()->document() || frame()->document()->topDocument().alwaysAllowLocalWebarchive())
     880        return false;
     881    return true;
    869882}
    870883
     
    878891    switch (policy) {
    879892    case PolicyAction::Use: {
    880         // Prevent remote web archives from loading because they can claim to be from any domain and thus avoid cross-domain security checks (4120255).
    881         if (!frameLoader()->client().canShowMIMEType(m_response.mimeType()) || isRemoteWebArchive(*this)) {
     893        if (!frameLoader()->client().canShowMIMEType(m_response.mimeType()) || disallowWebArchive()) {
    882894            frameLoader()->policyChecker().cannotShowMIMEType(m_response);
    883895            // Check reachedTerminalState since the load may have already been canceled inside of _handleUnimplementablePolicyWithErrorCode::.
  • trunk/Source/WebCore/loader/DocumentLoader.h

    r237266 r238562  
    415415    WEBCORE_EXPORT void enqueueSecurityPolicyViolationEvent(SecurityPolicyViolationEvent::Init&&) final;
    416416
     417    bool disallowWebArchive() const;
     418
    417419    Ref<CachedResourceLoader> m_cachedResourceLoader;
    418420
  • trunk/Source/WebCore/testing/Internals.cpp

    r238378 r238562  
    48254825}
    48264826
     4827void Internals::setAlwaysAllowLocalWebarchive() const
     4828{
     4829    auto* document = contextDocument();
     4830    if (!document)
     4831        return;
     4832    document->setAlwaysAllowLocalWebarchive();
     4833}
     4834
    48274835} // namespace WebCore
  • trunk/Source/WebCore/testing/Internals.h

    r238345 r238562  
    786786    Vector<CookieData> getCookies() const;
    787787
     788    void setAlwaysAllowLocalWebarchive() const;
     789
    788790private:
    789791    explicit Internals(Document&);
  • trunk/Source/WebCore/testing/Internals.idl

    r238345 r238562  
    724724
    725725    sequence<CookieData> getCookies();
    726 };
     726
     727    void setAlwaysAllowLocalWebarchive();
     728};
  • trunk/Source/WebKit/ChangeLog

    r238553 r238562  
     12018-11-16  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        Disallow loading webarchives as iframes
     4        https://bugs.webkit.org/show_bug.cgi?id=191728
     5        <rdar://problem/45524528>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        * UIProcess/WebPageProxy.cpp:
     10        (WebKit::WebPageProxy::unableToImplementPolicy):
     11        Add a check to prevent null pointer dereference.
     12
    1132018-11-27  Wenson Hsieh  <wenson_hsieh@apple.com>
    214
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r238538 r238562  
    44154415    MESSAGE_CHECK(frame);
    44164416
     4417    if (!m_policyClient)
     4418        return;
    44174419    m_policyClient->unableToImplementPolicy(*this, *frame, error, m_process->transformHandlesToObjects(userData.object()).get());
    44184420}
Note: See TracChangeset for help on using the changeset viewer.