Changeset 170733 in webkit


Ignore:
Timestamp:
Jul 2, 2014 3:54:32 PM (10 years ago)
Author:
oliver@apple.com
Message:

Restrict network process sandbox
https://bugs.webkit.org/show_bug.cgi?id=134360

Reviewed by Sam Weinig.

Add more restrictions to the network process sandbox.

  • NetworkProcess/cocoa/NetworkProcessCocoa.mm: (WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):

Always use the cache directory provided in the initialization parameters,
and make sure we consume the cookie directory extension.

  • Resources/SandboxProfiles/ios/com.apple.WebKit.Networking.sb:

Make the sandbox profile much more restrictive.

  • Shared/Network/NetworkProcessCreationParameters.cpp: (WebKit::NetworkProcessCreationParameters::encode): (WebKit::NetworkProcessCreationParameters::decode):
  • Shared/Network/NetworkProcessCreationParameters.h:

The network process now requires an extension to access
its cookie storage.

  • Shared/mac/SandboxUtilities.cpp: (WebKit::pathForProcessContainer):
  • Shared/mac/SandboxUtilities.h:

We need to be able to get hold of our container so
that we can get the correct cookie storage directory.

  • UIProcess/WebContext.cpp: (WebKit::WebContext::ensureNetworkProcess):

We have to pass in the an extension for the cookie storage directory when

initalising the network process

  • UIProcess/mac/WebContextMac.mm: (WebKit::WebContext::platformDefaultCookieStorageDirectory):

Make sure we provide the correct location on IOS

  • WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::platformInitializeWebProcess):

Consume the cookie storage extension

Location:
trunk/Source/WebKit2
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r170732 r170733  
     12014-06-28  Oliver Hunt  <oliver@apple.com>
     2
     3       Restrict network process sandbox
     4       https://bugs.webkit.org/show_bug.cgi?id=134360
     5
     6       Reviewed by Sam Weinig.
     7
     8       Add more restrictions to the network process sandbox.
     9
     10       * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
     11       (WebKit::NetworkProcess::platformInitializeNetworkProcessCocoa):
     12         Always use the cache directory provided in the initialization parameters,
     13         and make sure we consume the cookie directory extension.
     14       * Resources/SandboxProfiles/ios/com.apple.WebKit.Networking.sb:
     15         Make the sandbox profile much more restrictive.
     16       * Shared/Network/NetworkProcessCreationParameters.cpp:
     17       (WebKit::NetworkProcessCreationParameters::encode):
     18       (WebKit::NetworkProcessCreationParameters::decode):
     19       * Shared/Network/NetworkProcessCreationParameters.h:
     20         The network process now requires an extension to access
     21         its cookie storage.
     22       * Shared/mac/SandboxUtilities.cpp:
     23       (WebKit::pathForProcessContainer):
     24       * Shared/mac/SandboxUtilities.h:
     25         We need to be able to get hold of our container so
     26         that we can get the correct cookie storage directory.
     27       * UIProcess/WebContext.cpp:
     28       (WebKit::WebContext::ensureNetworkProcess):
     29         We have to pass in the an extension for the cookie storage directory when
     30       initalising the network process
     31       * UIProcess/mac/WebContextMac.mm:
     32       (WebKit::WebContext::platformDefaultCookieStorageDirectory):
     33         Make sure we provide the correct location on IOS
     34       * WebProcess/cocoa/WebProcessCocoa.mm:
     35       (WebKit::WebProcess::platformInitializeWebProcess):
     36         Consume the cookie storage extension
     37
    1382014-07-02  Csaba Osztrogonác  <ossy@webkit.org>
    239
  • trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm

    r170686 r170733  
    6161void NetworkProcess::platformInitializeNetworkProcessCocoa(const NetworkProcessCreationParameters& parameters)
    6262{
     63    SandboxExtension::consumePermanently(parameters.cookieStorageDirectoryExtensionHandle);
     64    m_diskCacheDirectory = parameters.diskCacheDirectory;
     65
     66    if (!m_diskCacheDirectory.isNull()) {
     67        SandboxExtension::consumePermanently(parameters.diskCacheDirectoryExtensionHandle);
    6368#if PLATFORM(IOS)
    64     if (!parameters.uiProcessBundleIdentifier.isNull()) {
    6569        [NSURLCache setSharedURLCache:adoptNS([[NSURLCache alloc]
    6670            _initWithMemoryCapacity:parameters.nsURLCacheMemoryCapacity
    6771            diskCapacity:parameters.nsURLCacheDiskCapacity
    6872            relativePath:parameters.uiProcessBundleIdentifier]).get()];
    69     }
    7073#else
    71     m_diskCacheDirectory = parameters.diskCacheDirectory;
    72 
    73     if (!m_diskCacheDirectory.isNull()) {
    74         SandboxExtension::consumePermanently(parameters.diskCacheDirectoryExtensionHandle);
    7574        [NSURLCache setSharedURLCache:adoptNS([[NSURLCache alloc]
    7675            initWithMemoryCapacity:parameters.nsURLCacheMemoryCapacity
    7776            diskCapacity:parameters.nsURLCacheDiskCapacity
    7877            diskPath:parameters.diskCacheDirectory]).get()];
     78#endif
    7979    }
    80 #endif
    8180
    8281#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
  • trunk/Source/WebKit2/Resources/SandboxProfiles/ios/com.apple.WebKit.Networking.sb

    r170686 r170733  
    2323
    2424(version 1)
    25 (allow default)
     25(deny default (with partial-symbolication))
     26(allow system-audit file-read-metadata)
    2627
    2728(import "common.sb")
    2829(import "removed-dev-nodes.sb")
     30
     31;; Access CFNetwork shared cookies
     32;; This is too generous -- <rdar://problem/17496756>
     33(apple-cookie-access 'with-read-write)
     34
     35;; Sandbox extensions
     36(allow file-read* (container-subpath "Library/")
     37       (extension "com.apple.webkit.read"))
     38
     39;; Access to client's cache folder & re-vending to CFNetwork.
     40(allow file-read* file-write* (require-all (container-subpath "Library/")
     41       (extension "com.apple.nsurlstorage.extension-cache")))
     42(allow file-issue-extension  (require-all ((container-subpath "Library/")
     43       (extension-class "com.apple.nsurlstorage.extension-cache")))
     44
     45;; App sandbox extensions
     46(allow file-read* file-write* (require-all (container-subpath "Library/")
     47       (extension "com.apple.app-sandbox.read-write")))
     48
     49;; Access to own cache & temp folders.
     50(allow file-read* file-write* (require-all (container-subpath "")
     51       (extension "com.apple.webkit.read-write")))
     52
     53;; IOKit user clients
     54(allow iokit-open
     55       (iokit-user-client-class "RootDomainUserClient"))
     56
     57;; Various services required by CFNetwork and other frameworks
     58(allow mach-lookup
     59       (global-name "com.apple.PowerManagement.control"))
     60
     61(network-client)
     62
     63;; Security framework
     64(allow mach-lookup
     65       (global-name "com.apple.ocspd")
     66       (global-name "com.apple.securityd"))
     67
     68(deny file-write-create
     69       (vnode-type SYMLINK))
  • trunk/Source/WebKit2/Shared/Network/NetworkProcessCreationParameters.cpp

    r170686 r170733  
    4343    encoder << diskCacheDirectory;
    4444    encoder << diskCacheDirectoryExtensionHandle;
     45    encoder << cookieStorageDirectory;
     46    encoder << cookieStorageDirectoryExtensionHandle;
    4547    encoder << shouldUseTestingNetworkSession;
    4648#if ENABLE(CUSTOM_PROTOCOLS)
     
    7375        return false;
    7476    if (!decoder.decode(result.diskCacheDirectoryExtensionHandle))
     77        return false;
     78    if (!decoder.decode(result.cookieStorageDirectory))
     79        return false;
     80    if (!decoder.decode(result.cookieStorageDirectoryExtensionHandle))
    7581        return false;
    7682    if (!decoder.decode(result.shouldUseTestingNetworkSession))
  • trunk/Source/WebKit2/Shared/Network/NetworkProcessCreationParameters.h

    r170686 r170733  
    5757    SandboxExtension::Handle diskCacheDirectoryExtensionHandle;
    5858
     59    String cookieStorageDirectory;
     60    SandboxExtension::Handle cookieStorageDirectoryExtensionHandle;
     61
    5962    bool shouldUseTestingNetworkSession;
    6063
  • trunk/Source/WebKit2/Shared/mac/SandboxUtilities.cpp

    r170686 r170733  
    2828
    2929#include <array>
     30#include <wtf/text/WTFString.h>
    3031
    3132#if __has_include(<sandbox/private.h>)
     
    6869}
    6970
     71String pathForProcessContainer()
     72{
     73    std::array<char, MAXPATHLEN> path;
     74    path[0] = 0;
     75    sandbox_container_path_for_pid(getpid(), path.data(), path.size());
     76
     77    return String::fromUTF8(path.data());
    7078}
     79
     80}
  • trunk/Source/WebKit2/Shared/mac/SandboxUtilities.h

    r170686 r170733  
    2828
    2929#include <sys/types.h>
     30#include <wtf/Forward.h>
    3031
    3132namespace WebKit {
     
    3435bool processHasContainer();
    3536
     37// Returns an empty string if the process is not in a container.
     38String pathForProcessContainer();
     39
    3640}
    3741
  • trunk/Source/WebKit2/UIProcess/WebContext.cpp

    r170686 r170733  
    412412        SandboxExtension::createHandleForReadWriteDirectory(parameters.diskCacheDirectory, parameters.diskCacheDirectoryExtensionHandle);
    413413
     414    parameters.cookieStorageDirectory = cookieStorageDirectory();
     415    if (!parameters.cookieStorageDirectory.isEmpty())
     416        SandboxExtension::createHandleForReadWriteDirectory(parameters.cookieStorageDirectory, parameters.cookieStorageDirectoryExtensionHandle);
     417
    414418    parameters.shouldUseTestingNetworkSession = m_shouldUseTestingNetworkSession;
    415419
  • trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm

    r170686 r170733  
    2828
    2929#import "PluginProcessManager.h"
     30#import "SandboxUtilities.h"
    3031#import "TextChecker.h"
    3132#import "WKBrowsingContextControllerInternal.h"
     
    270271String WebContext::platformDefaultCookieStorageDirectory() const
    271272{
     273#if PLATFORM(IOS)
     274    String path = pathForProcessContainer();
     275    if (path.isEmpty())
     276        path = NSHomeDirectory();
     277
     278    path = path + "/Library/Cookies";
     279    return stringByResolvingSymlinksInPath(path);
     280#else
    272281    notImplemented();
    273282    return [@"" stringByStandardizingPath];
     283#endif
    274284}
    275285
  • trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm

    r170686 r170733  
    168168    SandboxExtension::consumePermanently(parameters.applicationCacheDirectoryExtensionHandle);
    169169    SandboxExtension::consumePermanently(parameters.diskCacheDirectoryExtensionHandle);
     170    SandboxExtension::consumePermanently(parameters.cookieStorageDirectoryExtensionHandle);
    170171#endif
    171172
Note: See TracChangeset for help on using the changeset viewer.