Title: [97270] trunk/Source
Revision
97270
Author
[email protected]
Date
2011-10-12 10:05:41 -0700 (Wed, 12 Oct 2011)

Log Message

ScriptController::executeIfJavaScriptURL gets confused by synchronous frame loads
https://bugs.webkit.org/show_bug.cgi?id=69777

Patch by Sergey Glazunov <[email protected]> on 2011-10-12
Reviewed by Adam Barth.

Source/WebCore: 

Test: http/tests/security/xss-DENIED-synchronous-frame-load-in-_javascript_-url.html

* bindings/ScriptControllerBase.cpp:
(WebCore::ScriptController::executeIfJavaScriptURL):
* loader/DocumentWriter.cpp:
(WebCore::DocumentWriter::replaceDocument):
(WebCore::DocumentWriter::begin):
* loader/DocumentWriter.h:

Source/WebKit/chromium: 

* src/WebFrameImpl.cpp:
(WebKit::WebFrameImpl::loadJavaScriptURL):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (97269 => 97270)


--- trunk/Source/WebCore/ChangeLog	2011-10-12 16:55:24 UTC (rev 97269)
+++ trunk/Source/WebCore/ChangeLog	2011-10-12 17:05:41 UTC (rev 97270)
@@ -1,3 +1,19 @@
+2011-10-12  Sergey Glazunov  <[email protected]>
+
+        ScriptController::executeIfJavaScriptURL gets confused by synchronous frame loads
+        https://bugs.webkit.org/show_bug.cgi?id=69777
+
+        Reviewed by Adam Barth.
+
+        Test: http/tests/security/xss-DENIED-synchronous-frame-load-in-_javascript_-url.html
+
+        * bindings/ScriptControllerBase.cpp:
+        (WebCore::ScriptController::executeIfJavaScriptURL):
+        * loader/DocumentWriter.cpp:
+        (WebCore::DocumentWriter::replaceDocument):
+        (WebCore::DocumentWriter::begin):
+        * loader/DocumentWriter.h:
+
 2011-10-12  Vsevolod Vlasov  <[email protected]>
 
         Web Inspector: Searching in multiple scripts in the scripts tab

Modified: trunk/Source/WebCore/bindings/ScriptControllerBase.cpp (97269 => 97270)


--- trunk/Source/WebCore/bindings/ScriptControllerBase.cpp	2011-10-12 16:55:24 UTC (rev 97269)
+++ trunk/Source/WebCore/bindings/ScriptControllerBase.cpp	2011-10-12 17:05:41 UTC (rev 97270)
@@ -93,6 +93,7 @@
     // We need to hold onto the Frame here because executing script can
     // destroy the frame.
     RefPtr<Frame> protector(m_frame);
+    RefPtr<Document> ownerDocument(m_frame->document());
 
     const int _javascript_SchemeLength = sizeof("_javascript_:") - 1;
 
@@ -125,7 +126,7 @@
         // DocumentWriter::replaceDocument can cause the DocumentLoader to get deref'ed and possible destroyed,
         // so protect it with a RefPtr.
         if (RefPtr<DocumentLoader> loader = m_frame->document()->loader())
-            loader->writer()->replaceDocument(scriptResult);
+            loader->writer()->replaceDocument(scriptResult, ownerDocument.get());
     }
     return true;
 }

Modified: trunk/Source/WebCore/loader/DocumentWriter.cpp (97269 => 97270)


--- trunk/Source/WebCore/loader/DocumentWriter.cpp	2011-10-12 16:55:24 UTC (rev 97269)
+++ trunk/Source/WebCore/loader/DocumentWriter.cpp	2011-10-12 17:05:41 UTC (rev 97270)
@@ -64,10 +64,10 @@
 // This is only called by ScriptController::executeIfJavaScriptURL
 // and always contains the result of evaluating a _javascript_: url.
 // This is the <iframe src="" case.
-void DocumentWriter::replaceDocument(const String& source)
+void DocumentWriter::replaceDocument(const String& source, Document* ownerDocument)
 {
     m_frame->loader()->stopAllLoaders();
-    begin(m_frame->document()->url(), true, InheritSecurityOrigin);
+    begin(m_frame->document()->url(), true, ownerDocument);
 
     if (!source.isNull()) {
         if (!m_hasReceivedSomeData) {
@@ -106,10 +106,8 @@
     return DOMImplementation::createDocument(m_mimeType, m_frame, url, m_frame->inViewSourceMode());
 }
 
-void DocumentWriter::begin(const KURL& urlReference, bool dispatch, SecurityOriginSource originSource)
+void DocumentWriter::begin(const KURL& urlReference, bool dispatch, Document* ownerDocument)
 {
-    RefPtr<Document> oldDocument = m_frame->document();
-
     // We grab a local copy of the URL because it's easy for callers to supply
     // a URL that will be deallocated during the execution of this function.
     // For example, see <https://bugs.webkit.org/show_bug.cgi?id=66360>.
@@ -137,9 +135,9 @@
 
     if (m_decoder)
         document->setDecoder(m_decoder.get());
-    if (originSource == InheritSecurityOrigin) {
-        document->setCookieURL(oldDocument->cookieURL());
-        document->setSecurityOrigin(oldDocument->securityOrigin());
+    if (ownerDocument) {
+        document->setCookieURL(ownerDocument->cookieURL());
+        document->setSecurityOrigin(ownerDocument->securityOrigin());
     }
 
     m_frame->domWindow()->setURL(document->url());

Modified: trunk/Source/WebCore/loader/DocumentWriter.h (97269 => 97270)


--- trunk/Source/WebCore/loader/DocumentWriter.h	2011-10-12 16:55:24 UTC (rev 97269)
+++ trunk/Source/WebCore/loader/DocumentWriter.h	2011-10-12 17:05:41 UTC (rev 97270)
@@ -47,12 +47,10 @@
 
     // This is only called by ScriptController::executeIfJavaScriptURL
     // and always contains the result of evaluating a _javascript_: url.
-    void replaceDocument(const String&);
+    void replaceDocument(const String&, Document* ownerDocument);
 
-    enum SecurityOriginSource { CreateNewSecurityOrigin, InheritSecurityOrigin };
-
     void begin();
-    void begin(const KURL&, bool dispatchWindowObjectAvailable = true, SecurityOriginSource = CreateNewSecurityOrigin);
+    void begin(const KURL&, bool dispatchWindowObjectAvailable = true, Document* ownerDocument = 0);
     void addData(const char* bytes, size_t length);
     void end();
     void endIfNotLoadingMainResource();

Modified: trunk/Source/WebKit/chromium/ChangeLog (97269 => 97270)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-10-12 16:55:24 UTC (rev 97269)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-10-12 17:05:41 UTC (rev 97270)
@@ -1,3 +1,13 @@
+2011-10-12  Sergey Glazunov  <[email protected]>
+
+        ScriptController::executeIfJavaScriptURL gets confused by synchronous frame loads
+        https://bugs.webkit.org/show_bug.cgi?id=69777
+
+        Reviewed by Adam Barth.
+
+        * src/WebFrameImpl.cpp:
+        (WebKit::WebFrameImpl::loadJavaScriptURL):
+
 2011-10-12  Yury Semikhatsky  <[email protected]>
 
         [Chromium] Web Inspector: testPauseWhenLoadingDevTools is broken

Modified: trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp (97269 => 97270)


--- trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp	2011-10-12 16:55:24 UTC (rev 97269)
+++ trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp	2011-10-12 17:05:41 UTC (rev 97270)
@@ -2273,6 +2273,8 @@
     if (!m_frame->document() || !m_frame->page())
         return;
 
+    RefPtr<Document> ownerDocument(m_frame->document());
+
     // Protect privileged pages against bookmarklets and other _javascript_ manipulations.
     if (SchemeRegistry::shouldTreatURLSchemeAsNotAllowingJavascriptURLs(m_frame->document()->url().protocol()))
         return;
@@ -2285,7 +2287,7 @@
         return;
 
     if (!m_frame->navigationScheduler()->locationChangePending())
-        m_frame->document()->loader()->writer()->replaceDocument(scriptResult);
+        m_frame->document()->loader()->writer()->replaceDocument(scriptResult, ownerDocument.get());
 }
 
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to