BinarySwitch should be faster on average
[WebKit.git] / Source / WebKit2 / WebProcess / com.apple.WebProcess.sb.in
1 ; Copyright (C) 2010, 2011, 2012, 2013, 2014 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 (define (allow-read-directory-and-issue-read-extensions path)
41     (if path
42         (begin
43             (allow file-read* (subpath path))
44             (allow file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") (subpath path))))))
45
46 ;; Read-only preferences and data
47 (allow file-read*
48        ;; Basic system paths
49        (subpath "/Library/Dictionaries")
50        (subpath "/Library/Fonts")
51        (subpath "/Library/Frameworks")
52        (subpath "/Library/Managed Preferences")
53        (subpath "/Library/Speech/Synthesizers")
54        (regex #"^/private/etc/(hosts|group|passwd)$")
55
56        ;; System and user preferences
57        (literal "/Library/Preferences/.GlobalPreferences.plist")
58        (home-literal "/Library/Preferences/.GlobalPreferences.plist")
59        (home-regex #"/Library/Preferences/ByHost/\.GlobalPreferences\.")
60        (home-regex #"/Library/Preferences/ByHost/com\.apple\.HIToolbox\.")
61        (home-regex #"/Library/Preferences/ByHost/com\.apple\.networkConnect\.")
62        (home-literal "/Library/Preferences/com.apple.ATS.plist")
63        (home-literal "/Library/Preferences/com.apple.CoreGraphics.plist")
64        (home-literal "/Library/Preferences/com.apple.DownloadAssessment.plist")
65        (home-literal "/Library/Preferences/com.apple.HIToolbox.plist")
66        (home-literal "/Library/Preferences/com.apple.LaunchServices.plist")
67        (home-literal "/Library/Preferences/com.apple.MultitouchSupport.plist") ;; FIXME: Remove when <rdar://problem/13011633> is fixed.
68        (home-literal "/Library/Preferences/com.apple.QTKit.plist")
69        (home-literal "/Library/Preferences/com.apple.WebFoundation.plist")
70        (home-literal "/Library/Preferences/com.apple.avfoundation.plist")
71        (home-literal "/Library/Preferences/com.apple.coremedia.plist")
72        (home-literal "/Library/Preferences/com.apple.speech.voice.prefs.plist")
73        (home-literal "/Library/Preferences/com.apple.universalaccess.plist")
74        (home-regex #"/Library/Preferences/com\.apple\.driver\.(AppleBluetoothMultitouch\.mouse|AppleBluetoothMultitouch\.trackpad|AppleHIDMouse)\.plist$")
75        (home-literal "/.CFUserTextEncoding")
76
77        ;; FIXME: This should be removed when <rdar://problem/8957845> is fixed.
78        (home-subpath "/Library/Fonts")
79
80        ;; FIXME: These should be removed when <rdar://problem/9217757> is fixed.
81        (home-subpath "/Library/Audio/Plug-Ins/Components")
82        (home-subpath "/Library/Preferences/QuickTime Preferences")
83        (home-literal "/Library/Caches/com.apple.coreaudio.components.plist")
84        (subpath "/Library/Audio/Plug-Ins/Components")
85        (subpath "/Library/Audio/Plug-Ins/HAL")
86        (subpath "/Library/Video/Plug-Ins")
87        (subpath "/Library/QuickTime")
88
89        (home-subpath "/Library/Dictionaries"))
90
91 ;; On-disk WebKit2 framework location, to account for debug installations outside of /System/Library/Frameworks,
92 ;; and to allow issuing extensions.
93 (allow-read-directory-and-issue-read-extensions (param "WEBKIT2_FRAMEWORK_DIR"))
94
95 ;; Allow issuing extensions to system libraries that the Network process can already read.
96 ;; This is to avoid warnings attempting to create extensions for these resources.
97 (allow-read-directory-and-issue-read-extensions "/System/Library/PrivateFrameworks/WebInspectorUI.framework")
98
99 ;; Sandbox extensions
100 (define (apply-read-and-issue-extension op path-filter)
101     (op file-read* path-filter)
102     (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") path-filter)))
103 (define (apply-write-and-issue-extension op path-filter)
104     (op file-write* path-filter)
105     (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read-write") path-filter)))
106 (define (read-only-and-issue-extensions path-filter)
107     (apply-read-and-issue-extension allow path-filter))
108 (define (read-write-and-issue-extensions path-filter)
109     (apply-read-and-issue-extension allow path-filter)
110     (apply-write-and-issue-extension allow path-filter))
111 (read-only-and-issue-extensions (extension "com.apple.app-sandbox.read"))
112 (read-write-and-issue-extensions (extension "com.apple.app-sandbox.read-write"))
113 (allow mach-lookup (extension "com.apple.app-sandbox.mach")) ;; FIXME: Should be removed when <rdar://problem/13066206> is fixed.
114
115 ;; Allow the OpenGL Profiler to attach.
116 (if (defined? 'mach-register)
117     (allow mach-register (global-name-regex #"^_oglprof_attach_<[0-9]+>$")))
118
119 ;; MediaAccessibility
120 (allow file-read* (home-literal "/Library/Preferences/com.apple.mediaaccessibility.plist"))
121 (allow file-read* file-write* (home-literal "/Library/Preferences/com.apple.mediaaccessibility.public.plist"))
122
123 (if (positive? (string-length (param "DARWIN_USER_CACHE_DIR")))
124     (allow file* (subpath (param "DARWIN_USER_CACHE_DIR"))))
125
126 (if (positive? (string-length (param "DARWIN_USER_TEMP_DIR")))
127     (allow file* (subpath (param "DARWIN_USER_TEMP_DIR"))))
128
129 ;; IOKit user clients
130 (allow iokit-open
131        (iokit-user-client-class "AppleUpstreamUserClient")
132        (iokit-user-client-class "IOHIDParamUserClient")
133        (iokit-user-client-class "RootDomainUserClient")
134        (iokit-user-client-class "IOAudioControlUserClient")
135        (iokit-user-client-class "IOAudioEngineUserClient"))
136
137 ;; cookied.
138 ;; FIXME: Update for <rdar://problem/13642852>.
139 (allow ipc-posix-shm-read-data
140     (ipc-posix-name "FNetwork.defaultStorageSession")
141     (ipc-posix-name-regex #"\.PrivateBrowsing-")
142     (ipc-posix-name-regex #"^WebKit Test-"))
143
144 ;; ColorSync
145 ;; FIXME: Remove names with underscores when possible (see <rdar://problem/13072721>).
146 (allow ipc-posix-shm*
147     (ipc-posix-name "_CS_GSHMEMLOCK")
148     (ipc-posix-name "_CS_DSHMEMLOCK")
149     (ipc-posix-name "_CSGRAYPROFILE")
150     (ipc-posix-name "_CSRGBPROFILE")
151     (ipc-posix-name "_CSGENGPROFILE")
152     (ipc-posix-name "_CSGENRPROFILE")
153     (ipc-posix-name "com.apple.ColorSync.Gen.lock")
154     (ipc-posix-name "com.apple.ColorSync.Disp.lock")
155     (ipc-posix-name "com.apple.ColorSync.Gray2.2")
156     (ipc-posix-name "com.apple.ColorSync.sRGB")
157     (ipc-posix-name "com.apple.ColorSync.GenGray")
158     (ipc-posix-name "com.apple.ColorSync.GenRGB"))
159
160 ;; Audio
161 (allow ipc-posix-shm-read* ipc-posix-shm-write-data
162     (ipc-posix-name-regex #"^AudioIO"))
163
164 ;; Remote Web Inspector
165 (allow mach-lookup
166        (global-name "com.apple.webinspector"))
167
168 ;; Various services required by AppKit and other frameworks
169 (allow mach-lookup
170        (global-name "com.apple.DiskArbitration.diskarbitrationd")
171        (global-name "com.apple.FileCoordination")
172        (global-name "com.apple.FontObjectsServer")
173        (global-name "com.apple.FontServer")
174        (global-name "com.apple.SystemConfiguration.configd")
175        (global-name "com.apple.SystemConfiguration.PPPController")
176        (global-name "com.apple.audio.VDCAssistant")
177        (global-name "com.apple.audio.audiohald")
178        (global-name "com.apple.audio.coreaudiod")
179        (global-name "com.apple.cookied")
180        (global-name "com.apple.dock.server")
181        (global-name "com.apple.system.opendirectoryd.api")
182        (global-name "com.apple.tccd")
183        (global-name "com.apple.tccd.system")
184        (global-name "com.apple.window_proxies")
185        (global-name "com.apple.windowserver.active")
186        (global-name "com.apple.cfnetwork.AuthBrokerAgent")
187        (global-name "com.apple.PowerManagement.control")
188        (global-name "com.apple.speech.speechsynthesisd")
189        (global-name "com.apple.speech.synthesis.console")
190        (global-name "com.apple.coreservices.launchservicesd")
191 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
192        (global-name "com.apple.iconservices")
193        (global-name "com.apple.iconservices.store")
194 #endif
195 )
196
197 ;; Security framework
198 (allow mach-lookup
199        (global-name "com.apple.ocspd")
200        (global-name "com.apple.SecurityServer"))
201 (allow file-read* file-write* (home-subpath "/Library/Keychains")) ;; FIXME: This should be removed when <rdar://problem/10479685> is fixed.
202 (allow file-read* file-write* (subpath "/private/var/db/mds/system")) ;; FIXME: This should be removed when <rdar://problem/9538414> is fixed.
203 (allow file-read*
204        (subpath "/Library/Keychains")
205        (subpath "/private/var/db/mds")
206        (literal "/private/var/db/DetachedSignatures")
207        (literal "/Library/Preferences/com.apple.crypto.plist")
208        (literal "/Library/Preferences/com.apple.security.plist")
209        (literal "/Library/Preferences/com.apple.security.common.plist")
210        (literal "/Library/Preferences/com.apple.security.revocation.plist")
211        (home-literal "/Library/Application Support/SyncServices/Local/ClientsWithChanges/com.apple.Keychain")
212        (home-literal "/Library/Preferences/com.apple.security.plist")
213        (home-literal "/Library/Preferences/com.apple.security.revocation.plist"))
214 (allow ipc-posix-shm-read* ipc-posix-shm-write-data
215        (ipc-posix-name "com.apple.AppleDatabaseChanged"))
216
217 ;; CoreFoundation. We don't import com.apple.corefoundation.sb, because it allows unnecessary access to pasteboard.
218 (allow mach-lookup
219     (global-name-regex #"^com.apple.distributed_notifications")                                                       
220     (global-name "com.apple.CoreServices.coreservicesd"))
221 (allow file-read-data
222     (literal "/dev/autofs_nowait")) ; Used by CF to circumvent automount triggers
223 (allow ipc-posix-shm
224     (ipc-posix-name-regex #"^CFPBS:")) ; <rdar://problem/13757475>
225
226 ;; Graphics
227 (system-graphics)
228
229 ;; Networking
230 (system-network)
231 (allow network-outbound
232        ;; Local mDNSResponder for DNS, arbitrary outbound TCP
233        (literal "/private/var/run/mDNSResponder")
234        (remote tcp))
235
236 ;; Needed for NSAttributedString, <rdar://problem/10844321>.
237 (allow file-read*
238        (home-literal "/Library/Preferences/pbs.plist")
239        (home-literal "/Library/Preferences/com.apple.ServicesMenu.Services.plist"))
240 (allow mach-lookup
241        (global-name "com.apple.pbs.fetch_services"))
242
243 ;; FIXME should be removed when <rdar://problem/9347205> + related radar in Safari is fixed
244 (allow mach-lookup
245        (global-name "org.h5l.kcm")
246        (global-name "com.apple.GSSCred")
247        (global-name "com.apple.system.logger")
248        (global-name "com.apple.system.notification_center"))
249 (allow network-outbound
250        (remote udp))
251 (allow file-read*
252         (home-subpath "/Library/Preferences/com.apple.Kerberos.plist")
253         (home-subpath "/Library/Preferences/com.apple.GSS.plist")
254         (home-subpath "/Library/Preferences/edu.mit.Kerberos")
255         (literal "/Library/Preferences/com.apple.Kerberos.plist")
256         (literal "/Library/Preferences/com.apple.GSS.plist")
257         (literal "/Library/Preferences/edu.mit.Kerberos")
258         (literal "/private/etc/krb5.conf")
259         (literal "/private/etc/services")
260         (literal "/private/etc/host")
261         (subpath "/Library/KerberosPlugins/GSSAPI")
262         (subpath "/Library/KerberosPlugins/KerberosFrameworkPlugins"))
263
264 (if (defined? 'vnode-type)
265         (deny file-write-create (vnode-type SYMLINK)))
266
267 ;; FIXME: Should be removed once <rdar://problem/16329087> is fixed.
268 (deny file-write-xattr (xattr "com.apple.quarantine") (with no-log))
269
270 ;; Reserve a namespace for additional protected extended attributes.
271 #if __MAC_OS_X_VERSION_MIN_REQUIRED > 1090
272 (deny file-read-xattr file-write-xattr (xattr-regex #"^com\.apple\.security\.private\."))
273 #else
274 (deny file-read-xattr file-write-xattr (xattr #"^com\.apple\.security\.private\."))
275 #endif
276
277 (deny file-read* file-write* (with no-log)
278        ;; FIXME: Should be removed after <rdar://problem/10463881> is fixed.
279        (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2")
280        (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2-journal"))
281
282 ;; Deny access needed for unnecessary NSApplication initialization.
283 ;; FIXME: This can be removed once <rdar://problem/13011633> is fixed.
284 (deny file-read* (with no-log)
285        (home-literal "/Library/Preferences/com.apple.speech.recognition.AppleSpeechRecognition.prefs.plist")
286        (subpath "/Library/InputManagers")
287        (home-subpath "/Library/InputManagers"))
288 (deny mach-lookup (with no-log)
289        (global-name "com.apple.coreservices.appleevents")
290        (global-name "com.apple.pasteboard.1")
291        (global-name "com.apple.speech.recognitionserver"))
292 ;; Also part of unnecessary NSApplication initialization, but we can't block access to these yet, see <rdar://problem/13869765>.
293 (allow file-read*
294        (subpath "/Library/Components")
295        (subpath "/Library/Keyboard Layouts")
296        (subpath "/Library/Input Methods")
297        (home-subpath "/Library/Components")
298        (home-subpath "/Library/Keyboard Layouts")
299        (home-subpath "/Library/Input Methods"))
300
301 (allow default)