[OS X][WK2] Expand sandbox for new mach endpoints
[WebKit-https.git] / Source / WebKit2 / NetworkProcess / mac / com.apple.WebKit.NetworkProcess.sb.in
1 ; Copyright (C) 2013-2016 Apple Inc. All rights reserved.
2 ;
3 ; Redistribution and use in source and binary forms, with or without
4 ; modification, are permitted provided that the following conditions
5 ; are met:
6 ; 1. Redistributions of source code must retain the above copyright
7 ;    notice, this list of conditions and the following disclaimer.
8 ; 2. Redistributions in binary form must reproduce the above copyright
9 ;    notice, this list of conditions and the following disclaimer in the
10 ;    documentation and/or other materials provided with the distribution.
11 ;
12 ; THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
13 ; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
14 ; THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
15 ; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
16 ; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17 ; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
18 ; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19 ; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20 ; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21 ; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
22 ; THE POSSIBILITY OF SUCH DAMAGE.
23
24 (version 1)
25 (deny default (with partial-symbolication))
26 (allow system-audit file-read-metadata)
27
28 (import "system.sb")
29
30 ;; Utility functions for home directory relative path filters
31 (define (home-regex home-relative-regex)
32   (regex (string-append "^" (regex-quote (param "HOME_DIR")) home-relative-regex)))
33
34 (define (home-subpath home-relative-subpath)
35     (subpath (string-append (param "HOME_DIR") home-relative-subpath)))
36
37 (define (home-literal home-relative-literal)
38     (literal (string-append (param "HOME_DIR") home-relative-literal)))
39
40 ;; Read-only preferences and data
41 (allow file-read*
42     ;; Basic system paths
43     (subpath "/Library/Frameworks")
44     (subpath "/Library/Managed Preferences")
45
46     (literal "/Library/Application Support/CrashReporter/SubmitDiagInfo.domains")
47
48     ;; System and user preferences
49     (literal "/Library/Preferences/.GlobalPreferences.plist")
50     (regex #"^/Library/Managed Preferences/[^/]+/com\.apple\.networkConnect\.plist$")
51     (home-literal "/Library/Preferences/.GlobalPreferences.plist")
52     (home-regex #"/Library/Preferences/ByHost/\.GlobalPreferences\.")
53     (home-regex #"/Library/Preferences/ByHost/com\.apple\.networkConnect\.")
54     (home-literal "/Library/Preferences/com.apple.DownloadAssessment.plist")
55     (home-literal "/Library/Preferences/com.apple.WebFoundation.plist")
56
57     ;; On-disk WebKit2 framework location, to account for debug installations
58     ;; outside of /System/Library/Frameworks
59     (subpath (param "WEBKIT2_FRAMEWORK_DIR")))
60 (allow system-fsctl (fsctl-command (_IO "h" 47)))
61
62 ;; Sandbox extensions
63 (define (apply-read-and-issue-extension op path-filter)
64     (op file-read* path-filter)
65     (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") path-filter)))
66 (define (apply-write-and-issue-extension op path-filter)
67     (op file-write* path-filter)
68     (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read-write") path-filter)))
69 (define (read-only-and-issue-extensions path-filter)
70     (apply-read-and-issue-extension allow path-filter))
71 (define (read-write-and-issue-extensions path-filter)
72     (apply-read-and-issue-extension allow path-filter)
73     (apply-write-and-issue-extension allow path-filter))
74 (read-only-and-issue-extensions (extension "com.apple.app-sandbox.read"))
75 (read-write-and-issue-extensions (extension "com.apple.app-sandbox.read-write"))
76
77 (allow file-read* file-write* (subpath (param "DARWIN_USER_CACHE_DIR")))
78
79 (allow file-read* file-write* (subpath (param "DARWIN_USER_TEMP_DIR")))
80
81 ;; IOKit user clients
82 (allow iokit-open
83     (iokit-user-client-class "RootDomainUserClient"))
84
85 ;; cookied.
86 ;; FIXME: Update for <rdar://problem/13642852>.
87 (allow ipc-posix-shm-read-data
88     (ipc-posix-name "FNetwork.defaultStorageSession")
89     (ipc-posix-name-regex #"\.PrivateBrowsing-")
90     (ipc-posix-name-regex #"^WebKit Test-"))
91
92 ;; Various services required by CFNetwork and other frameworks
93 (allow mach-lookup
94     (global-name "com.apple.FileCoordination")
95     (global-name "com.apple.PowerManagement.control")
96     (global-name "com.apple.SystemConfiguration.configd")
97     (global-name "com.apple.cookied")
98     (global-name "com.apple.cfnetwork.AuthBrokerAgent")
99 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
100     (global-name "com.apple.nesessionmanager.flow-divert-token")
101 #endif
102 )
103
104 ;; Security framework
105 (allow mach-lookup
106        (global-name "com.apple.ctkd.token-client") 
107        (global-name "com.apple.ocspd")
108        (global-name "com.apple.securityd.xpc") 
109        (global-name "com.apple.CoreAuthentication.agent.libxpc")
110        (global-name "com.apple.SecurityServer"))
111 (allow file-read* file-write* (home-subpath "/Library/Keychains")) ;; FIXME: This should be removed when <rdar://problem/10479685> is fixed.
112 (allow file-read* file-write* (subpath "/private/var/db/mds/system")) ;; FIXME: This should be removed when <rdar://problem/9538414> is fixed.
113 (allow file-read*
114        (subpath "/Library/Keychains")
115        (subpath "/private/var/db/mds")
116        (literal "/private/var/db/DetachedSignatures")
117        (literal "/Library/Preferences/com.apple.crypto.plist")
118        (literal "/Library/Preferences/com.apple.security.plist")
119        (literal "/Library/Preferences/com.apple.security.common.plist")
120        (literal "/Library/Preferences/com.apple.security.revocation.plist")
121        (home-literal "/Library/Application Support/SyncServices/Local/ClientsWithChanges/com.apple.Keychain")
122        (home-literal "/Library/Preferences/com.apple.security.plist")
123        (home-literal "/Library/Preferences/com.apple.security.revocation.plist"))
124 (allow ipc-posix-shm-read* ipc-posix-shm-write-data
125        (ipc-posix-name "com.apple.AppleDatabaseChanged"))
126
127 (system-network)
128 (allow network-outbound
129     ;; Local mDNSResponder for DNS, arbitrary outbound TCP
130     (literal "/private/var/run/mDNSResponder")
131     (remote tcp))
132
133 ;; FIXME should be removed when <rdar://problem/9347205> + related radar in Safari is fixed
134 (allow mach-lookup
135     (global-name "org.h5l.kcm")
136     (global-name "com.apple.GSSCred")
137     (global-name "com.apple.system.logger")
138     (global-name "com.apple.system.notification_center"))
139 (allow network-outbound
140     (remote udp))
141 (allow file-read*
142     (home-subpath "/Library/Preferences/com.apple.Kerberos.plist")
143     (home-subpath "/Library/Preferences/com.apple.GSS.plist")
144     (home-subpath "/Library/Preferences/edu.mit.Kerberos")
145     (literal "/Library/Preferences/com.apple.Kerberos.plist")
146     (literal "/Library/Preferences/com.apple.GSS.plist")
147     (literal "/Library/Preferences/edu.mit.Kerberos")
148     (literal "/private/etc/krb5.conf")
149     (literal "/private/etc/services")
150     (literal "/private/etc/host")
151     (subpath "/Library/KerberosPlugins/GSSAPI")
152     (subpath "/Library/KerberosPlugins/KerberosFrameworkPlugins"))
153
154 (if (defined? 'vnode-type)
155     (deny file-write-create (vnode-type SYMLINK)))
156
157 ;; FIXME: Should be removed once <rdar://problem/16329087> is fixed.
158 (deny file-write-xattr (xattr "com.apple.quarantine") (with no-log))
159
160 ;; Reserve a namespace for additional protected extended attributes.
161 (deny file-read-xattr file-write-xattr (xattr-regex #"^com\.apple\.security\.private\."))
162
163 (deny file-read* file-write* (with no-log)
164     ;; FIXME: Should be removed after <rdar://problem/10463881> is fixed.
165     (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2")
166     (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2-journal"))