e7e93a3c3f03ad2485f43544727999bf4f90256b
[WebKit-https.git] / Source / WebKit / NetworkProcess / mac / com.apple.WebKit.NetworkProcess.sb.in
1 ; Copyright (C) 2013-2017 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 ;;; process-info* defaults to allow; deny it and then allow operations we actually need.
31 (deny process-info*)
32 (allow process-info-pidinfo)
33 (allow process-info-setcontrol (target self))
34
35 (deny sysctl*)
36 (allow sysctl-read
37     (sysctl-name
38         "hw.availcpu"
39         "hw.ncpu"
40         "hw.model"
41         "kern.memorystatus_level"
42         "vm.footprint_suspend"))
43
44 (deny iokit-get-properties)
45
46 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
47 (deny mach-lookup (xpc-service-name-prefix ""))
48 #endif
49
50 ;; Utility functions for home directory relative path filters
51 (define (home-regex home-relative-regex)
52   (regex (string-append "^" (regex-quote (param "HOME_DIR")) home-relative-regex)))
53
54 (define (home-subpath home-relative-subpath)
55     (subpath (string-append (param "HOME_DIR") home-relative-subpath)))
56
57 (define (home-literal home-relative-literal)
58     (literal (string-append (param "HOME_DIR") home-relative-literal)))
59
60 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
61 ;; CFNetwork
62 (allow file-read-data (path "/private/var/db/nsurlstoraged/dafsaData.bin"))
63 #endif
64
65 ;; Remove when <rdar://problem/29646094> is fixed.
66 (define (HEX-pattern-match-generator pattern-descriptor)
67     (letrec ((pattern-string ""))
68         (for-each  (lambda (repeat-count)
69             (if (zero? repeat-count)
70                 (set! pattern-string (string-append  pattern-string "-"))
71                 (let appender ((count repeat-count))
72                     (if (> count 0)
73                         (begin
74                             (set! pattern-string (string-append  pattern-string "[0-9A-F]"))
75                             (appender (- count 1)))))))
76             pattern-descriptor)
77         pattern-string))
78
79 ;; return a regex pattern matching string for 8-4-4-4-12 UUIDs:
80 (define (uuid-HEX-pattern-match-string)
81     (HEX-pattern-match-generator '(8 0 4 0 4 0 4 0 12)))
82
83 ;; global to hold the computed UUID matching pattern.
84 (define *uuid-pattern* "")
85
86 (define (uuid-regex-string)
87     (if (zero? (string-length *uuid-pattern*))
88         (set! *uuid-pattern* (uuid-HEX-pattern-match-string)))
89     *uuid-pattern*)
90
91 ;; Read-only preferences and data
92 (allow user-preference-read
93     (preference-domain
94         "kCFPreferencesAnyApplication"
95         "com.apple.DownloadAssessment"
96         "com.apple.WebFoundation"
97         "com.apple.networkConnect"))
98 (allow file-read*
99     ;; Basic system paths
100     (subpath "/Library/Frameworks")
101     (subpath "/Library/Managed Preferences")
102
103     (literal "/Library/Application Support/CrashReporter/SubmitDiagInfo.domains")
104
105     ;; System and user preferences
106     (regex #"^/Library/Managed Preferences/[^/]+/com\.apple\.networkConnect\.plist$")
107
108     ;; On-disk WebKit2 framework location, to account for debug installations
109     ;; outside of /System/Library/Frameworks
110     (subpath (param "WEBKIT2_FRAMEWORK_DIR")))
111 (allow system-fsctl (fsctl-command (_IO "h" 47)))
112
113 (allow file-read-data
114     (literal "/usr/local/lib/log") ; <rdar://problem/36629495>
115 )
116
117 ;; Sandbox extensions
118 (define (apply-read-and-issue-extension op path-filter)
119     (op file-read* path-filter)
120     (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") path-filter)))
121 (define (apply-write-and-issue-extension op path-filter)
122     (op file-write* path-filter)
123     (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read-write") path-filter)))
124 (define (read-only-and-issue-extensions path-filter)
125     (apply-read-and-issue-extension allow path-filter))
126 (define (read-write-and-issue-extensions path-filter)
127     (apply-read-and-issue-extension allow path-filter)
128     (apply-write-and-issue-extension allow path-filter))
129 (read-only-and-issue-extensions (extension "com.apple.app-sandbox.read"))
130 (read-write-and-issue-extensions (extension "com.apple.app-sandbox.read-write"))
131
132 (allow file-read* file-write* (subpath (param "DARWIN_USER_CACHE_DIR")))
133
134 (allow file-read* file-write* (subpath (param "DARWIN_USER_TEMP_DIR")))
135
136 ;; IOKit user clients
137 (allow iokit-open
138     (iokit-user-client-class "RootDomainUserClient"))
139
140 ;; cookied.
141 ;; FIXME: Update for <rdar://problem/13642852>.
142 (allow ipc-posix-shm-read-data
143     (ipc-posix-name "FNetwork.defaultStorageSession")
144     (ipc-posix-name-regex #"\.PrivateBrowsing-")
145     (ipc-posix-name-regex #"^WebKit Test-"))
146
147 ;; Various services required by CFNetwork and other frameworks
148 (allow mach-lookup
149     (global-name "com.apple.FileCoordination")
150     (global-name "com.apple.PowerManagement.control")
151     (global-name "com.apple.SystemConfiguration.configd")
152 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
153     (global-name "com.apple.analyticsd")
154 #endif
155     (global-name "com.apple.cookied")
156     (global-name "com.apple.cfnetwork.AuthBrokerAgent")
157     (global-name "com.apple.cfnetwork.cfnetworkagent")
158     (global-name "com.apple.lsd.mapdb")
159     (global-name "com.apple.nesessionmanager.flow-divert-token")
160 )
161
162 ;; Security framework
163 (allow mach-lookup
164 #if !HAVE(SEC_KEY_PROXY)
165        (global-name "com.apple.ctkd.token-client")
166        (global-name "com.apple.securityd.xpc") 
167        (global-name "com.apple.CoreAuthentication.agent.libxpc")
168 #endif
169        (global-name "com.apple.ocspd")
170        (global-name "com.apple.SecurityServer"))
171
172 #if !HAVE(SEC_KEY_PROXY)
173 ;; FIXME: This should be removed when <rdar://problem/10479685> is fixed.
174 ;; Restrict AppSandboxed processes from creating /Library/Keychains, but allow access to the contents of /Library/Keychains:
175 (allow file-read-data file-read-metadata file-write*
176     (subpath "/Library/Keychains")
177     (home-subpath "/Library/Keychains"))
178
179 ;; Except deny access to new-style iOS Keychain folders which are UUIDs.
180 (deny file-read* file-write*
181     (regex (string-append "/Library/Keychains/" (uuid-regex-string) "(/|$)"))
182     (home-regex (string-append "/Library/Keychains/" (uuid-regex-string) "(/|$)")))
183 #endif
184
185 (allow file-read* file-write* (subpath "/private/var/db/mds/system")) ;; FIXME: This should be removed when <rdar://problem/9538414> is fixed.
186
187 (allow user-preference-read
188     (preference-domain
189         "com.apple.crypto"
190         "com.apple.security"
191         "com.apple.security.common"
192         "com.apple.security.revocation"))
193
194 (allow file-read*
195        (subpath "/private/var/db/mds")
196        (literal "/private/var/db/DetachedSignatures"))
197
198 (allow ipc-posix-shm-read* ipc-posix-shm-write-data
199        (ipc-posix-name "com.apple.AppleDatabaseChanged"))
200
201 (system-network)
202 (allow network-outbound
203     ;; Local mDNSResponder for DNS, arbitrary outbound TCP
204     (literal "/private/var/run/mDNSResponder")
205     (remote tcp))
206
207 ;; FIXME should be removed when <rdar://problem/9347205> + related radar in Safari is fixed
208 (allow mach-lookup
209     (global-name "org.h5l.kcm")
210     (global-name "com.apple.GSSCred")
211     (global-name "com.apple.system.logger")
212     (global-name "com.apple.system.notification_center"))
213 (allow network-outbound
214     (remote udp))
215 (allow user-preference-read
216     (preference-domain
217         "com.apple.GSS"
218         "com.apple.Kerberos"
219         "edu.mit.Kerberos"))
220 (allow file-read*
221     (literal "/private/etc/krb5.conf")
222     (literal "/private/etc/services")
223     (literal "/private/etc/host")
224     (subpath "/Library/KerberosPlugins/GSSAPI")
225     (subpath "/Library/KerberosPlugins/KerberosFrameworkPlugins"))
226
227 (if (defined? 'vnode-type)
228     (deny file-write-create (vnode-type SYMLINK)))
229
230 ;; Reserve a namespace for additional protected extended attributes.
231 (deny file-read-xattr file-write-xattr (xattr-regex #"^com\.apple\.security\.private\."))
232
233 (deny file-read* file-write* (with no-log)
234     ;; FIXME: Should be removed after <rdar://problem/10463881> is fixed.
235     (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2")
236     (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2-journal"))
237
238 (macro (with-filter form)
239    (let* ((ps (cdr form))
240           (extra-filter (car ps))
241           (rules (cdr ps)))
242     `(letrec
243         ((collect
244              (lambda (l filters non-filters)
245                  (if (null? l)
246                      (list filters non-filters)
247                      (let* 
248                          ((x (car l))
249                           (rest (cdr l)))
250                          (if (sbpl-filter? x)
251                              (collect rest (cons x filters) non-filters)
252                              (collect rest filters (cons x non-filters)))))))
253          (inject-filter
254              (lambda args
255                  (let* ((collected (collect args '() '()))
256                         (filters (car collected))
257                         (non-filters (cadr collected)))
258                  (if (null? filters)
259                      (cons ,extra-filter non-filters)
260                      (cons (require-all (apply require-any filters) ,extra-filter) non-filters)))))
261          (orig-allow allow)
262          (orig-deny deny)
263          (wrapper
264              (lambda (action)
265                  (lambda args (apply action (apply inject-filter args))))))
266         (set! allow (wrapper orig-allow))
267         (set! deny (wrapper orig-deny))
268         ,@rules
269         (set! deny orig-deny)
270         (set! allow orig-allow))))
271
272 ;; FIXME should be removed when <rdar://problem/30498072> is fixed.
273 (allow network*
274     (local udp)
275     (remote udp)
276     (local tcp)
277     (remote tcp))
278