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

Changeset 245538 in webkit


Ignore:
Timestamp:
May 20, 2019, 3:53:03 PM (7 years ago)
Author:
Chris Dumez
Message:

Fix security check in ScriptController::canAccessFromCurrentOrigin()
https://bugs.webkit.org/show_bug.cgi?id=196730
<rdar://problem/49731231>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Fix security check in ScriptController::canAccessFromCurrentOrigin() when there is no
current JS exec state. Instead of returning true unconditionally, we now fall back to
using the accessing document's origin for the security check. The new behavior is
aligned with Blink:
https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/html/html_frame_element_base.cc?rcl=d3f22423d512b45466f1694020e20da9e0c6ee6a&l=62

This fix is based on a patch from Sergei Glazunov <glazunov@google.com>.

Test: http/tests/security/showModalDialog-sync-cross-origin-page-load2.html

  • bindings/js/ScriptController.cpp:

(WebCore::ScriptController::canAccessFromCurrentOrigin):

  • bindings/js/ScriptController.h:
  • html/HTMLFrameElementBase.cpp:

(WebCore::HTMLFrameElementBase::isURLAllowed const):

LayoutTests:

Add layout test coverage.

  • http/tests/security/showModalDialog-sync-cross-origin-page-load2-expected.txt: Added.
  • http/tests/security/showModalDialog-sync-cross-origin-page-load2.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r245534 r245538  
     12019-05-20  Chris Dumez  <cdumez@apple.com>
     2
     3        Fix security check in ScriptController::canAccessFromCurrentOrigin()
     4        https://bugs.webkit.org/show_bug.cgi?id=196730
     5        <rdar://problem/49731231>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Add layout test coverage.
     10
     11        * http/tests/security/showModalDialog-sync-cross-origin-page-load2-expected.txt: Added.
     12        * http/tests/security/showModalDialog-sync-cross-origin-page-load2.html: Added.
     13
    1142019-05-20  Gabe Giosia  <giosia@google.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r245534 r245538  
     12019-05-20  Chris Dumez  <cdumez@apple.com>
     2
     3        Fix security check in ScriptController::canAccessFromCurrentOrigin()
     4        https://bugs.webkit.org/show_bug.cgi?id=196730
     5        <rdar://problem/49731231>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Fix security check in ScriptController::canAccessFromCurrentOrigin() when there is no
     10        current JS exec state. Instead of returning true unconditionally, we now fall back to
     11        using the accessing document's origin for the security check. The new behavior is
     12        aligned with Blink:
     13        https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/html/html_frame_element_base.cc?rcl=d3f22423d512b45466f1694020e20da9e0c6ee6a&l=62
     14
     15        This fix is based on a patch from Sergei Glazunov <glazunov@google.com>.
     16
     17        Test: http/tests/security/showModalDialog-sync-cross-origin-page-load2.html
     18
     19        * bindings/js/ScriptController.cpp:
     20        (WebCore::ScriptController::canAccessFromCurrentOrigin):
     21        * bindings/js/ScriptController.h:
     22        * html/HTMLFrameElementBase.cpp:
     23        (WebCore::HTMLFrameElementBase::isURLAllowed const):
     24
    1252019-05-20  Gabe Giosia  <giosia@google.com>
    226
  • trunk/Source/WebCore/bindings/js/ScriptController.cpp

    r245508 r245538  
    384384}
    385385
    386 bool ScriptController::canAccessFromCurrentOrigin(Frame* frame)
     386bool ScriptController::canAccessFromCurrentOrigin(Frame* frame, Document& accessingDocument)
    387387{
    388388    auto* state = JSExecState::currentState();
    389389
    390     // If the current state is null we're in a call path where the DOM security check doesn't apply (eg. parser).
    391     if (!state)
    392         return true;
     390    // If the current state is null we should use the accessing document for the security check.
     391    if (!state) {
     392        auto* targetDocument = frame ? frame->document() : nullptr;
     393        return targetDocument && accessingDocument.securityOrigin().canAccess(targetDocument->securityOrigin());
     394    }
    393395
    394396    return BindingSecurity::shouldAllowAccessToFrame(state, frame);
  • trunk/Source/WebCore/bindings/js/ScriptController.h

    r243324 r245538  
    124124    void disableWebAssembly(const String& errorMessage);
    125125
    126     static bool canAccessFromCurrentOrigin(Frame*);
     126    static bool canAccessFromCurrentOrigin(Frame*, Document& accessingDocument);
    127127    WEBCORE_EXPORT bool canExecuteScripts(ReasonForCallingCanExecuteScripts);
    128128
  • trunk/Source/WebCore/html/HTMLFrameElementBase.cpp

    r238771 r245538  
    7474    if (WTF::protocolIsJavaScript(completeURL)) {
    7575        RefPtr<Document> contentDoc = this->contentDocument();
    76         if (contentDoc && !ScriptController::canAccessFromCurrentOrigin(contentDoc->frame()))
     76        if (contentDoc && !ScriptController::canAccessFromCurrentOrigin(contentDoc->frame(), document()))
    7777            return false;
    7878    }
Note: See TracChangeset for help on using the changeset viewer.