Title: [95679] trunk/Source/WebKit2
Revision
95679
Author
[email protected]
Date
2011-09-21 16:25:35 -0700 (Wed, 21 Sep 2011)

Log Message

        [WK2] UIProcess should check that WebProcess isn't sending unexpected file: URLs to it
        https://bugs.webkit.org/show_bug.cgi?id=68573

        Reviewed by Anders Carlsson.

        * UIProcess/API/mac/WKView.mm:
        (maybeCreateSandboxExtensionFromPasteboard): Return a boolean, telling the caller whether
        an extension actually needed to be created
        (-[WKView performDragOperation:]): Tell process proxy when the process is going to get
        universal file read sandbox extension.

        * UIProcess/WebContext.cpp:
        (WebKit::WebContext::didPerformClientRedirect): Check the URLs.
        (WebKit::WebContext::didPerformServerRedirect): Ditto.
        (WebKit::WebContext::didUpdateHistoryTitle): Ditto.
        (WebKit::WebContext::getPluginPath): Ditto. Also, properly parse the URL - we can never
        assume that a string coming from WebProcess is a ParsedURLString.

        * UIProcess/WebPageProxy.cpp:
        (WebKit::WebPageProxy::reattachToWebProcessWithItem): Tell process proxy when the process
        is going to get universal file read sandbox extension.
        (WebKit::WebPageProxy::maybeInitializeSandboxExtensionHandle): Changed to return a boolean,
        telling the caller whether an extension actually needed to be created.
        (WebKit::WebPageProxy::loadURL): Tell process proxy about extension.
        (WebKit::WebPageProxy::loadURLRequest): Ditto.
        (WebKit::WebPageProxy::loadHTMLString): Tell process proxy if a file URL was used as a base
        one for a string. In this case, WebKit2 assumes that WebProcess has access to a subdirectory,
        (typically, one where error page resources live), and can load from it.
        (WebKit::WebPageProxy::loadAlternateHTMLString): Ditto.
        (WebKit::WebPageProxy::goForward): Tell process proxy about extension.
        (WebKit::WebPageProxy::goBack): Tell process proxy about extension.
        (WebKit::WebPageProxy::goToBackForwardItem): Tell process proxy about extension.
        (WebKit::WebPageProxy::didStartProvisionalLoadForFrame): Check the URL.
        (WebKit::WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame): Ditto.
        (WebKit::WebPageProxy::didSameDocumentNavigationForFrame): Ditto.
        (WebKit::WebPageProxy::decidePolicyForNavigationAction): Ditto.
        (WebKit::WebPageProxy::decidePolicyForNewWindowAction): Ditto.
        (WebKit::WebPageProxy::decidePolicyForResponse): Ditto.
        (WebKit::WebPageProxy::didInitiateLoadForResource): Ditto.
        (WebKit::WebPageProxy::didSendRequestForResource): Ditto.
        (WebKit::WebPageProxy::didReceiveResponseForResource): Ditto.
        (WebKit::WebPageProxy::missingPluginButtonClicked): Ditto.

        * UIProcess/WebPageProxy.h: Changed initializeSandboxExtensionHandle() to return a bool,
        and renamed to maybeInitializeSandboxExtensionHandle (matching WKView counterpart).

        * UIProcess/WebProcessProxy.cpp:
        (WebKit::WebProcessProxy::WebProcessProxy): Initialize m_mayHaveUniversalFileReadSandboxExtension.
        It's going to be true if we ever granted an extension for "/".
        (WebKit::WebProcessProxy::willLoadHTMLStringWithBaseURL): Remember the path, we should expect
        that WebProcess will load subresources from it.
        (WebKit::WebProcessProxy::checkURLReceivedFromWebProcess): Check that it's reasonable to expect
        WebProcess send us a URL like this.
        (WebKit::WebProcessProxy::addBackForwardItem): Check the URLs.

        * UIProcess/WebProcessProxy.h: Added data members remembering what to expect from this process.

        * UIProcess/cf/WebPageProxyCF.cpp: (WebKit::WebPageProxy::restoreFromSessionStateData):
        Tell process proxy when the process is going to get universal file read sandbox extension.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (95678 => 95679)


--- trunk/Source/WebKit2/ChangeLog	2011-09-21 23:06:42 UTC (rev 95678)
+++ trunk/Source/WebKit2/ChangeLog	2011-09-21 23:25:35 UTC (rev 95679)
@@ -1,3 +1,65 @@
+2011-09-21  Alexey Proskuryakov  <[email protected]>
+
+        [WK2] UIProcess should check that WebProcess isn't sending unexpected file: URLs to it
+        https://bugs.webkit.org/show_bug.cgi?id=68573
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/API/mac/WKView.mm:
+        (maybeCreateSandboxExtensionFromPasteboard): Return a boolean, telling the caller whether
+        an extension actually needed to be created
+        (-[WKView performDragOperation:]): Tell process proxy when the process is going to get
+        universal file read sandbox extension.
+
+        * UIProcess/WebContext.cpp:
+        (WebKit::WebContext::didPerformClientRedirect): Check the URLs.
+        (WebKit::WebContext::didPerformServerRedirect): Ditto.
+        (WebKit::WebContext::didUpdateHistoryTitle): Ditto.
+        (WebKit::WebContext::getPluginPath): Ditto. Also, properly parse the URL - we can never
+        assume that a string coming from WebProcess is a ParsedURLString.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::reattachToWebProcessWithItem): Tell process proxy when the process
+        is going to get universal file read sandbox extension.
+        (WebKit::WebPageProxy::maybeInitializeSandboxExtensionHandle): Changed to return a boolean,
+        telling the caller whether an extension actually needed to be created.
+        (WebKit::WebPageProxy::loadURL): Tell process proxy about extension.
+        (WebKit::WebPageProxy::loadURLRequest): Ditto.
+        (WebKit::WebPageProxy::loadHTMLString): Tell process proxy if a file URL was used as a base
+        one for a string. In this case, WebKit2 assumes that WebProcess has access to a subdirectory,
+        (typically, one where error page resources live), and can load from it.
+        (WebKit::WebPageProxy::loadAlternateHTMLString): Ditto.
+        (WebKit::WebPageProxy::goForward): Tell process proxy about extension.
+        (WebKit::WebPageProxy::goBack): Tell process proxy about extension.
+        (WebKit::WebPageProxy::goToBackForwardItem): Tell process proxy about extension.
+        (WebKit::WebPageProxy::didStartProvisionalLoadForFrame): Check the URL.
+        (WebKit::WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame): Ditto.
+        (WebKit::WebPageProxy::didSameDocumentNavigationForFrame): Ditto.
+        (WebKit::WebPageProxy::decidePolicyForNavigationAction): Ditto.
+        (WebKit::WebPageProxy::decidePolicyForNewWindowAction): Ditto.
+        (WebKit::WebPageProxy::decidePolicyForResponse): Ditto.
+        (WebKit::WebPageProxy::didInitiateLoadForResource): Ditto.
+        (WebKit::WebPageProxy::didSendRequestForResource): Ditto.
+        (WebKit::WebPageProxy::didReceiveResponseForResource): Ditto.
+        (WebKit::WebPageProxy::missingPluginButtonClicked): Ditto.
+
+        * UIProcess/WebPageProxy.h: Changed initializeSandboxExtensionHandle() to return a bool,
+        and renamed to maybeInitializeSandboxExtensionHandle (matching WKView counterpart).
+
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::WebProcessProxy): Initialize m_mayHaveUniversalFileReadSandboxExtension.
+        It's going to be true if we ever granted an extension for "/".
+        (WebKit::WebProcessProxy::willLoadHTMLStringWithBaseURL): Remember the path, we should expect
+        that WebProcess will load subresources from it.
+        (WebKit::WebProcessProxy::checkURLReceivedFromWebProcess): Check that it's reasonable to expect
+        WebProcess send us a URL like this.
+        (WebKit::WebProcessProxy::addBackForwardItem): Check the URLs.
+
+        * UIProcess/WebProcessProxy.h: Added data members remembering what to expect from this process.
+
+        * UIProcess/cf/WebPageProxyCF.cpp: (WebKit::WebPageProxy::restoreFromSessionStateData):
+        Tell process proxy when the process is going to get universal file read sandbox extension.
+
 2011-09-19  Jer Noble  <[email protected]>
 
         Add settings to control the availability of the Web Audio API to WebKit and WebKit2.

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (95678 => 95679)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2011-09-21 23:06:42 UTC (rev 95678)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2011-09-21 23:25:35 UTC (rev 95679)
@@ -1660,25 +1660,26 @@
 
 // FIXME: This code is more or less copied from Pasteboard::getBestURL.
 // It would be nice to be able to share the code somehow.
-static void maybeCreateSandboxExtensionFromPasteboard(NSPasteboard *pasteboard, SandboxExtension::Handle& sandboxExtensionHandle)
+static bool maybeCreateSandboxExtensionFromPasteboard(NSPasteboard *pasteboard, SandboxExtension::Handle& sandboxExtensionHandle)
 {
     NSArray *types = [pasteboard types];
     if (![types containsObject:NSFilenamesPboardType])
-        return;
+        return false;
 
     NSArray *files = [pasteboard propertyListForType:NSFilenamesPboardType];
     if ([files count] != 1)
-        return;
+        return false;
 
     NSString *file = [files objectAtIndex:0];
     BOOL isDirectory;
     if (![[NSFileManager defaultManager] fileExistsAtPath:file isDirectory:&isDirectory])
-        return;
+        return false;
 
     if (isDirectory)
-        return;
+        return false;
 
     SandboxExtension::createHandle("/", SandboxExtension::ReadOnly, sandboxExtensionHandle);
+    return true;
 }
 
 - (BOOL)performDragOperation:(id <NSDraggingInfo>)draggingInfo
@@ -1688,7 +1689,9 @@
     DragData dragData(draggingInfo, client, global, static_cast<DragOperation>([draggingInfo draggingSourceOperationMask]), [self applicationFlags:draggingInfo]);
 
     SandboxExtension::Handle sandboxExtensionHandle;
-    maybeCreateSandboxExtensionFromPasteboard([draggingInfo draggingPasteboard], sandboxExtensionHandle);
+    bool createdExtension = maybeCreateSandboxExtensionFromPasteboard([draggingInfo draggingPasteboard], sandboxExtensionHandle);
+    if (createdExtension)
+        _data->_page->process()->willAcquireUniversalFileReadSandboxExtension();
 
     _data->_page->performDrag(&dragData, [[draggingInfo draggingPasteboard] name], sandboxExtensionHandle);
 

Modified: trunk/Source/WebKit2/UIProcess/WebContext.cpp (95678 => 95679)


--- trunk/Source/WebKit2/UIProcess/WebContext.cpp	2011-09-21 23:06:42 UTC (rev 95678)
+++ trunk/Source/WebKit2/UIProcess/WebContext.cpp	2011-09-21 23:25:35 UTC (rev 95679)
@@ -65,7 +65,8 @@
 #include <wtf/RefCountedLeakCounter.h>
 #endif
 
-#define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, process()->connection())
+#define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, m_process->connection())
+#define MESSAGE_CHECK_URL(url) MESSAGE_CHECK_BASE(m_process->checkURLReceivedFromWebProcess(url), m_process->connection())
 
 using namespace WebCore;
 
@@ -439,7 +440,9 @@
     WebFrameProxy* frame = m_process->webFrame(frameID);
     MESSAGE_CHECK(frame);
     MESSAGE_CHECK(frame->page() == page);
-    
+    MESSAGE_CHECK_URL(sourceURLString);
+    MESSAGE_CHECK_URL(destinationURLString);
+
     m_historyClient.didPerformClientRedirect(this, page, sourceURLString, destinationURLString, frame);
 }
 
@@ -455,7 +458,9 @@
     WebFrameProxy* frame = m_process->webFrame(frameID);
     MESSAGE_CHECK(frame);
     MESSAGE_CHECK(frame->page() == page);
-    
+    MESSAGE_CHECK_URL(sourceURLString);
+    MESSAGE_CHECK_URL(destinationURLString);
+
     m_historyClient.didPerformServerRedirect(this, page, sourceURLString, destinationURLString, frame);
 }
 
@@ -468,6 +473,7 @@
     WebFrameProxy* frame = m_process->webFrame(frameID);
     MESSAGE_CHECK(frame);
     MESSAGE_CHECK(frame->page() == page);
+    MESSAGE_CHECK_URL(url);
 
     m_historyClient.didUpdateHistoryTitle(this, page, title, url, frame);
 }
@@ -553,9 +559,11 @@
 
 void WebContext::getPluginPath(const String& mimeType, const String& urlString, String& pluginPath)
 {
+    MESSAGE_CHECK_URL(urlString);
+
     String newMimeType = mimeType.lower();
 
-    PluginModuleInfo plugin = pluginInfoStore().findPlugin(newMimeType, KURL(ParsedURLString, urlString));
+    PluginModuleInfo plugin = pluginInfoStore().findPlugin(newMimeType, KURL(KURL(), urlString));
     if (!plugin.path)
         return;
 

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (95678 => 95679)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2011-09-21 23:06:42 UTC (rev 95678)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2011-09-21 23:25:35 UTC (rev 95679)
@@ -90,7 +90,8 @@
 // This controls what strategy we use for mouse wheel coalescing.
 #define MERGE_WHEEL_EVENTS 1
 
-#define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, process()->connection())
+#define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, m_process->connection())
+#define MESSAGE_CHECK_URL(url) MESSAGE_CHECK_BASE(m_process->checkURLReceivedFromWebProcess(url), m_process->connection())
 
 using namespace WebCore;
 
@@ -296,7 +297,9 @@
         return;
 
     SandboxExtension::Handle sandboxExtensionHandle;
-    initializeSandboxExtensionHandle(KURL(KURL(), item->url()), sandboxExtensionHandle);
+    bool createdExtension = maybeInitializeSandboxExtensionHandle(KURL(KURL(), item->url()), sandboxExtensionHandle);
+    if (createdExtension)
+        process()->willAcquireUniversalFileReadSandboxExtension();
     process()->send(Messages::WebPage::GoToBackForwardItem(item->itemID(), sandboxExtensionHandle), m_pageID);
     process()->responsivenessTimer()->start();
 }
@@ -396,16 +399,17 @@
     return false;
 }
 
-void WebPageProxy::initializeSandboxExtensionHandle(const KURL& url, SandboxExtension::Handle& sandboxExtensionHandle)
+bool WebPageProxy::maybeInitializeSandboxExtensionHandle(const KURL& url, SandboxExtension::Handle& sandboxExtensionHandle)
 {
     if (!url.isLocalFile())
-        return;
+        return false;
 
     // Don't give the inspector full access to the file system.
     if (WebInspectorProxy::isInspectorPage(this))
-        return;
+        return false;
 
     SandboxExtension::createHandle("/", SandboxExtension::ReadOnly, sandboxExtensionHandle);
+    return true;
 }
 
 void WebPageProxy::loadURL(const String& url)
@@ -416,7 +420,9 @@
         reattachToWebProcess();
 
     SandboxExtension::Handle sandboxExtensionHandle;
-    initializeSandboxExtensionHandle(KURL(KURL(), url), sandboxExtensionHandle);
+    bool createdExtension = maybeInitializeSandboxExtensionHandle(KURL(KURL(), url), sandboxExtensionHandle);
+    if (createdExtension)
+        process()->willAcquireUniversalFileReadSandboxExtension();
     process()->send(Messages::WebPage::LoadURL(url, sandboxExtensionHandle), m_pageID);
     process()->responsivenessTimer()->start();
 }
@@ -429,7 +435,9 @@
         reattachToWebProcess();
 
     SandboxExtension::Handle sandboxExtensionHandle;
-    initializeSandboxExtensionHandle(urlRequest->resourceRequest().url(), sandboxExtensionHandle);
+    bool createdExtension = maybeInitializeSandboxExtensionHandle(urlRequest->resourceRequest().url(), sandboxExtensionHandle);
+    if (createdExtension)
+        process()->willAcquireUniversalFileReadSandboxExtension();
     process()->send(Messages::WebPage::LoadURLRequest(urlRequest->resourceRequest(), sandboxExtensionHandle), m_pageID);
     process()->responsivenessTimer()->start();
 }
@@ -439,6 +447,7 @@
     if (!isValid())
         reattachToWebProcess();
 
+    process()->willLoadHTMLStringWithBaseURL(baseURL);
     process()->send(Messages::WebPage::LoadHTMLString(htmlString, baseURL), m_pageID);
     process()->responsivenessTimer()->start();
 }
@@ -451,6 +460,7 @@
     if (m_mainFrame)
         m_mainFrame->setUnreachableURL(unreachableURL);
 
+    process()->willLoadHTMLStringWithBaseURL(baseURL);
     process()->send(Messages::WebPage::LoadAlternateHTMLString(htmlString, baseURL, unreachableURL), m_pageID);
     process()->responsivenessTimer()->start();
 }
@@ -502,7 +512,9 @@
     }
 
     SandboxExtension::Handle sandboxExtensionHandle;
-    initializeSandboxExtensionHandle(KURL(KURL(), forwardItem->url()), sandboxExtensionHandle);
+    bool createdExtension = maybeInitializeSandboxExtensionHandle(KURL(KURL(), forwardItem->url()), sandboxExtensionHandle);
+    if (createdExtension)
+        process()->willAcquireUniversalFileReadSandboxExtension();
     process()->send(Messages::WebPage::GoForward(forwardItem->itemID(), sandboxExtensionHandle), m_pageID);
     process()->responsivenessTimer()->start();
 }
@@ -527,7 +539,9 @@
     }
 
     SandboxExtension::Handle sandboxExtensionHandle;
-    initializeSandboxExtensionHandle(KURL(KURL(), backItem->url()), sandboxExtensionHandle);
+    bool createdExtension = maybeInitializeSandboxExtensionHandle(KURL(KURL(), backItem->url()), sandboxExtensionHandle);
+    if (createdExtension)
+        process()->willAcquireUniversalFileReadSandboxExtension();
     process()->send(Messages::WebPage::GoBack(backItem->itemID(), sandboxExtensionHandle), m_pageID);
     process()->responsivenessTimer()->start();
 }
@@ -547,7 +561,9 @@
     setPendingAPIRequestURL(item->url());
 
     SandboxExtension::Handle sandboxExtensionHandle;
-    initializeSandboxExtensionHandle(KURL(KURL(), item->url()), sandboxExtensionHandle);
+    bool createdExtension = maybeInitializeSandboxExtensionHandle(KURL(KURL(), item->url()), sandboxExtensionHandle);
+    if (createdExtension)
+        process()->willAcquireUniversalFileReadSandboxExtension();
     process()->send(Messages::WebPage::GoToBackForwardItem(item->itemID(), sandboxExtensionHandle), m_pageID);
     process()->responsivenessTimer()->start();
 }
@@ -1524,6 +1540,7 @@
 
     WebFrameProxy* frame = process()->webFrame(frameID);
     MESSAGE_CHECK(frame);
+    MESSAGE_CHECK_URL(url);
 
     frame->setUnreachableURL(unreachableURL);
 
@@ -1540,6 +1557,7 @@
 
     WebFrameProxy* frame = process()->webFrame(frameID);
     MESSAGE_CHECK(frame);
+    MESSAGE_CHECK_URL(url);
 
     frame->didReceiveServerRedirectForProvisionalLoad(url);
 
@@ -1661,6 +1679,7 @@
 
     WebFrameProxy* frame = process()->webFrame(frameID);
     MESSAGE_CHECK(frame);
+    MESSAGE_CHECK_URL(url);
 
     clearPendingAPIRequestURL();
     frame->didSameDocumentNavigation(url);
@@ -1773,6 +1792,7 @@
 
     WebFrameProxy* frame = process()->webFrame(frameID);
     MESSAGE_CHECK(frame);
+    MESSAGE_CHECK_URL(request.url());
 
     NavigationType navigationType = static_cast<NavigationType>(opaqueNavigationType);
     WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
@@ -1807,6 +1827,7 @@
 
     WebFrameProxy* frame = process()->webFrame(frameID);
     MESSAGE_CHECK(frame);
+    MESSAGE_CHECK_URL(request.url());
 
     NavigationType navigationType = static_cast<NavigationType>(opaqueNavigationType);
     WebEvent::Modifiers modifiers = static_cast<WebEvent::Modifiers>(opaqueModifiers);
@@ -1826,7 +1847,9 @@
 
     WebFrameProxy* frame = process()->webFrame(frameID);
     MESSAGE_CHECK(frame);
-
+    MESSAGE_CHECK_URL(request.url());
+    MESSAGE_CHECK_URL(response.url());
+    
     RefPtr<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID);
 
     ASSERT(!m_inDecidePolicyForMIMEType);
@@ -1886,6 +1909,7 @@
 {
     WebFrameProxy* frame = process()->webFrame(frameID);
     MESSAGE_CHECK(frame);
+    MESSAGE_CHECK_URL(request.url());
 
     m_resourceLoadClient.didInitiateLoadForResource(this, frame, resourceIdentifier, request, pageIsProvisionallyLoading);
 }
@@ -1894,6 +1918,7 @@
 {
     WebFrameProxy* frame = process()->webFrame(frameID);
     MESSAGE_CHECK(frame);
+    MESSAGE_CHECK_URL(request.url());
 
     m_resourceLoadClient.didSendRequestForResource(this, frame, resourceIdentifier, request, redirectResponse);
 }
@@ -1902,6 +1927,7 @@
 {
     WebFrameProxy* frame = process()->webFrame(frameID);
     MESSAGE_CHECK(frame);
+    MESSAGE_CHECK_URL(response.url());
 
     m_resourceLoadClient.didReceiveResponseForResource(this, frame, resourceIdentifier, response);
 }
@@ -2016,6 +2042,9 @@
 
 void WebPageProxy::missingPluginButtonClicked(const String& mimeType, const String& url, const String& pluginsPageURL)
 {
+    MESSAGE_CHECK_URL(url);
+    MESSAGE_CHECK_URL(pluginsPageURL);
+
     m_uiClient.missingPluginButtonClicked(this, mimeType, url, pluginsPageURL);
 }
 

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (95678 => 95679)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2011-09-21 23:06:42 UTC (rev 95678)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2011-09-21 23:25:35 UTC (rev 95679)
@@ -774,7 +774,7 @@
     void clearPendingAPIRequestURL() { m_pendingAPIRequestURL = String(); }
     void setPendingAPIRequestURL(const String& pendingAPIRequestURL) { m_pendingAPIRequestURL = pendingAPIRequestURL; }
 
-    void initializeSandboxExtensionHandle(const WebCore::KURL&, SandboxExtension::Handle&);
+    bool maybeInitializeSandboxExtensionHandle(const WebCore::KURL&, SandboxExtension::Handle&);
 
 #if PLATFORM(MAC)
     void substitutionsPanelIsShowing(bool&);

Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp (95678 => 95679)


--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp	2011-09-21 23:06:42 UTC (rev 95678)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp	2011-09-21 23:25:35 UTC (rev 95679)
@@ -45,6 +45,8 @@
 using namespace WebCore;
 using namespace std;
 
+#define MESSAGE_CHECK_URL(url) MESSAGE_CHECK_BASE(checkURLReceivedFromWebProcess(url), connection())
+
 namespace WebKit {
 
 template<typename HashMap>
@@ -67,6 +69,7 @@
 WebProcessProxy::WebProcessProxy(PassRefPtr<WebContext> context)
     : m_responsivenessTimer(this)
     , m_context(context)
+    , m_mayHaveUniversalFileReadSandboxExtension(false)
 {
     connect();
 }
@@ -200,8 +203,56 @@
     m_backForwardListItemMap.set(item->itemID(), item);
 }
 
+void WebProcessProxy::willLoadHTMLStringWithBaseURL(const String& urlString)
+{
+    KURL url(KURL(), urlString);
+    if (!url.isLocalFile())
+        return;
+
+    // Client loads an alternate string. This doesn't grant universal file read, but the web process is assumed
+    // to have read access to this directory already.
+    m_localPathsWithAssumedReadAccess.add(url.fileSystemPath());
+}
+
+bool WebProcessProxy::checkURLReceivedFromWebProcess(const String& urlString)
+{
+    return checkURLReceivedFromWebProcess(KURL(KURL(), urlString));
+}
+
+bool WebProcessProxy::checkURLReceivedFromWebProcess(const KURL& url)
+{
+    if (url.isNull())
+        return true;
+
+    // Web process should not be sending us invalid URLs.
+    if (!url.isValid())
+        return false;
+
+    // Any other non-file URL is OK.
+    if (!url.isLocalFile())
+        return true;
+
+    // Any file URL is also OK if we've loaded a file URL through API before, granting universal read access.
+    if (m_mayHaveUniversalFileReadSandboxExtension)
+        return true;
+
+    // If we loaded a string with a file base URL before, loading resources from that subdirectory is fine.
+    // There are no ".." components, because all URLs received from WebProcess are parsed with KURL, which removes those.
+    String path = url.fileSystemPath();
+    for (HashSet<String>::const_iterator iter = m_localPathsWithAssumedReadAccess.begin(); iter != m_localPathsWithAssumedReadAccess.end(); ++iter) {
+        if (path.startsWith(*iter))
+            return true;
+    }
+
+    // A Web process that was never asked to load a file URL should not ever ask us to do anything with a file URL.
+    return false;
+}
+
 void WebProcessProxy::addBackForwardItem(uint64_t itemID, const String& originalURL, const String& url, const String& title, const CoreIPC::DataReference& backForwardData)
 {
+    MESSAGE_CHECK_URL(originalURL);
+    MESSAGE_CHECK_URL(url);
+
     std::pair<WebBackForwardListItemMap::iterator, bool> result = m_backForwardListItemMap.add(itemID, 0);
     if (result.second) {
         // New item.

Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.h (95678 => 95679)


--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.h	2011-09-21 23:06:42 UTC (rev 95678)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.h	2011-09-21 23:25:35 UTC (rev 95679)
@@ -104,6 +104,12 @@
 
     void registerNewWebBackForwardListItem(WebBackForwardListItem*);
 
+    void willAcquireUniversalFileReadSandboxExtension() { m_mayHaveUniversalFileReadSandboxExtension = true; }
+    void willLoadHTMLStringWithBaseURL(const String&);
+
+    bool checkURLReceivedFromWebProcess(const String&);
+    bool checkURLReceivedFromWebProcess(const WebCore::KURL&);
+
     // FIXME: This variant of send is deprecated. All clients should move to an overload that take a message type.
     template<typename E, typename T> bool deprecatedSend(E messageID, uint64_t destinationID, const T& arguments);
 
@@ -175,6 +181,9 @@
 
     RefPtr<WebContext> m_context;
 
+    bool m_mayHaveUniversalFileReadSandboxExtension; // True if a read extension for "/" was ever granted - we don't track whether WebProcess still has it.
+    HashSet<String> m_localPathsWithAssumedReadAccess;
+
     HashMap<uint64_t, WebPageProxy*> m_pageMap;
     WebFrameProxyMap m_frameMap;
     WebBackForwardListItemMap m_backForwardListItemMap;

Modified: trunk/Source/WebKit2/UIProcess/cf/WebPageProxyCF.cpp (95678 => 95679)


--- trunk/Source/WebKit2/UIProcess/cf/WebPageProxyCF.cpp	2011-09-21 23:06:42 UTC (rev 95678)
+++ trunk/Source/WebKit2/UIProcess/cf/WebPageProxyCF.cpp	2011-09-21 23:25:35 UTC (rev 95679)
@@ -166,7 +166,9 @@
                 else {
                     SandboxExtension::Handle sandboxExtensionHandle;
                     if (WebBackForwardListItem* item = m_backForwardList->currentItem()) {
-                        initializeSandboxExtensionHandle(KURL(KURL(), item->url()), sandboxExtensionHandle);
+                        bool createdExtension = maybeInitializeSandboxExtensionHandle(KURL(KURL(), item->url()), sandboxExtensionHandle);
+                        if (createdExtension)
+                            process()->willAcquireUniversalFileReadSandboxExtension();
                         setPendingAPIRequestURL(item->url());
                     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to