Title: [140843] trunk/Source/WebKit2
Revision
140843
Author
a...@apple.com
Date
2013-01-25 10:07:02 -0800 (Fri, 25 Jan 2013)

Log Message

        Send sandbox extensions for local files to NetworkProcess
        https://bugs.webkit.org/show_bug.cgi?id=107872

        Reviewed by Brady Eidson.

        Send sandbox extensions in NetworkResourceLoadParameters, and consume/invalidate
        them during loading. Changed NetworkProcess code to only use that class for IPC,
        not for actual implementation.

        * NetworkProcess/HostRecord.cpp:
        (WebKit::HostRecord::scheduleResourceLoader):
        * NetworkProcess/NetworkResourceLoadScheduler.cpp:
        (WebKit::NetworkResourceLoadScheduler::scheduleLoader):
        (WebKit::NetworkResourceLoadScheduler::removeLoader):
        (WebKit::NetworkResourceLoadScheduler::receivedRedirect):
        * NetworkProcess/NetworkResourceLoader.cpp:
        (WebKit::NetworkResourceLoader::destinationID):
        (WebKit::NetworkResourceLoader::start):
        (WebKit::NetworkResourceLoader::resourceHandleStopped):
        (WebKit::NetworkResourceLoader::didReceiveResponse):
        (WebKit::NetworkResourceLoader::didFinishLoading):
        (WebKit::NetworkResourceLoader::didFail):
        (WebKit::NetworkResourceLoader::shouldUseCredentialStorage):
        * NetworkProcess/SchedulableLoader.cpp:
        (WebKit::SchedulableLoader::SchedulableLoader):
        (WebKit::SchedulableLoader::consumeSandboxExtensions):
        (WebKit::SchedulableLoader::invalidateSandboxExtensions):
        * NetworkProcess/SchedulableLoader.h:
        (WebKit::SchedulableLoader::identifier):
        (WebKit::SchedulableLoader::request):
        (WebKit::SchedulableLoader::priority):
        (WebKit::SchedulableLoader::contentSniffingPolicy):
        (WebKit::SchedulableLoader::allowStoredCredentials):
        (WebKit::SchedulableLoader::inPrivateBrowsingMode):
        (SchedulableLoader):
        * NetworkProcess/SyncNetworkResourceLoader.cpp:
        (WebKit::SyncNetworkResourceLoader::start):
        * Shared/Network/NetworkResourceLoadParameters.cpp:
        (WebKit::NetworkResourceLoadParameters::encode):
        (WebKit::NetworkResourceLoadParameters::decode):
        * Shared/Network/NetworkResourceLoadParameters.h:
        (WebKit::NetworkResourceLoadParameters::requestBodyExtensions):
        (WebKit::NetworkResourceLoadParameters::resourceSandboxExtension):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (140842 => 140843)


--- trunk/Source/WebKit2/ChangeLog	2013-01-25 18:04:37 UTC (rev 140842)
+++ trunk/Source/WebKit2/ChangeLog	2013-01-25 18:07:02 UTC (rev 140843)
@@ -1,3 +1,49 @@
+2013-01-25  Alexey Proskuryakov  <a...@apple.com>
+
+        Send sandbox extensions for local files to NetworkProcess
+        https://bugs.webkit.org/show_bug.cgi?id=107872
+
+        Reviewed by Brady Eidson.
+
+        Send sandbox extensions in NetworkResourceLoadParameters, and consume/invalidate
+        them during loading. Changed NetworkProcess code to only use that class for IPC,
+        not for actual implementation.
+
+        * NetworkProcess/HostRecord.cpp:
+        (WebKit::HostRecord::scheduleResourceLoader):
+        * NetworkProcess/NetworkResourceLoadScheduler.cpp:
+        (WebKit::NetworkResourceLoadScheduler::scheduleLoader):
+        (WebKit::NetworkResourceLoadScheduler::removeLoader):
+        (WebKit::NetworkResourceLoadScheduler::receivedRedirect):
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::destinationID):
+        (WebKit::NetworkResourceLoader::start):
+        (WebKit::NetworkResourceLoader::resourceHandleStopped):
+        (WebKit::NetworkResourceLoader::didReceiveResponse):
+        (WebKit::NetworkResourceLoader::didFinishLoading):
+        (WebKit::NetworkResourceLoader::didFail):
+        (WebKit::NetworkResourceLoader::shouldUseCredentialStorage):
+        * NetworkProcess/SchedulableLoader.cpp:
+        (WebKit::SchedulableLoader::SchedulableLoader):
+        (WebKit::SchedulableLoader::consumeSandboxExtensions):
+        (WebKit::SchedulableLoader::invalidateSandboxExtensions):
+        * NetworkProcess/SchedulableLoader.h:
+        (WebKit::SchedulableLoader::identifier):
+        (WebKit::SchedulableLoader::request):
+        (WebKit::SchedulableLoader::priority):
+        (WebKit::SchedulableLoader::contentSniffingPolicy):
+        (WebKit::SchedulableLoader::allowStoredCredentials):
+        (WebKit::SchedulableLoader::inPrivateBrowsingMode):
+        (SchedulableLoader):
+        * NetworkProcess/SyncNetworkResourceLoader.cpp:
+        (WebKit::SyncNetworkResourceLoader::start):
+        * Shared/Network/NetworkResourceLoadParameters.cpp:
+        (WebKit::NetworkResourceLoadParameters::encode):
+        (WebKit::NetworkResourceLoadParameters::decode):
+        * Shared/Network/NetworkResourceLoadParameters.h:
+        (WebKit::NetworkResourceLoadParameters::requestBodyExtensions):
+        (WebKit::NetworkResourceLoadParameters::resourceSandboxExtension):
+
 2013-01-25  Claudio Saavedra  <csaave...@igalia.com>
 
         Remove stale class include

Modified: trunk/Source/WebKit2/NetworkProcess/HostRecord.cpp (140842 => 140843)


--- trunk/Source/WebKit2/NetworkProcess/HostRecord.cpp	2013-01-25 18:04:37 UTC (rev 140842)
+++ trunk/Source/WebKit2/NetworkProcess/HostRecord.cpp	2013-01-25 18:07:02 UTC (rev 140843)
@@ -65,7 +65,7 @@
     if (loader->isSynchronous())
         m_syncLoadersPending.append(loader);
     else
-        m_loadersPending[loader->loadParameters().priority()].append(loader);
+        m_loadersPending[loader->priority()].append(loader);
 }
 
 void HostRecord::addLoaderInProgress(SchedulableLoader* loader)

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.cpp (140842 => 140843)


--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.cpp	2013-01-25 18:04:37 UTC (rev 140842)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.cpp	2013-01-25 18:07:02 UTC (rev 140843)
@@ -41,8 +41,8 @@
 
 void NetworkResourceLoadScheduler::scheduleLoader(PassRefPtr<SchedulableLoader> loader)
 {
-    ResourceLoadPriority priority = loader->loadParameters().priority();
-    const ResourceRequest& resourceRequest = loader->loadParameters().request();
+    ResourceLoadPriority priority = loader->priority();
+    const ResourceRequest& resourceRequest = loader->request();
         
     LOG(NetworkScheduling, "(NetworkProcess) NetworkResourceLoadScheduler::scheduleLoader resource '%s'", resourceRequest.url().string().utf8().data());
 
@@ -82,7 +82,7 @@
     ASSERT(isMainThread());
     ASSERT(loader);
 
-    LOG(NetworkScheduling, "(NetworkProcess) NetworkResourceLoadScheduler::removeLoadIdentifier removing loader %s", loader->loadParameters().request().url().string().utf8().data());
+    LOG(NetworkScheduling, "(NetworkProcess) NetworkResourceLoadScheduler::removeLoadIdentifier removing loader %s", loader->request().url().string().utf8().data());
 
     HostRecord* host = loader->hostRecord();
     
@@ -98,7 +98,7 @@
 void NetworkResourceLoadScheduler::receivedRedirect(SchedulableLoader* loader, const WebCore::KURL& redirectURL)
 {
     ASSERT(isMainThread());
-    LOG(NetworkScheduling, "(NetworkProcess) NetworkResourceLoadScheduler::receivedRedirect loader originally for '%s' redirected to '%s'", loader->loadParameters().request().url().string().utf8().data(), redirectURL.string().utf8().data());
+    LOG(NetworkScheduling, "(NetworkProcess) NetworkResourceLoadScheduler::receivedRedirect loader originally for '%s' redirected to '%s'", loader->request().url().string().utf8().data(), redirectURL.string().utf8().data());
 
     HostRecord* oldHost = loader->hostRecord();
 

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp (140842 => 140843)


--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp	2013-01-25 18:04:37 UTC (rev 140842)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp	2013-01-25 18:07:02 UTC (rev 140843)
@@ -66,7 +66,7 @@
 
 uint64_t NetworkResourceLoader::destinationID() const
 {
-    return loadParameters().identifier();
+    return identifier();
 }
 
 void NetworkResourceLoader::start()
@@ -77,10 +77,12 @@
     ref();
     
     // FIXME (NetworkProcess): Create RemoteNetworkingContext with actual settings.
-    m_networkingContext = RemoteNetworkingContext::create(false, false, loadParameters().inPrivateBrowsingMode());
+    m_networkingContext = RemoteNetworkingContext::create(false, false, inPrivateBrowsingMode());
 
+    consumeSandboxExtensions();
+
     // FIXME (NetworkProcess): Pass an actual value for defersLoading
-    m_handle = ResourceHandle::create(m_networkingContext.get(), loadParameters().request(), this, false /* defersLoading */, loadParameters().contentSniffingPolicy() == SniffContent);
+    m_handle = ResourceHandle::create(m_networkingContext.get(), request(), this, false /* defersLoading */, contentSniffingPolicy() == SniffContent);
 }
 
 static bool stopRequestsCalled = false;
@@ -128,7 +130,7 @@
 {
     ASSERT(isMainThread());
 
-    if (FormData* formData = loadParameters().request().httpBody())
+    if (FormData* formData = request().httpBody())
         formData->removeGeneratedFilesIfNeeded();
 
     m_handle = 0;
@@ -144,7 +146,7 @@
 void NetworkResourceLoader::didReceiveResponse(ResourceHandle*, const ResourceResponse& response)
 {
     // FIXME (NetworkProcess): Cache the response.
-    if (FormData* formData = loadParameters().request().httpBody())
+    if (FormData* formData = request().httpBody())
         formData->removeGeneratedFilesIfNeeded();
     send(Messages::WebResourceLoader::DidReceiveResponseWithCertificateInfo(response, PlatformCertificateInfo(response)));
 }
@@ -162,6 +164,7 @@
 {
     // FIXME (NetworkProcess): For the memory cache we'll need to update the finished status of the cached resource here.
     // Such bookkeeping will need to be thread safe, as this callback is happening on a background thread.
+    invalidateSandboxExtensions();
     send(Messages::WebResourceLoader::DidFinishResourceLoad(finishTime));
     scheduleStopOnMainThread();
 }
@@ -170,6 +173,7 @@
 {
     // FIXME (NetworkProcess): For the memory cache we'll need to update the finished status of the cached resource here.
     // Such bookkeeping will need to be thread safe, as this callback is happening on a background thread.
+    invalidateSandboxExtensions();
     send(Messages::WebResourceLoader::DidFailResourceLoad(error));
     scheduleStopOnMainThread();
 }
@@ -218,7 +222,7 @@
     // When the WebProcess is handling loading a client is consulted each time this shouldUseCredentialStorage question is asked.
     // In NetworkProcess mode we ask the WebProcess client up front once and then reuse the cached answer.
 
-    return loadParameters().allowStoredCredentials() == AllowStoredCredentials;
+    return allowStoredCredentials() == AllowStoredCredentials;
 }
 
 void NetworkResourceLoader::didReceiveAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge& challenge)

Modified: trunk/Source/WebKit2/NetworkProcess/SchedulableLoader.cpp (140842 => 140843)


--- trunk/Source/WebKit2/NetworkProcess/SchedulableLoader.cpp	2013-01-25 18:04:37 UTC (rev 140842)
+++ trunk/Source/WebKit2/NetworkProcess/SchedulableLoader.cpp	2013-01-25 18:07:02 UTC (rev 140843)
@@ -31,9 +31,19 @@
 namespace WebKit {
 
 SchedulableLoader::SchedulableLoader(const NetworkResourceLoadParameters& parameters, NetworkConnectionToWebProcess* connection)
-    : m_networkResourceLoadParameters(parameters)
+    : m_identifier(parameters.identifier())
+    , m_request(parameters.request())
+    , m_priority(parameters.priority())
+    , m_contentSniffingPolicy(parameters.contentSniffingPolicy())
+    , m_allowStoredCredentials(parameters.allowStoredCredentials())
+    , m_inPrivateBrowsingMode(parameters.inPrivateBrowsingMode())
     , m_connection(connection)
 {
+    for (size_t i = 0, count = parameters.requestBodySandboxExtensions().size(); i < count; ++i) {
+        if (RefPtr<SandboxExtension> extension = SandboxExtension::create(parameters.requestBodySandboxExtensions()[i]))
+            m_requestBodySandboxExtensions.append(extension);
+    }
+    m_resourceSandboxExtension = SandboxExtension::create(parameters.resourceSandboxExtension());
 }
 
 SchedulableLoader::~SchedulableLoader()
@@ -48,6 +58,24 @@
     // FIXME (NetworkProcess): Cancel the load. The request may be long-living, so we don't want it to linger around after all clients are gone.
 }
 
+void SchedulableLoader::consumeSandboxExtensions()
+{
+    for (size_t i = 0, count = m_requestBodySandboxExtensions.size(); i < count; ++i)
+        m_requestBodySandboxExtensions[i]->consume();
+
+    if (m_resourceSandboxExtension)
+        m_resourceSandboxExtension->consume();
+}
+
+void SchedulableLoader::invalidateSandboxExtensions()
+{
+    for (size_t i = 0, count = m_requestBodySandboxExtensions.size(); i < count; ++i)
+        m_requestBodySandboxExtensions[i]->invalidate();
+
+    if (m_resourceSandboxExtension)
+        m_resourceSandboxExtension->invalidate();
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(NETWORK_PROCESS)

Modified: trunk/Source/WebKit2/NetworkProcess/SchedulableLoader.h (140842 => 140843)


--- trunk/Source/WebKit2/NetworkProcess/SchedulableLoader.h	2013-01-25 18:04:37 UTC (rev 140842)
+++ trunk/Source/WebKit2/NetworkProcess/SchedulableLoader.h	2013-01-25 18:07:02 UTC (rev 140843)
@@ -40,7 +40,12 @@
 public:
     virtual ~SchedulableLoader();
 
-    const NetworkResourceLoadParameters& loadParameters() const { return m_networkResourceLoadParameters; }
+    ResourceLoadIdentifier identifier() const { return m_identifier; }
+    const WebCore::ResourceRequest& request() const { return m_request; }
+    WebCore::ResourceLoadPriority priority() const { return m_priority; }
+    WebCore::ContentSniffingPolicy contentSniffingPolicy() const { return m_contentSniffingPolicy; }
+    WebCore::StoredCredentials allowStoredCredentials() const { return m_allowStoredCredentials; }
+    bool inPrivateBrowsingMode() const { return m_inPrivateBrowsingMode; }
 
     NetworkConnectionToWebProcess* connectionToWebProcess() const { return m_connection.get(); }
     void connectionToWebProcessDidClose();
@@ -55,8 +60,20 @@
 protected:
     SchedulableLoader(const NetworkResourceLoadParameters&, NetworkConnectionToWebProcess*);
 
+    void consumeSandboxExtensions();
+    void invalidateSandboxExtensions();
+
 private:
-    NetworkResourceLoadParameters m_networkResourceLoadParameters;
+    ResourceLoadIdentifier m_identifier;
+    WebCore::ResourceRequest m_request;
+    WebCore::ResourceLoadPriority m_priority;
+    WebCore::ContentSniffingPolicy m_contentSniffingPolicy;
+    WebCore::StoredCredentials m_allowStoredCredentials;
+    bool m_inPrivateBrowsingMode;
+
+    Vector<RefPtr<SandboxExtension> > m_requestBodySandboxExtensions;
+    RefPtr<SandboxExtension> m_resourceSandboxExtension;
+
     RefPtr<NetworkConnectionToWebProcess> m_connection;
     
     RefPtr<HostRecord> m_hostRecord;

Modified: trunk/Source/WebKit2/NetworkProcess/SyncNetworkResourceLoader.cpp (140842 => 140843)


--- trunk/Source/WebKit2/NetworkProcess/SyncNetworkResourceLoader.cpp	2013-01-25 18:04:37 UTC (rev 140842)
+++ trunk/Source/WebKit2/NetworkProcess/SyncNetworkResourceLoader.cpp	2013-01-25 18:07:02 UTC (rev 140843)
@@ -58,13 +58,15 @@
     ResourceResponse response;
     Vector<char> data;
     
-    const NetworkResourceLoadParameters& parameters = loadParameters();
-
     // FIXME (NetworkProcess): Create RemoteNetworkingContext with actual settings.
-    RefPtr<RemoteNetworkingContext> networkingContext = RemoteNetworkingContext::create(false, false, parameters.inPrivateBrowsingMode());
-    
-    ResourceHandle::loadResourceSynchronously(networkingContext.get(), parameters.request(), parameters.allowStoredCredentials(), error, response, data);
+    RefPtr<RemoteNetworkingContext> networkingContext = RemoteNetworkingContext::create(false, false, inPrivateBrowsingMode());
 
+    consumeSandboxExtensions();
+
+    ResourceHandle::loadResourceSynchronously(networkingContext.get(), request(), allowStoredCredentials(), error, response, data);
+
+    invalidateSandboxExtensions();
+
     m_delayedReply->send(error, response, CoreIPC::DataReference((uint8_t*)data.data(), data.size()));
     
     NetworkProcess::shared().networkResourceLoadScheduler().removeLoader(this);

Modified: trunk/Source/WebKit2/Shared/Network/NetworkResourceLoadParameters.cpp (140842 => 140843)


--- trunk/Source/WebKit2/Shared/Network/NetworkResourceLoadParameters.cpp	2013-01-25 18:04:37 UTC (rev 140842)
+++ trunk/Source/WebKit2/Shared/Network/NetworkResourceLoadParameters.cpp	2013-01-25 18:07:02 UTC (rev 140843)
@@ -65,8 +65,33 @@
         EncoderAdapter httpBodyEncoderAdapter;
         m_request.httpBody()->encode(httpBodyEncoderAdapter);
         encoder.encode(httpBodyEncoderAdapter.dataReference());
+
+        const Vector<FormDataElement>& elements = m_request.httpBody()->elements();
+        size_t fileCount = 0;
+        for (size_t i = 0, count = elements.size(); i < count; ++i) {
+            if (elements[i].m_type == FormDataElement::encodedFile)
+                ++fileCount;
+        }
+
+        SandboxExtension::HandleArray requestBodySandboxExtensions;
+        requestBodySandboxExtensions.allocate(fileCount);
+        size_t extensionIndex = 0;
+        for (size_t i = 0, count = elements.size(); i < count; ++i) {
+            const FormDataElement& element = elements[i];
+            if (element.m_type == FormDataElement::encodedFile) {
+                const String& path = element.m_shouldGenerateFile ? element.m_generatedFilename : element.m_filename;
+                SandboxExtension::createHandle(path, SandboxExtension::ReadOnly, requestBodySandboxExtensions[extensionIndex++]);
+            }
+        }
+        encoder.encode(requestBodySandboxExtensions);
     }
 
+    if (m_request.url().isLocalFile()) {
+        SandboxExtension::Handle requestSandboxExtension;
+        SandboxExtension::createHandle(m_request.url().path(), SandboxExtension::ReadOnly, requestSandboxExtension);
+        encoder.encode(requestSandboxExtension);
+    }
+
     encoder.encodeEnum(m_priority);
     encoder.encodeEnum(m_contentSniffingPolicy);
     encoder.encodeEnum(m_allowStoredCredentials);
@@ -91,8 +116,16 @@
             return false;
         DecoderAdapter httpBodyDecoderAdapter(formData.data(), formData.size());
         result.m_request.setHTTPBody(FormData::decode(httpBodyDecoderAdapter));
+
+        if (!decoder->decode(result.m_requestBodySandboxExtensions))
+            return false;
     }
 
+    if (result.m_request.url().isLocalFile()) {
+        if (!decoder->decode(result.m_resourceSandboxExtension))
+            return false;
+    }
+
     if (!decoder->decodeEnum(result.m_priority))
         return false;
     if (!decoder->decodeEnum(result.m_contentSniffingPolicy))

Modified: trunk/Source/WebKit2/Shared/Network/NetworkResourceLoadParameters.h (140842 => 140843)


--- trunk/Source/WebKit2/Shared/Network/NetworkResourceLoadParameters.h	2013-01-25 18:04:37 UTC (rev 140842)
+++ trunk/Source/WebKit2/Shared/Network/NetworkResourceLoadParameters.h	2013-01-25 18:07:02 UTC (rev 140843)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,6 +26,7 @@
 #ifndef NetworkResourceLoadParameters_h
 #define NetworkResourceLoadParameters_h
 
+#include "SandboxExtension.h"
 #include <WebCore/ResourceHandle.h>
 #include <WebCore/ResourceLoaderOptions.h>
 #include <WebCore/ResourceRequest.h>
@@ -51,6 +52,8 @@
 
     ResourceLoadIdentifier identifier() const { return m_identifier; }
     const WebCore::ResourceRequest& request() const { return m_request; }
+    const SandboxExtension::HandleArray& requestBodySandboxExtensions() const { return m_requestBodySandboxExtensions; }
+    const SandboxExtension::Handle& resourceSandboxExtension() const { return m_resourceSandboxExtension; }
     WebCore::ResourceLoadPriority priority() const { return m_priority; }
     WebCore::ContentSniffingPolicy contentSniffingPolicy() const { return m_contentSniffingPolicy; }
     WebCore::StoredCredentials allowStoredCredentials() const { return m_allowStoredCredentials; }
@@ -59,6 +62,8 @@
 private:
     ResourceLoadIdentifier m_identifier;
     WebCore::ResourceRequest m_request;
+    SandboxExtension::HandleArray m_requestBodySandboxExtensions; // Created automatically for the sender.
+    SandboxExtension::Handle m_resourceSandboxExtension; // Created automatically for the sender.
     WebCore::ResourceLoadPriority m_priority;
     WebCore::ContentSniffingPolicy m_contentSniffingPolicy;
     WebCore::StoredCredentials m_allowStoredCredentials;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to