6ef15da06eb8897524f0b3b8d529570a824a493b
[WebKit-https.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        (literal "/Library/Application Support/CrashReporter/SubmitDiagInfo.domains")
57
58        ;; System and user preferences
59        (literal "/Library/Preferences/.GlobalPreferences.plist")
60        (home-literal "/Library/Preferences/.GlobalPreferences.plist")
61        (home-regex #"/Library/Preferences/ByHost/\.GlobalPreferences\.")
62        (home-regex #"/Library/Preferences/ByHost/com\.apple\.HIToolbox\.")
63        (home-regex #"/Library/Preferences/ByHost/com\.apple\.networkConnect\.")
64        (home-literal "/Library/Preferences/com.apple.ATS.plist")
65        (home-literal "/Library/Preferences/com.apple.CoreGraphics.plist")
66        (home-literal "/Library/Preferences/com.apple.DownloadAssessment.plist")
67        (home-literal "/Library/Preferences/com.apple.HIToolbox.plist")
68        (home-literal "/Library/Preferences/com.apple.LaunchServices.plist")
69        (home-literal "/Library/Preferences/com.apple.MultitouchSupport.plist") ;; FIXME: Remove when <rdar://problem/13011633> is fixed.
70        (home-literal "/Library/Preferences/com.apple.QTKit.plist")
71        (home-literal "/Library/Preferences/com.apple.WebFoundation.plist")
72        (home-literal "/Library/Preferences/com.apple.avfoundation.plist")
73        (home-literal "/Library/Preferences/com.apple.coremedia.plist")
74        (home-literal "/Library/Preferences/com.apple.speech.voice.prefs.plist")
75        (home-literal "/Library/Preferences/com.apple.systemsound.plist")
76        (home-literal "/Library/Preferences/com.apple.universalaccess.plist")
77        (home-literal "/Library/Preferences/com.apple.lookup.shared.plist")
78        (home-regex #"/Library/Preferences/com\.apple\.driver\.(AppleBluetoothMultitouch\.mouse|AppleBluetoothMultitouch\.trackpad|AppleHIDMouse)\.plist$")
79        (home-literal "/.CFUserTextEncoding")
80
81        ;; FIXME: This should be removed when <rdar://problem/8957845> is fixed.
82        (home-subpath "/Library/Fonts")
83
84        ;; FIXME: These should be removed when <rdar://problem/9217757> is fixed.
85        (home-subpath "/Library/Audio/Plug-Ins/Components")
86        (home-subpath "/Library/Preferences/QuickTime Preferences")
87        (home-literal "/Library/Caches/com.apple.coreaudio.components.plist")
88        (subpath "/Library/Audio/Plug-Ins/Components")
89        (subpath "/Library/Audio/Plug-Ins/HAL")
90        (subpath "/Library/Video/Plug-Ins")
91        (subpath "/Library/QuickTime")
92
93        (home-subpath "/Library/Dictionaries"))
94
95 ;; On-disk WebKit2 framework location, to account for debug installations outside of /System/Library/Frameworks,
96 ;; and to allow issuing extensions.
97 (allow-read-directory-and-issue-read-extensions (param "WEBKIT2_FRAMEWORK_DIR"))
98
99 ;; Allow issuing extensions to system libraries that the Network process can already read.
100 ;; This is to avoid warnings attempting to create extensions for these resources.
101 (allow-read-directory-and-issue-read-extensions "/System/Library/PrivateFrameworks/WebInspectorUI.framework")
102
103 ;; Sandbox extensions
104 (define (apply-read-and-issue-extension op path-filter)
105     (op file-read* path-filter)
106     (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") path-filter)))
107 (define (apply-write-and-issue-extension op path-filter)
108     (op file-write* path-filter)
109     (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read-write") path-filter)))
110 (define (read-only-and-issue-extensions path-filter)
111     (apply-read-and-issue-extension allow path-filter))
112 (define (read-write-and-issue-extensions path-filter)
113     (apply-read-and-issue-extension allow path-filter)
114     (apply-write-and-issue-extension allow path-filter))
115 (read-only-and-issue-extensions (extension "com.apple.app-sandbox.read"))
116 (read-write-and-issue-extensions (extension "com.apple.app-sandbox.read-write"))
117 (allow mach-lookup (extension "com.apple.app-sandbox.mach")) ;; FIXME: Should be removed when <rdar://problem/13066206> is fixed.
118
119 ;; Allow the OpenGL Profiler to attach.
120 (if (defined? 'mach-register)
121     (allow mach-register (global-name-regex #"^_oglprof_attach_<[0-9]+>$")))
122
123 ;; MediaAccessibility
124 (allow file-read* (home-literal "/Library/Preferences/com.apple.mediaaccessibility.plist"))
125 (allow file-read* file-write* (home-literal "/Library/Preferences/com.apple.mediaaccessibility.public.plist"))
126
127 (if (positive? (string-length (param "DARWIN_USER_CACHE_DIR")))
128     (allow file* (subpath (param "DARWIN_USER_CACHE_DIR"))))
129
130 (if (positive? (string-length (param "DARWIN_USER_TEMP_DIR")))
131     (allow file* (subpath (param "DARWIN_USER_TEMP_DIR"))))
132
133 ;; IOKit user clients
134 (allow iokit-open
135        (iokit-user-client-class "AppleUpstreamUserClient")
136        (iokit-user-client-class "IOHIDParamUserClient")
137        (iokit-user-client-class "RootDomainUserClient")
138        (iokit-user-client-class "IOAudioControlUserClient")
139        (iokit-user-client-class "IOAudioEngineUserClient"))
140
141 ;; cookied.
142 ;; FIXME: Update for <rdar://problem/13642852>.
143 (allow ipc-posix-shm-read-data
144     (ipc-posix-name "FNetwork.defaultStorageSession")
145     (ipc-posix-name-regex #"\.PrivateBrowsing-")
146     (ipc-posix-name-regex #"^WebKit Test-"))
147
148 ;; ColorSync
149 (allow ipc-posix-shm*
150     (ipc-posix-name "com.apple.ColorSync.Gen.lock")
151     (ipc-posix-name "com.apple.ColorSync.Disp.lock")
152     (ipc-posix-name "com.apple.ColorSync.Gray2.2")
153     (ipc-posix-name "com.apple.ColorSync.sRGB")
154     (ipc-posix-name "com.apple.ColorSync.GenGray")
155     (ipc-posix-name "com.apple.ColorSync.GenRGB"))
156
157 ;; Audio
158 (allow ipc-posix-shm-read* ipc-posix-shm-write-data
159     (ipc-posix-name-regex #"^AudioIO"))
160
161 ;; Remote Web Inspector
162 (allow mach-lookup
163        (global-name "com.apple.webinspector"))
164
165 ;; Various services required by AppKit and other frameworks
166 (allow mach-lookup
167        (global-name "com.apple.DiskArbitration.diskarbitrationd")
168        (global-name "com.apple.FileCoordination")
169        (global-name "com.apple.FontObjectsServer")
170        (global-name "com.apple.FontServer")
171        (global-name "com.apple.SystemConfiguration.configd")
172        (global-name "com.apple.SystemConfiguration.PPPController")
173        (global-name "com.apple.audio.SystemSoundServer-OSX")
174        (global-name "com.apple.audio.VDCAssistant")
175        (global-name "com.apple.audio.audiohald")
176        (global-name "com.apple.audio.coreaudiod")
177        (global-name "com.apple.awdd")
178        (global-name "com.apple.cookied")
179        (global-name "com.apple.dock.server")
180        (global-name "com.apple.fonts")
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        (global-name "com.apple.iconservices")
192        (global-name "com.apple.iconservices.store")
193 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
194        (global-name "com.apple.nesessionmanager.flow-divert-token")
195 #endif
196 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
197        (global-name "com.apple.mediaremoted.xpc")
198 #endif
199 )
200
201 ;; Security framework
202 (allow mach-lookup
203        (global-name "com.apple.ctkd.token-client") 
204        (global-name "com.apple.ocspd")
205        (global-name "com.apple.securityd.xpc") 
206        (global-name "com.apple.CoreAuthentication.agent.libxpc")
207        (global-name "com.apple.SecurityServer"))
208
209 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101240
210 (allow file-read* file-write* (home-subpath "/Library/Keychains")) ;; FIXME: This should be removed when <rdar://problem/10479685> is fixed.
211 #endif
212
213 (allow file-read* file-write* (subpath "/private/var/db/mds/system")) ;; FIXME: This should be removed when <rdar://problem/9538414> is fixed.
214
215 (allow file-read*
216 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101240
217        (subpath "/Library/Keychains")
218 #endif
219        (subpath "/private/var/db/mds")
220        (literal "/private/var/db/DetachedSignatures")
221        (literal "/Library/Preferences/com.apple.crypto.plist")
222        (literal "/Library/Preferences/com.apple.security.plist")
223        (literal "/Library/Preferences/com.apple.security.common.plist")
224        (literal "/Library/Preferences/com.apple.security.revocation.plist")
225        (home-literal "/Library/Application Support/SyncServices/Local/ClientsWithChanges/com.apple.Keychain")
226        (home-literal "/Library/Preferences/com.apple.security.plist")
227        (home-literal "/Library/Preferences/com.apple.security.revocation.plist"))
228
229 (allow ipc-posix-shm-read* ipc-posix-shm-write-data
230        (ipc-posix-name "com.apple.AppleDatabaseChanged"))
231
232 ;; CoreFoundation. We don't import com.apple.corefoundation.sb, because it allows unnecessary access to pasteboard.
233 (allow mach-lookup
234     (global-name-regex #"^com.apple.distributed_notifications")                                                       
235     (global-name "com.apple.CoreServices.coreservicesd"))
236 (allow file-read-data
237     (literal "/dev/autofs_nowait")) ; Used by CF to circumvent automount triggers
238 (allow ipc-posix-shm
239     (ipc-posix-name-regex #"^CFPBS:")) ; <rdar://problem/13757475>
240 (allow system-fsctl (fsctl-command (_IO "h" 47)))
241
242 ;; Graphics
243 (system-graphics)
244
245 ;; Networking
246 (system-network)
247 (allow network-outbound
248        ;; Local mDNSResponder for DNS, arbitrary outbound TCP
249        (literal "/private/var/run/mDNSResponder")
250        (remote tcp))
251
252 ;; Needed for NSAttributedString, <rdar://problem/10844321>.
253 (allow file-read*
254        (home-literal "/Library/Preferences/pbs.plist")
255        (home-literal "/Library/Preferences/com.apple.ServicesMenu.Services.plist"))
256 (allow mach-lookup
257        (global-name "com.apple.pbs.fetch_services"))
258
259 ;; FIXME should be removed when <rdar://problem/9347205> + related radar in Safari is fixed
260 (allow mach-lookup
261        (global-name "org.h5l.kcm")
262        (global-name "com.apple.GSSCred")
263        (global-name "com.apple.system.logger")
264        (global-name "com.apple.system.notification_center"))
265 (allow network-outbound
266        (remote udp))
267 (allow file-read*
268         (home-subpath "/Library/Preferences/com.apple.Kerberos.plist")
269         (home-subpath "/Library/Preferences/com.apple.GSS.plist")
270         (home-subpath "/Library/Preferences/edu.mit.Kerberos")
271         (literal "/Library/Preferences/com.apple.Kerberos.plist")
272         (literal "/Library/Preferences/com.apple.GSS.plist")
273         (literal "/Library/Preferences/edu.mit.Kerberos")
274         (literal "/private/etc/krb5.conf")
275         (literal "/private/etc/services")
276         (literal "/private/etc/host")
277         (subpath "/Library/KerberosPlugins/GSSAPI")
278         (subpath "/Library/KerberosPlugins/KerberosFrameworkPlugins"))
279
280 (if (defined? 'vnode-type)
281         (deny file-write-create (vnode-type SYMLINK)))
282
283 ;; Reserve a namespace for additional protected extended attributes.
284 (deny file-read-xattr file-write-xattr (xattr-regex #"^com\.apple\.security\.private\."))
285
286 (deny file-read* file-write* (with no-log)
287        ;; FIXME: Should be removed after <rdar://problem/10463881> is fixed.
288        (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2")
289        (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2-journal"))
290
291 ;; Deny access needed for unnecessary NSApplication initialization.
292 ;; FIXME: This can be removed once <rdar://problem/13011633> is fixed.
293 (deny file-read* (with no-log)
294        (home-literal "/Library/Preferences/com.apple.speech.recognition.AppleSpeechRecognition.prefs.plist")
295        (subpath "/Library/InputManagers")
296        (home-subpath "/Library/InputManagers"))
297 (deny mach-lookup (with no-log)
298        (global-name "com.apple.coreservices.appleevents")
299        (global-name "com.apple.pasteboard.1")
300        (global-name "com.apple.speech.recognitionserver"))
301 ;; Also part of unnecessary NSApplication initialization, but we can't block access to these yet, see <rdar://problem/13869765>.
302 (allow file-read*
303        (subpath "/Library/Components")
304        (subpath "/Library/Keyboard Layouts")
305        (subpath "/Library/Input Methods")
306        (home-subpath "/Library/Components")
307        (home-subpath "/Library/Keyboard Layouts")
308        (home-subpath "/Library/Input Methods"))
309
310 ;; AirPlay
311 (allow mach-lookup
312     (global-name "com.apple.coremedia.endpoint.xpc")
313     (global-name "com.apple.coremedia.endpointstream.xpc")
314     (global-name "com.apple.coremedia.endpointplaybacksession.xpc")
315     (global-name "com.apple.coremedia.endpointpicker.xpc"))
316
317 ;; Data Detectors
318 (allow file-read* (subpath "/private/var/db/datadetectors/sys"))
319
320 ;; Media capture, utilities
321 (if (not (defined? 'sbpl-filter?))
322   (define (sbpl-filter? x)
323       (and (list? x)
324            (eq? (car x) 'filter))))
325
326 (macro (with-filter form)
327    (let* ((ps (cdr form))
328           (extra-filter (car ps))
329           (rules (cdr ps)))
330     `(letrec
331         ((collect
332              (lambda (l filters non-filters)
333                  (if (null? l)
334                      (list filters non-filters)
335                      (let* 
336                          ((x (car l))
337                           (rest (cdr l)))
338                          (if (sbpl-filter? x)
339                              (collect rest (cons x filters) non-filters)
340                              (collect rest filters (cons x non-filters)))))))
341          (inject-filter
342              (lambda args
343                  (let* ((collected (collect args '() '()))
344                         (filters (car collected))
345                         (non-filters (cadr collected)))
346                  (if (null? filters)
347                      (cons ,extra-filter non-filters)
348                      (cons (require-all (apply require-any filters) ,extra-filter) non-filters)))))
349          (orig-allow allow)
350          (orig-deny deny)
351          (wrapper
352              (lambda (action)
353                  (lambda args (apply action (apply inject-filter args))))))
354         (set! allow (wrapper orig-allow))
355         (set! deny (wrapper orig-deny))
356         ,@rules
357         (set! deny orig-deny)
358         (set! allow orig-allow))))
359
360 (define (home-library-preferences-regex home-library-preferences-relative-regex)
361     (regex (string-append "^" (regex-quote (param "HOME_LIBRARY_PREFERENCES_DIR")) home-library-preferences-relative-regex)))
362
363 (define (home-library-preferences-literal home-library-preferences-relative-literal)
364     (literal (string-append (param "HOME_LIBRARY_PREFERENCES_DIR") home-library-preferences-relative-literal)))
365
366 (define (shared-preferences-read . domains)
367   (for-each (lambda (domain)
368               (begin
369                 (if (defined? `user-preference-read)
370                     (allow user-preference-read (preference-domain domain)))
371                 ; (Temporary) backward compatibility with non-CFPreferences readers.
372                 (allow file-read*
373                        (literal (string-append "/Library/Preferences/" domain ".plist"))
374                        (home-library-preferences-literal (string-append "/" domain ".plist"))
375                        (home-library-preferences-regex (string-append #"/ByHost/" (regex-quote domain) #"\..*\.plist$")))))
376             domains))
377
378 ;; Media capture, microphone access
379 (with-filter (extension "com.apple.webkit.microphone")
380     (allow device-microphone))
381
382 ;; Media capture, camera access
383 (with-filter (extension "com.apple.webkit.camera")
384     (shared-preferences-read "com.apple.coremedia")
385     (allow mach-lookup (extension "com.apple.app-sandbox.mach"))
386     (allow mach-lookup
387         (global-name "com.apple.cmio.AppleCameraAssistant")
388         ;; Apple DAL assistants
389         (global-name "com.apple.cmio.VDCAssistant")
390         (global-name "com.apple.cmio.AVCAssistant")
391         (global-name "com.apple.cmio.IIDCVideoAssistant")
392         ;; QuickTimeIIDCDigitizer assistant
393         (global-name "com.apple.IIDCAssistant"))
394     (allow iokit-open
395         ;; QuickTimeUSBVDCDigitizer
396         (iokit-user-client-class "IOUSBDeviceUserClientV2")
397         (iokit-user-client-class "IOUSBInterfaceUserClientV2"))
398     (allow device-camera))