Skip to content

Commit

Permalink
Add webpushd iOS sandbox
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=249436
rdar://103410333

Reviewed by Brady Eidson.

This adds a sandbox profile for webpushd on iOS. It allows standard system operations, reading and
writing to the PushDatabase, interacting with apsd, and interacting with LaunchServices.

For now, the sandbox defaults to allowing all operations with symbolication, but we'll change the
default to deny once we're sure these rules are sufficient.

* Source/WebKit/DerivedSources-input.xcfilelist:
* Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.webpushd.sb.in: Added.
* Source/WebKit/Scripts/process-entitlements.sh:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:

Canonical link: https://commits.webkit.org/258033@main
  • Loading branch information
bnham committed Dec 17, 2022
1 parent eb4a573 commit 5ab76c7
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 3 deletions.
1 change: 1 addition & 0 deletions Source/WebKit/DerivedSources-input.xcfilelist
Expand Up @@ -129,6 +129,7 @@ $(PROJECT_DIR)/Resources/SandboxProfiles/ios/com.apple.WebKit.Networking.sb.in
$(PROJECT_DIR)/Resources/SandboxProfiles/ios/com.apple.WebKit.WebAuthn.sb.in
$(PROJECT_DIR)/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb.in
$(PROJECT_DIR)/Resources/SandboxProfiles/ios/com.apple.WebKit.adattributiond.sb.in
$(PROJECT_DIR)/Resources/SandboxProfiles/ios/com.apple.WebKit.webpushd.sb.in
$(PROJECT_DIR)/Scripts/PreferencesTemplates/WebPageUpdatePreferences.cpp.erb
$(PROJECT_DIR)/Scripts/PreferencesTemplates/WebPreferencesDefinitions.h.erb
$(PROJECT_DIR)/Scripts/PreferencesTemplates/WebPreferencesExperimentalFeatures.cpp.erb
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/DerivedSources-output.xcfilelist
Expand Up @@ -489,4 +489,5 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/com.apple.WebKit.WebContent.sb
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/com.apple.WebKit.adattributiond.sb
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/com.apple.WebKit.plugin-common.sb
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/com.apple.WebKit.webpushd.mac.sb
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/com.apple.WebKit.webpushd.sb
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/com.apple.WebProcess.sb
1 change: 1 addition & 0 deletions Source/WebKit/DerivedSources.make
Expand Up @@ -375,6 +375,7 @@ SANDBOX_PROFILES = \

SANDBOX_PROFILES_IOS = \
com.apple.WebKit.adattributiond.sb \
com.apple.WebKit.webpushd.sb \
com.apple.WebKit.GPU.sb \
com.apple.WebKit.Networking.sb \
com.apple.WebKit.WebContent.sb
Expand Down
@@ -0,0 +1,212 @@
; Copyright (C) 2021-2022 Apple Inc. All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions
; are met:
; 1. Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; 2. Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
; THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
; THE POSSIBILITY OF SUCH DAMAGE.

(version 1)
; FIXME: tighten sandbox after we get enough internal reports.
; (deny default (with partial-symbolication))
(allow (with report) default)
(allow system-audit file-read-metadata)

(import "util.sb")

(define (allow-read-write-directory-contents path)
(if path
(begin
(allow file-read* (subpath path))
(allow file-read* file-write*
(regex (string-append "^" (regex-quote path) "/")))
(allow file-write-create
file-write-data
(require-all (vnode-type DIRECTORY) (literal path))))))

(define (allow-read-directory-and-issue-read-extensions path)
(if path
(begin
(allow file-read* (subpath path))
(allow file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") (subpath path))))))

(allow file-read* file-map-executable
(subpath "/usr/lib")
(subpath "/System/Library/Frameworks")
(subpath "/System/Library/PrivateFrameworks"))

(with-filter (system-attribute apple-internal)
(allow mach-lookup
(global-name "com.apple.analyticsd")
(global-name "com.apple.diagnosticd")))

(deny sysctl* (with telemetry))
(allow sysctl-read
(sysctl-name
"hw.activecpu"
"hw.osenvironment"
"hw.target"
"hw.machine"
"hw.memsize"
"hw.ncpu"
"hw.pagesize_compat"
"kern.bootargs"
"kern.hostname"
"kern.maxfilesperproc"
"kern.osproductversion"
"kern.osrelease"
"kern.ostype"
"kern.osvariant_status"
"kern.osversion"
"kern.secure_kernel"
"kern.version"
"vm.footprint_suspend")
(sysctl-name-prefix "kern.proc.pid.")
)

(with-filter (system-attribute apple-internal)
(allow sysctl-read sysctl-write
(sysctl-name
"vm.footprint_suspend"
)
)
)

(allow-read-write-directory-contents (param "DARWIN_USER_CACHE_DIR"))
(allow-read-write-directory-contents (param "DARWIN_USER_TEMP_DIR"))

(allow-read-directory-and-issue-read-extensions (param "FRAMEWORKS_DIR"))

;; AWD
(allow mach-lookup
(global-name
"com.apple.analyticsd"
"com.apple.awdd"))

;; Note this does not allow subpaths of "/"
(allow file-read* file-test-existence
(literal "/"))

(allow file-read-data
(literal "/System/Library/CoreServices/SystemVersion.plist")
(literal "/usr/lib/log")
(literal "/usr/local/lib/log")) ; <rdar://problem/36629495>

;; Security framework
(allow mach-lookup (global-name "com.apple.SecurityServer")
(global-name "com.apple.ocspd"))
(allow file-read*
(literal "/dev/urandom")
(literal "/private/etc/master.passwd")
(subpath "/private/var/preferences/Logging")
(subpath "/Library/Keychains")
(subpath "/private/var/db/mds")
(literal "/Library/Preferences/com.apple.security.plist")
(home-literal "/Library/Preferences/com.apple.security.plist"))

;;; Allow reading internal profiles on development builds
(allow file-read*
(require-all (file-mode #o0004)
(subpath "/AppleInternal/Library/Preferences/Logging")
(system-attribute apple-internal)))

(allow file-read* (subpath "/usr/share"))

(allow file-read* (literal "/Library/Application Support/CrashReporter/SubmitDiagInfo.domains"))

(allow ipc-posix-shm-read-data
(ipc-posix-name "com.apple.AppleDatabaseChanged"))
(allow ipc-posix-shm-write-data
(ipc-posix-name "com.apple.AppleDatabaseChanged"))
(allow ipc-posix-shm-read*
(ipc-posix-name "apple.shm.notification_center")) ;; Needed by os_log_create

;; Read-only preferences and data
(allow file-read*
;; Basic system paths
(subpath "/Library/Managed Preferences")

;; System and user preferences
(literal "/Library/Preferences/.GlobalPreferences.plist")
(home-literal "/Library/Preferences/.GlobalPreferences.plist")
(home-regex #"/Library/Preferences/ByHost/\.GlobalPreferences\."))

(allow system-fsctl (fsctl-command (_IO "h" 47)))

#if ENABLE(SYSTEM_CONTENT_PATH_SANDBOX_RULES)
#include <WebKitAdditions/SystemContentSandbox-ios.defs>

(allow file-read* file-test-existence
(apply subpath file-read-existence-secondary-paths))

(allow file-map-executable
(apply subpath secondary-framework-and-dylib-paths))
#endif

;; Standard paths.
(define required-etc-files
(literal "/private/etc/hosts"
"/private/etc/passwd"
"/private/etc/services"))

(allow file-read*
required-etc-files)

;; Various services required by CFNetwork and other frameworks.
(allow mach-lookup
(global-name "com.apple.logd")
(global-name "com.apple.system.notification_center"))

;; Daemon prefs.
(allow user-preference-read user-preference-write
(preference-domain "com.apple.webkit.webpushd"))

;; Push notification registration.
(allow mach-lookup
(global-name "com.apple.apsd"))

;; Allow webpushd to launch UI processes in response to a push via LaunchServices.
(allow lsopen)

(allow mach-lookup
(global-name "com.apple.coreservices.launchservicesd")
(global-name "com.apple.coreservices.quarantine-resolver")
(global-name "com.apple.lsd.mapdb"))

(allow user-preference-read
(preference-domain
"com.apple.inputmethodkit"
"com.apple.inputsources"
"com.apple.LaunchServices"
"kCFPreferencesAnyApplication"))

;; We might need to create ~/Library/WebKit and ~/Library/WebKit/WebPush on a clean install.
(allow file-write-create
(require-all (vnode-type DIRECTORY) (home-literal "/Library/WebKit"))
(require-all (vnode-type DIRECTORY) (home-literal "/Library/WebKit/WebPush")))

;; Push database.
(allow file*
(home-literal "/Library/WebKit/WebPush/PushDatabase.db")
(home-literal "/Library/WebKit/WebPush/PushDatabase.db-shm")
(home-literal "/Library/WebKit/WebPush/PushDatabase.db-wal")
(home-literal "/Library/WebKit/WebPush/PushDatabase.db-lock")
(home-literal "/Library/WebKit/WebPush/PushDatabase.db-journal"))

;; Let SQLite open the parent directory of the database for fsync purposes.
(allow file-read-data (require-all (vnode-type DIRECTORY) (home-prefix "/Library/WebKit/WebPush")))
3 changes: 1 addition & 2 deletions Source/WebKit/Scripts/process-entitlements.sh
Expand Up @@ -430,8 +430,7 @@ function ios_family_process_adattributiond_entitlements()

function ios_family_process_webpushd_entitlements()
{
# FIXME: Add a sandbox profile for webpushd and add it to the seatbelt-profiles array.
echo "webpushd sandbox has not been implemented yet"
plistbuddy Add :com.apple.private.sandbox.profile string com.apple.WebKit.webpushd
plistbuddy Add :aps-connection-initiate bool YES
plistbuddy Add :com.apple.private.launchservices.allowopenwithanyhandler bool YES
plistbuddy Add :com.apple.springboard.opensensitiveurl bool YES
Expand Down
5 changes: 4 additions & 1 deletion Source/WebKit/WebKit.xcodeproj/project.pbxproj
Expand Up @@ -7546,6 +7546,7 @@
EBA8D3AF27A5E33F00CB7900 /* PushServiceConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PushServiceConnection.h; sourceTree = "<group>"; };
EBA8D3B027A5E33F00CB7900 /* MockPushServiceConnection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MockPushServiceConnection.mm; sourceTree = "<group>"; };
EBA8D3B127A5E33F00CB7900 /* PushServiceConnection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PushServiceConnection.mm; sourceTree = "<group>"; };
EBE0B837294BDD65004FA3BE /* com.apple.WebKit.webpushd.sb.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = com.apple.WebKit.webpushd.sb.in; sourceTree = "<group>"; };
EBE4D2AE28A2F44700C0FAE7 /* LoggingPreferences.plist */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; name = LoggingPreferences.plist; path = Resources/LoggingPreferences.plist; sourceTree = "<group>"; };
ECA680D31E6904B500731D20 /* ExtraPrivateSymbolsForTAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtraPrivateSymbolsForTAPI.h; sourceTree = "<group>"; };
ECBFC1DB1E6A4D66000300C7 /* ExtraPublicSymbolsForTAPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ExtraPublicSymbolsForTAPI.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -12092,6 +12093,7 @@
2DB96052239886B900102791 /* com.apple.WebKit.GPU.sb.in */,
A78CCDD8193AC9E3005ECC25 /* com.apple.WebKit.Networking.sb.in */,
E313664D265EE5AF0051084F /* com.apple.WebKit.WebContent.sb.in */,
EBE0B837294BDD65004FA3BE /* com.apple.WebKit.webpushd.sb.in */,
);
path = ios;
sourceTree = "<group>";
Expand Down Expand Up @@ -16846,6 +16848,7 @@
"$(SRCROOT)/Resources/SandboxProfiles/ios/com.apple.WebKit.GPU.sb",
"$(SRCROOT)/Resources/SandboxProfiles/ios/com.apple.WebKit.WebAuthn.sb",
"$(SRCROOT)/Resources/SandboxProfiles/ios/com.apple.WebKit.adattributiond.sb",
"$(SRCROOT)/Resources/SandboxProfiles/ios/com.apple.WebKit.webpushd.sb",
);
name = "Copy iOS Sandbox Profiles for Manual Sandboxing";
outputPaths = (
Expand Down Expand Up @@ -17707,7 +17710,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "echo \"Preprocessing sandbox\"\nScripts/generate-derived-sources.sh sandbox-profiles-ios\nmkdir -p ${DSTROOT}/${INSTALL_PATH}\ncp ${BUILT_PRODUCTS_DIR}/DerivedSources/WebKit/com.apple.WebKit.adattributiond.sb ${DSTROOT}/${INSTALL_PATH}\ncp ${BUILT_PRODUCTS_DIR}/DerivedSources/WebKit/com.apple.WebKit.GPU.sb ${DSTROOT}/${INSTALL_PATH}\ncp ${BUILT_PRODUCTS_DIR}/DerivedSources/WebKit/com.apple.WebKit.Networking.sb ${DSTROOT}/${INSTALL_PATH}\ncp ${BUILT_PRODUCTS_DIR}/DerivedSources/WebKit/com.apple.WebKit.WebAuthn.sb ${DSTROOT}/${INSTALL_PATH}\ncp ${BUILT_PRODUCTS_DIR}/DerivedSources/WebKit/com.apple.WebKit.WebContent.sb ${DSTROOT}/${INSTALL_PATH}\n";
shellScript = "echo \"Preprocessing sandbox\"\nScripts/generate-derived-sources.sh sandbox-profiles-ios\nmkdir -p ${DSTROOT}/${INSTALL_PATH}\ncp ${BUILT_PRODUCTS_DIR}/DerivedSources/WebKit/com.apple.WebKit.adattributiond.sb ${DSTROOT}/${INSTALL_PATH}\ncp ${BUILT_PRODUCTS_DIR}/DerivedSources/WebKit/com.apple.WebKit.webpushd.sb ${DSTROOT}/${INSTALL_PATH}\ncp ${BUILT_PRODUCTS_DIR}/DerivedSources/WebKit/com.apple.WebKit.GPU.sb ${DSTROOT}/${INSTALL_PATH}\ncp ${BUILT_PRODUCTS_DIR}/DerivedSources/WebKit/com.apple.WebKit.Networking.sb ${DSTROOT}/${INSTALL_PATH}\ncp ${BUILT_PRODUCTS_DIR}/DerivedSources/WebKit/com.apple.WebKit.WebAuthn.sb ${DSTROOT}/${INSTALL_PATH}\ncp ${BUILT_PRODUCTS_DIR}/DerivedSources/WebKit/com.apple.WebKit.WebContent.sb ${DSTROOT}/${INSTALL_PATH}\n";
};
EBE4D2AD28A2F3BD00C0FAE7 /* Copy Signpost Plists */ = {
isa = PBXShellScriptBuildPhase;
Expand Down

0 comments on commit 5ab76c7

Please sign in to comment.