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