1 ; Copyright (C) 2013-2022 Apple Inc. All rights reserved.
3 ; Redistribution and use in source and binary forms, with or without
4 ; modification, are permitted provided that the following conditions
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.
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.
25 (deny default (with partial-symbolication))
27 (deny system-privilege)
29 (allow system-audit file-read-metadata)
31 (allow system-privilege (with grant)
33 (privilege-id PRIV_NET_PRIVILEGED_SOCKET_DELEGATE)
34 (require-entitlement "com.apple.private.network.socket-delegate")))
36 ;; We can remove the catch once we no longer need to support older macOS
38 (import "dyld-support.sb"))
40 ;; Silence spurious logging due to rdar://20117923 and rdar://72366475
41 (deny system-privilege (privilege-id PRIV_GLOBAL_PROC_INFO) (with no-report))
43 #include "Shared/Sandbox/preferences.sb"
45 #if ENABLE(SYSTEM_CONTENT_PATH_SANDBOX_RULES)
46 #include <WebKitAdditions/SystemContentSandbox-macos.defs>
49 ;; Utility functions for home directory relative path filters
50 (define (home-regex home-relative-regex)
51 (regex (string-append "^" (regex-quote (param "HOME_DIR")) home-relative-regex)))
53 (define (home-subpath home-relative-subpath)
54 (subpath (string-append (param "HOME_DIR") home-relative-subpath)))
56 (define (home-literal home-relative-literal)
57 (literal (string-append (param "HOME_DIR") home-relative-literal)))
60 (deny mach-register (local-name-prefix ""))
62 (allow system-automount
63 (process-attribute is-platform-binary))
65 (allow file-map-executable (with telemetry))
66 (allow file-map-executable
67 (home-subpath "/Library/Caches")
68 (home-subpath "/Library/Containers")
69 (subpath (param "DARWIN_USER_TEMP_DIR"))
70 (subpath "/Library/KerberosPlugins")
71 (subpath "/System/Library/Frameworks")
72 (subpath "/System/Library/KerberosPlugins")
73 (subpath "/System/Library/PrivateFrameworks")
76 (allow file-read-metadata
80 (literal "/private/etc/localtime"))
82 (allow file-read-metadata (path-ancestors "/System/Volumes/Data/private"))
84 (allow file-read* (literal "/"))
90 (subpath "/Library/Preferences/Logging") ; Logging Rethink
91 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 110000
92 (subpath "/private/var/db/dyld")
94 (subpath "/private/var/db/timezone")
96 (subpath "/usr/share"))
99 (literal "/dev/urandom")
100 (literal "/private/etc/master.passwd")
101 (literal "/private/etc/passwd")
102 (literal "/private/etc/services"))
104 (allow file-read* file-write-data file-ioctl
105 (literal "/dev/dtracehelper"))
108 (require-all (subpath "/AppleInternal/Library/Preferences/Logging")
109 (system-attribute apple-internal)))
111 (allow network-outbound
112 (literal "/private/var/run/syslog"))
114 (allow ipc-posix-shm-read*
115 (ipc-posix-name "apple.shm.notification_center")
116 #if !ENABLE(CFPREFS_DIRECT_MODE)
117 (ipc-posix-name-prefix "apple.cfprefs.")
121 #if ENABLE(SET_WEBCONTENT_PROCESS_INFORMATION_IN_NETWORK_PROCESS)
122 (allow mach-lookup (global-name "com.apple.coreservices.launchservicesd"))
125 #if !ENABLE(CFPREFS_DIRECT_MODE)
127 (global-name "com.apple.cfprefsd.agent")
128 (global-name "com.apple.cfprefsd.daemon")
133 (global-name "com.apple.system.opendirectoryd.libinfo")
134 (global-name "com.apple.trustd")
135 (global-name "com.apple.trustd.agent"))
137 (define (system-network)
139 (literal "/Library/Preferences/com.apple.networkd.plist")
140 (literal "/private/var/db/nsurlstoraged/dafsaData.bin"))
142 (global-name "com.apple.SystemConfiguration.PPPController")
143 (global-name "com.apple.SystemConfiguration.SCNetworkReachability")
144 (global-name "com.apple.networkd")
145 (global-name "com.apple.nsurlstorage-cache")
146 (global-name "com.apple.symptomsd"))
148 (global-name "com.apple.dnssd.service")
149 (global-name "com.apple.nehelper")
150 (global-name "com.apple.nesessionmanager")
151 (global-name "com.apple.usymptomsd"))
152 (allow network-outbound
153 (control-name "com.apple.netsrc"))
155 (socket-domain AF_ROUTE))
157 (require-all (socket-domain AF_SYSTEM)
158 (socket-protocol 2))) ; SYSPROTO_CONTROL
160 (global-name "com.apple.AppSSO.service-xpc"))
161 (deny ipc-posix-shm-read-data
162 (ipc-posix-name "/com.apple.AppSSO.version")))
167 ;;; process-info* defaults to allow; deny it and then allow operations we actually need.
169 (allow process-info-dirtycontrol (target self))
170 (allow process-info-pidinfo)
171 (allow process-info-setcontrol (target self))
179 "kern.maxfilesperproc"
180 "kern.osproductversion" ;; Needed by CFNetwork (HSTS store and others)
183 "kern.osversion" ;; Needed by WebKit and ASL logging.
184 "kern.tcsm_available" ;; Needed for IndexedDB support.
186 (sysctl-name-prefix "kern.proc.pid.")
187 (sysctl-name-prefix "net.routetable"))
193 (deny iokit-get-properties)
194 (allow iokit-get-properties
197 "IOClassNameOverride"
199 "IOServiceDEXTEntitlements"
201 "Product Identification"
202 "Protocol Characteristics"
205 "driver-child-bundle"
210 (deny mach-lookup (xpc-service-name-prefix ""))
212 ;; Remove when <rdar://problem/29646094> is fixed.
213 (define (HEX-pattern-match-generator pattern-descriptor)
214 (letrec ((pattern-string ""))
215 (for-each (lambda (repeat-count)
216 (if (zero? repeat-count)
217 (set! pattern-string (string-append pattern-string "-"))
218 (let appender ((count repeat-count))
221 (set! pattern-string (string-append pattern-string "[0-9A-F]"))
222 (appender (- count 1)))))))
226 ;; return a regex pattern matching string for 8-4-4-4-12 UUIDs:
227 (define (uuid-HEX-pattern-match-string)
228 (HEX-pattern-match-generator '(8 0 4 0 4 0 4 0 12)))
230 ;; global to hold the computed UUID matching pattern.
231 (define *uuid-pattern* "")
233 (define (uuid-regex-string)
234 (if (zero? (string-length *uuid-pattern*))
235 (set! *uuid-pattern* (uuid-HEX-pattern-match-string)))
238 ;; Read-only preferences and data
239 (allow-reading-global-preferences)
241 (shared-preferences-read
242 "com.apple.CFNetwork"
243 "com.apple.DownloadAssessment"
244 "com.apple.WebFoundation"
245 "com.apple.ist.ds.appleconnect2.uat" ;; Remove after <rdar://problem/35542803> ships
246 "com.apple.networkConnect")
249 ;; Basic system paths
250 (subpath "/Library/Frameworks")
251 (subpath "/Library/Managed Preferences")
253 ;; On-disk WebKit2 framework location, to account for debug installations
254 ;; outside of /System/Library/Frameworks
255 (subpath (param "WEBKIT2_FRAMEWORK_DIR")))
257 (allow file-read-data
258 (literal "/usr/local/lib/log") ; <rdar://problem/36629495>
261 ;; Sandbox extensions
262 (define (apply-read-and-issue-extension op path-filter)
263 (op file-read* path-filter)
264 (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") path-filter)))
265 (define (apply-write-and-issue-extension op path-filter)
266 (op file-write* path-filter)
267 (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read-write") path-filter)))
268 (define (read-only-and-issue-extensions path-filter)
269 (apply-read-and-issue-extension allow path-filter))
270 (define (read-write-and-issue-extensions path-filter)
271 (apply-read-and-issue-extension allow path-filter)
272 (apply-write-and-issue-extension allow path-filter))
273 (read-only-and-issue-extensions (extension "com.apple.app-sandbox.read"))
274 (read-write-and-issue-extensions (extension "com.apple.app-sandbox.read-write"))
276 (allow file-read* file-write* (subpath (param "DARWIN_USER_CACHE_DIR")))
278 (allow file-read* file-write* (subpath (param "DARWIN_USER_TEMP_DIR")))
280 ;; IOKit user clients
282 (iokit-user-client-class "RootDomainUserClient") ; Used by PowerObserver
286 (global-name "com.apple.PowerManagement.control"))
288 ;; Various services required by CFNetwork and other frameworks
290 (global-name "com.apple.FileCoordination")
291 (global-name "com.apple.SystemConfiguration.configd")
292 (global-name "com.apple.cfnetwork.AuthBrokerAgent")
293 (global-name "com.apple.cfnetwork.cfnetworkagent")
294 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 120000
295 (global-name "com.apple.cookied")
297 (global-name "com.apple.ist.ds.appleconnect2.service.kdctunnelcontroller")
298 (global-name "com.apple.logd")
299 (global-name "com.apple.logd.events")
300 (global-name "com.apple.lsd.mapdb")
301 (global-name "com.apple.nesessionmanager.flow-divert-token")
302 (global-name "com.apple.nesessionmanager.content-filter") ;; <rdar://problem/47598758>
303 (global-name "com.apple.system.notification_center"))
305 (with-filter (system-attribute apple-internal)
307 (global-name "com.apple.aggregated")
308 (global-name "com.apple.analyticsd")
309 (global-name "com.apple.diagnosticd")))
311 (allow mach-lookup (global-name "com.apple.webkit.adattributiond.service"))
312 (allow mach-lookup (global-name "org.webkit.pcmtestdaemon.service"))
314 (allow mach-lookup (global-name "com.apple.webkit.webpushd.service"))
315 (allow mach-lookup (global-name "org.webkit.webpushtestdaemon.service"))
317 (deny mach-lookup (with no-log)
318 (global-name "com.apple.DiskArbitration.diskarbitrationd"))
321 (global-name "com.apple.DiskArbitration.diskarbitrationd")))
324 (global-name "com.apple.ctkd.token-client")
325 (global-name "com.apple.securityd.xpc")
326 (global-name "com.apple.CoreAuthentication.agent")
327 (global-name "com.apple.ocspd"))
329 ;; Security framework
331 (global-name "com.apple.SecurityServer"))
333 ;; FIXME: This should be removed when <rdar://problem/10479685> is fixed.
334 ;; Restrict AppSandboxed processes from creating /Library/Keychains, but allow access to the contents of /Library/Keychains:
335 (allow file-read-data file-read-metadata
336 (subpath "/Library/Keychains")
337 (home-subpath "/Library/Keychains"))
339 ;; Except deny access to new-style iOS Keychain folders which are UUIDs.
340 (deny file-read* file-write*
341 (regex (string-append "/Library/Keychains/" (uuid-regex-string) "(/|$)"))
342 (home-regex (string-append "/Library/Keychains/" (uuid-regex-string) "(/|$)")))
344 (allow file-read* (subpath "/private/var/db/mds/system")) ;; FIXME: This should be removed when <rdar://problem/9538414> is fixed.
347 (subpath "/private/var/db/mds/system")) ;; FIXME: This should be removed when <rdar://problem/9538414> is fixed.
350 (shared-preferences-read
353 "com.apple.security.common"
354 "com.apple.security.revocation")
357 (subpath "/private/var/db/mds")
359 ; The following are needed until the causes of <rdar://problem/41487786> are resolved.
360 (literal "/Library/Preferences/com.apple.security.plist")
361 (home-literal "/Library/Preferences/com.apple.security.plist")
363 ; Likewise for <rdar://problem/43310000>
364 (literal "/Library/Preferences/com.apple.ist.ds.appleconnect2.plist")
365 (literal "/Library/Preferences/com.apple.ist.ds.appleconnect2.production.plist")
366 (home-literal "/Library/Preferences/com.apple.ist.ds.appleconnect2.plist")
367 (home-literal "/Library/Preferences/com.apple.ist.ds.appleconnect2.production.plist")
368 (home-regex (string-append "/Library/Preferences/ByHost/com\.apple\.ist\.ds\.appleconnect2\." (uuid-regex-string) "\.plist$"))
369 (home-regex (string-append "/Library/Preferences/ByHost/com\.apple\.ist\.ds\.appleconnect2\.production\." (uuid-regex-string) "\.plist$"))
372 (allow ipc-posix-shm-read* ipc-posix-shm-write-create ipc-posix-shm-write-data
373 (ipc-posix-name "com.apple.AppleDatabaseChanged"))
376 (allow network-outbound
377 ;; Local mDNSResponder for DNS, arbitrary outbound TCP
378 (literal "/private/var/run/mDNSResponder")
383 (global-name "com.apple.system.logger")))
385 ;; FIXME should be removed when <rdar://problem/9347205> + related radar in Safari is fixed
387 (global-name "org.h5l.kcm")
388 (global-name "com.apple.GSSCred")
389 (global-name "com.apple.ist.ds.appleconnect.service.kdctunnel")) ;; Remove after <rdar://problem/35542803> ships
390 (allow network-outbound
392 (shared-preferences-read
397 (literal "/private/etc/services")
398 (literal "/private/etc/hosts")
399 (subpath "/Library/KerberosPlugins/GSSAPI")
400 (subpath "/Library/KerberosPlugins/KerberosFrameworkPlugins"))
402 (deny file-write-create (vnode-type SYMLINK))
404 ;; Reserve a namespace for additional protected extended attributes.
405 (deny file-read-xattr file-write-xattr (xattr-prefix "com.apple.security.private."))
407 (deny file-read* file-write* (with no-log)
408 ;; FIXME: Should be removed after <rdar://problem/10463881> is fixed.
409 (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2")
410 (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2-journal"))
412 (macro (with-filter form)
413 (let* ((ps (cdr form))
414 (extra-filter (car ps))
418 (lambda (l filters non-filters)
420 (list filters non-filters)
425 (collect rest (cons x filters) non-filters)
426 (collect rest filters (cons x non-filters)))))))
429 (let* ((collected (collect args '() '()))
430 (filters (car collected))
431 (non-filters (cadr collected)))
433 (cons ,extra-filter non-filters)
434 (cons (require-all (apply require-any filters) ,extra-filter) non-filters)))))
439 (lambda args (apply action (apply inject-filter args))))))
440 (set! allow (wrapper orig-allow))
441 (set! deny (wrapper orig-deny))
443 (set! deny orig-deny)
444 (set! allow orig-allow))))
446 ;; FIXME should be removed when <rdar://problem/30498072> is fixed.
453 ;; For reporting progress for active downloads <rdar://problem/44405661>
455 (global-name "com.apple.ProgressReporting"))
459 (global-name "com.apple.tccd"))
461 (deny mach-lookup (with no-log)
462 (global-name "com.apple.tccd.system")
463 (global-name "com.apple.CoreServices.coreservicesd")
464 (global-name-prefix "com.apple.distributed_notifications"))
468 (global-name "com.apple.networkserviceproxy.fetch-token"))
470 (allow file-read* file-write*
471 (home-subpath "/Library/HTTPStorages"))
474 (prefix "/private/var/db/com.apple.networkextension."))
476 (when (defined? 'syscall-unix)
477 (deny syscall-unix (with telemetry))
478 (allow syscall-unix (syscall-number
479 SYS___channel_get_info
482 SYS___disable_threadsignal
485 SYS___pthread_sigmask
487 SYS___semwait_signal_nocancel
488 SYS_abort_with_payload
492 SYS_bsdthread_terminate
493 SYS_change_fdguard_np
505 SYS_fileport_makeport
541 SYS_guarded_open_dprotected_np
543 SYS_guarded_pwrite_np
548 SYS_kdebug_trace_string
549 SYS_kdebug_typefilter
560 SYS_memorystatus_control
567 SYS_necp_client_action
570 SYS_open_dprotected_np
573 SYS_os_fault_with_payload
581 SYS_psynch_cvclrprepost
593 SYS_recvfrom_nocancel
624 SYS_write_nocancel)))
626 (when (defined? 'SYS_map_with_linking_np)
627 (allow syscall-unix (syscall-number SYS_map_with_linking_np)))
629 #if HAVE(SANDBOX_MESSAGE_FILTERING)
630 (when (and (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES") (defined? 'mach-kernel-endpoint))
631 (allow mach-kernel-endpoint
632 (apply-message-filter
633 (allow mach-message-send (with telemetry)))))
635 (when (and (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES") (defined? 'syscall-mach))
636 (deny syscall-mach (with telemetry))
639 MSC__kernelrpc_mach_port_allocate_trap
640 MSC__kernelrpc_mach_port_construct_trap
641 MSC__kernelrpc_mach_port_deallocate_trap
642 MSC__kernelrpc_mach_port_destruct_trap
643 MSC__kernelrpc_mach_port_extract_member_trap
644 MSC__kernelrpc_mach_port_guard_trap
645 MSC__kernelrpc_mach_port_insert_member_trap
646 MSC__kernelrpc_mach_port_insert_right_trap
647 MSC__kernelrpc_mach_port_mod_refs_trap
648 MSC__kernelrpc_mach_port_request_notification_trap
649 MSC__kernelrpc_mach_port_type_trap
650 MSC__kernelrpc_mach_port_unguard_trap
651 MSC__kernelrpc_mach_vm_allocate_trap
652 MSC__kernelrpc_mach_vm_deallocate_trap
653 MSC__kernelrpc_mach_vm_map_trap
654 MSC__kernelrpc_mach_vm_protect_trap
655 MSC__kernelrpc_mach_vm_purgable_control_trap
656 MSC_host_create_mach_voucher_trap
658 MSC_mach_generate_activity_id
661 MSC_mach_voucher_extract_attr_recipe_trap
666 MSC_semaphore_signal_trap
667 MSC_semaphore_timedwait_trap
668 MSC_semaphore_wait_trap
670 MSC_syscall_thread_switch
671 MSC_task_dyld_process_info_notify_get
673 MSC_thread_get_special_reply_port
674 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 120000
679 (when (defined? 'MSC_mach_msg2_trap)
681 (machtrap-number MSC_mach_msg2_trap))))
682 #endif // HAVE(SANDBOX_MESSAGE_FILTERING)