[Mac][WK2] Stop using file* rules in WebProcess sandbox profiles
[WebKit-https.git] / Source / WebKit2 / DatabaseProcess / mac / com.apple.WebKit.Databases.sb.in
1 ; Copyright (C) 2014-2016 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-write-directory-and-issue-read-write-extensions path)
41     (if path
42         (begin
43             (allow file-read* file-write* (subpath path))
44             (allow file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") (subpath path)))
45             (allow file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read-write") (subpath path))))))
46
47 ;; IOKit user clients
48 (allow iokit-open
49     (iokit-user-client-class "RootDomainUserClient"))
50
51 ;; Security framework
52 (allow mach-lookup
53        (global-name "com.apple.SecurityServer"))
54 (allow user-preference-read
55     (preference-domain
56         "com.apple.security"
57         "com.apple.security.revocation"))
58 (allow file-read*
59        (subpath "/private/var/db/mds")
60        (literal "/private/var/db/DetachedSignatures")
61        ; The following are needed until <rdar://problem/11134688> is resolved.
62        (literal "/Library/Preferences/com.apple.security.plist")
63        (literal "/Library/Preferences/com.apple.security.revocation.plist")
64        (home-literal "/Library/Preferences/com.apple.security.plist")
65        (home-literal "/Library/Preferences/com.apple.security.revocation.plist"))
66 (allow ipc-posix-shm-read* ipc-posix-shm-write-data
67        (ipc-posix-name "com.apple.AppleDatabaseChanged"))
68 (if (positive? (string-length (param "DARWIN_USER_CACHE_DIR")))
69     (allow-read-write-directory-and-issue-read-write-extensions (param "DARWIN_USER_CACHE_DIR")))
70 (if (positive? (string-length (param "DARWIN_USER_TEMP_DIR")))
71     (allow-read-write-directory-and-issue-read-write-extensions (param "DARWIN_USER_TEMP_DIR")))
72
73 ;; Read-only preferences and data
74 (allow user-preference-read
75     (preference-domain
76         "kCFPreferencesAnyApplication"))
77 (allow file-read*
78     ;; Basic system paths
79     (subpath "/Library/Frameworks")
80     (subpath "/Library/Managed Preferences")
81
82     ;; On-disk WebKit2 framework location, to account for debug installations
83     ;; outside of /System/Library/Frameworks
84     (subpath (param "WEBKIT2_FRAMEWORK_DIR")))
85 (allow system-fsctl (fsctl-command (_IO "h" 47)))
86
87 ;; Sandbox extensions
88 (define (apply-read-and-issue-extension op path-filter)
89     (op file-read* path-filter)
90     (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") path-filter)))
91 (define (apply-write-and-issue-extension op path-filter)
92     (op file-write* path-filter)
93     (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read-write") path-filter)))
94 (define (read-only-and-issue-extensions path-filter)
95     (apply-read-and-issue-extension allow path-filter))
96 (define (read-write-and-issue-extensions path-filter)
97     (apply-read-and-issue-extension allow path-filter)
98     (apply-write-and-issue-extension allow path-filter))
99 (read-only-and-issue-extensions (extension "com.apple.app-sandbox.read"))
100 (read-write-and-issue-extensions (extension "com.apple.app-sandbox.read-write"))
101
102 (if (defined? 'vnode-type)
103     (deny file-write-create (vnode-type SYMLINK)))
104
105 ;; Reserve a namespace for additional protected extended attributes.
106 (deny file-read-xattr file-write-xattr (xattr-regex #"^com\.apple\.security\.private\."))