Title: [125126] trunk/Source/WebCore
Revision
125126
Author
[email protected]
Date
2012-08-08 17:41:02 -0700 (Wed, 08 Aug 2012)

Log Message

Rewire the same-origin checks for the _javascript_Core bindings through BindingSecurity
https://bugs.webkit.org/show_bug.cgi?id=93382

Reviewed by Eric Seidel.

This patch rewires the same-origin policy checks in the _javascript_Core
bindings to use the implementation in BindingSecurity.cpp, which is now
shared by _javascript_Core and V8. There are still a few places were we
use the JSDOMWindowCustom-based code path, but I plan to change those
in a follow up patch in the interest of keeping this patch as small as
possible.

This patch as two main benefits:

1) We no longer need to maintain duplicate code in the JSC and the V8
   bindings for as delicate an area as the same-origin check.
   Previously, the two implementations accomplished the same task using
   a slightly different mechansim. After this patch, they use the same
   mechanism, which means we only need to convince ourselves that one
   implementation is correct.

2) This patch will make it easier to remove DOMWindow::m_securityOrigin
   because there will be only one piece of code that needs to change.
   Prior to this patch, we would have had to change both
   implementations of the same-origin policy not to rely upon
   DOMWindow::m_securityOrigin.

* bindings/js/BindingState.cpp:
(WebCore::immediatelyReportUnsafeAccessTo):
(WebCore):
* bindings/js/BindingState.h:
(WebCore):
* bindings/js/JSDOMBinding.cpp:
(WebCore::shouldAllowAccessToNode):
(WebCore::shouldAllowAccessToFrame):

Modified Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (125125 => 125126)


--- trunk/Source/WebCore/CMakeLists.txt	2012-08-09 00:40:37 UTC (rev 125125)
+++ trunk/Source/WebCore/CMakeLists.txt	2012-08-09 00:41:02 UTC (rev 125126)
@@ -973,6 +973,7 @@
     bindings/ScriptControllerBase.cpp
 
     bindings/generic/ActiveDOMCallback.cpp
+    bindings/generic/BindingSecurity.cpp
     bindings/generic/RuntimeEnabledFeatures.cpp
 
     css/CSSAspectRatioValue.cpp

Modified: trunk/Source/WebCore/ChangeLog (125125 => 125126)


--- trunk/Source/WebCore/ChangeLog	2012-08-09 00:40:37 UTC (rev 125125)
+++ trunk/Source/WebCore/ChangeLog	2012-08-09 00:41:02 UTC (rev 125126)
@@ -1,3 +1,41 @@
+2012-08-08  Adam Barth  <[email protected]>
+
+        Rewire the same-origin checks for the _javascript_Core bindings through BindingSecurity
+        https://bugs.webkit.org/show_bug.cgi?id=93382
+
+        Reviewed by Eric Seidel.
+
+        This patch rewires the same-origin policy checks in the _javascript_Core
+        bindings to use the implementation in BindingSecurity.cpp, which is now
+        shared by _javascript_Core and V8. There are still a few places were we
+        use the JSDOMWindowCustom-based code path, but I plan to change those
+        in a follow up patch in the interest of keeping this patch as small as
+        possible.
+
+        This patch as two main benefits:
+
+        1) We no longer need to maintain duplicate code in the JSC and the V8
+           bindings for as delicate an area as the same-origin check.
+           Previously, the two implementations accomplished the same task using
+           a slightly different mechansim. After this patch, they use the same
+           mechanism, which means we only need to convince ourselves that one
+           implementation is correct.
+
+        2) This patch will make it easier to remove DOMWindow::m_securityOrigin
+           because there will be only one piece of code that needs to change.
+           Prior to this patch, we would have had to change both
+           implementations of the same-origin policy not to rely upon
+           DOMWindow::m_securityOrigin.
+
+        * bindings/js/BindingState.cpp:
+        (WebCore::immediatelyReportUnsafeAccessTo):
+        (WebCore):
+        * bindings/js/BindingState.h:
+        (WebCore):
+        * bindings/js/JSDOMBinding.cpp:
+        (WebCore::shouldAllowAccessToNode):
+        (WebCore::shouldAllowAccessToFrame):
+
 2012-08-08  Brady Eidson  <[email protected]>
 
         Google search query text reverts to original search query after multiple searches

Modified: trunk/Source/WebCore/bindings/js/BindingState.cpp (125125 => 125126)


--- trunk/Source/WebCore/bindings/js/BindingState.cpp	2012-08-09 00:40:37 UTC (rev 125125)
+++ trunk/Source/WebCore/bindings/js/BindingState.cpp	2012-08-09 00:41:02 UTC (rev 125126)
@@ -47,4 +47,9 @@
     return asJSDOMWindow(exec->dynamicGlobalObject())->impl();
 }
 
+void immediatelyReportUnsafeAccessTo(ExecState* exec, Document* target)
+{
+    printErrorMessageForFrame(target->frame(), target->domWindow()->crossDomainAccessErrorMessage(activeDOMWindow(exec)));
 }
+
+}

Modified: trunk/Source/WebCore/bindings/js/BindingState.h (125125 => 125126)


--- trunk/Source/WebCore/bindings/js/BindingState.h	2012-08-09 00:40:37 UTC (rev 125125)
+++ trunk/Source/WebCore/bindings/js/BindingState.h	2012-08-09 00:41:02 UTC (rev 125126)
@@ -48,7 +48,7 @@
 inline Frame* activeFrame(BindingState*) { return 0; }
 inline Frame* firstFrame(BindingState*) { return 0; }
 
-inline void immediatelyReportUnsafeAccessTo(BindingState*, Document*) { }
+void immediatelyReportUnsafeAccessTo(BindingState*, Document* target);
 
 }
 

Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp (125125 => 125126)


--- trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp	2012-08-09 00:40:37 UTC (rev 125125)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp	2012-08-09 00:41:02 UTC (rev 125126)
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "JSDOMBinding.h"
 
+#include "BindingSecurity.h"
 #include "DOMObjectHashTableMap.h"
 #include "DOMStringList.h"
 #include "ExceptionCode.h"
@@ -223,23 +224,22 @@
 
 bool shouldAllowAccessToNode(ExecState* exec, Node* node)
 {
-    return node && shouldAllowAccessToFrame(exec, node->document()->frame());
+    return BindingSecurity::shouldAllowAccessToNode(exec, node);
 }
 
 bool shouldAllowAccessToFrame(ExecState* exec, Frame* frame)
 {
-    if (!frame)
-        return false;
-    JSDOMWindow* window = toJSDOMWindow(frame, currentWorld(exec));
-    return window && window->allowsAccessFrom(exec);
+    return BindingSecurity::shouldAllowAccessToFrame(exec, frame);
 }
 
 bool shouldAllowAccessToFrame(ExecState* exec, Frame* frame, String& message)
 {
     if (!frame)
         return false;
-    JSDOMWindow* window = toJSDOMWindow(frame, currentWorld(exec));
-    return window && window->allowsAccessFrom(exec, message);
+    bool result = BindingSecurity::shouldAllowAccessToFrame(exec, frame, DoNotReportSecurityError);
+    // FIXME: The following line of code should move somewhere that it can be shared with immediatelyReportUnsafeAccessTo.
+    message = frame->domWindow()->crossDomainAccessErrorMessage(activeDOMWindow(exec));
+    return result;
 }
 
 void printErrorMessageForFrame(Frame* frame, const String& message)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to