com.apple.WebKit.plugin-common.sb 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. ; Copyright (C) 2013, 2014 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. (version 1)
  24. (deny default)
  25. (allow system-audit file-read-metadata)
  26. (import "system.sb")
  27. ;; Utility functions
  28. (define (home-literal home-relative-literal)
  29. (literal (string-append (param "HOME_DIR") home-relative-literal)))
  30. (define (home-library-regex home-library-relative-regex)
  31. (regex (string-append "^" (regex-quote (param "HOME_LIBRARY_DIR")) home-library-relative-regex)))
  32. (define (home-library-subpath home-library-relative-subpath)
  33. (subpath (string-append (param "HOME_LIBRARY_DIR") home-library-relative-subpath)))
  34. (define (home-library-literal home-library-relative-literal)
  35. (literal (string-append (param "HOME_LIBRARY_DIR") home-library-relative-literal)))
  36. (define (home-library-preferences-regex home-library-preferences-relative-regex)
  37. (regex (string-append "^" (regex-quote (param "HOME_LIBRARY_PREFERENCES_DIR")) home-library-preferences-relative-regex)))
  38. (define (home-library-preferences-subpath home-library-preferences-relative-subpath)
  39. (subpath (string-append (param "HOME_LIBRARY_PREFERENCES_DIR") home-library-preferences-relative-subpath)))
  40. (define (home-library-preferences-literal home-library-preferences-relative-literal)
  41. (literal (string-append (param "HOME_LIBRARY_PREFERENCES_DIR") home-library-preferences-relative-literal)))
  42. (define (shared-preferences-read . domains)
  43. (for-each (lambda (domain)
  44. (begin
  45. (if (defined? `user-preference-read)
  46. (allow user-preference-read (preference-domain domain)))
  47. ; (Temporary) backward compatibility with non-CFPreferences readers.
  48. (allow file-read*
  49. (literal (string-append "/Library/Preferences/" domain ".plist"))
  50. (home-library-preferences-literal (string-append "/" domain ".plist"))
  51. (home-library-preferences-regex (string-append #"/ByHost/" (regex-quote domain) #"\..*\.plist$")))))
  52. domains))
  53. (define (shared-preferences-read-write . domains)
  54. (for-each (lambda (domain)
  55. (begin
  56. (if (defined? `user-preference-write)
  57. (allow user-preference-read user-preference-write (preference-domain domain)))
  58. ; (Temporary) backward compatibility with non-CFPreferences readers / writers.
  59. (allow file-read* file-write*
  60. (literal (string-append "/Library/Preferences/" domain ".plist"))
  61. (home-library-preferences-literal (string-append "/" domain ".plist"))
  62. (home-library-preferences-regex (string-append #"/ByHost/" (regex-quote domain) #"\..*\.plist$")))))
  63. domains))
  64. ;; WebKit2 sandbox launcher needs to define an _OS_VERSION parameter
  65. ;; This parameter is the major OS Version number.
  66. (if (not (defined? 'os-version))
  67. (define os-version (param "_OS_VERSION")))
  68. ;; OS X 10.7 (Lion) compatibility
  69. (if (not (defined? 'ipc-posix-shm*))
  70. (define ipc-posix-shm* ipc-posix-shm))
  71. (if (not (defined? 'ipc-posix-shm-read*))
  72. (define ipc-posix-shm-read* ipc-posix-shm))
  73. (if (not (defined? 'ipc-posix-shm-write-data))
  74. (define ipc-posix-shm-write-data ipc-posix-shm))
  75. ;; Graphics
  76. (if (defined? 'system-graphics)
  77. (system-graphics)
  78. (begin
  79. (shared-preferences-read
  80. "com.apple.opengl"
  81. "com.nvidia.OpenGL")
  82. (allow mach-lookup (global-name "com.apple.cvmsServ"))
  83. (allow iokit-open
  84. (iokit-connection "IOAccelerator")
  85. (iokit-user-client-class "IOAccelerationUserClient")
  86. (iokit-user-client-class "IOSurfaceRootUserClient")
  87. (iokit-user-client-class "IOSurfaceSendRight")
  88. (iokit-user-client-class "IOFramebufferSharedUserClient")
  89. (iokit-user-client-class "AppleSNBFBUserClient")
  90. (iokit-user-client-class "AGPMClient")
  91. (iokit-user-client-class "AppleGraphicsControlClient")
  92. (iokit-user-client-class "AppleGraphicsPolicyClient"))))
  93. ;; Read-only preferences
  94. (shared-preferences-read
  95. ".GlobalPreferences"
  96. "com.apple.Bluetooth"
  97. "com.apple.CoreGraphics"
  98. "com.apple.QuickTime"
  99. "com.apple.HIToolbox"
  100. "com.apple.ATS"
  101. "com.apple.driver.AppleBluetoothMultitouch.mouse"
  102. "com.apple.driver.AppleBluetoothMultitouch.trackpad"
  103. "com.apple.driver.AppleHIDMouse"
  104. "com.apple.inputmethodkit"
  105. "com.apple.iWork.Pages"
  106. "com.apple.LaunchServices"
  107. "com.apple.MultitouchSupport"
  108. "com.apple.security"
  109. "com.apple.security.revocation"
  110. "com.apple.security_common"
  111. "com.apple.speech.voice.prefs"
  112. "com.apple.speech.synthesis.general.prefs"
  113. "com.apple.speech.recognition.AppleSpeechRecognition.prefs"
  114. "com.apple.systemsound"
  115. "com.apple.universalaccess"
  116. "com.apple.WebFoundation"
  117. "com.apple.WebKit.PluginProcess"
  118. "pbs"
  119. "com.apple.ServicesMenu.Services")
  120. ;; Read-only data
  121. (allow file-read*
  122. (literal "/")
  123. (literal "/private/etc/hosts")
  124. (literal "/private/etc/protocols")
  125. (literal "/private/etc/services")
  126. (literal "/private/etc/resolv.conf")
  127. (literal "/private/var/run/resolv.conf")
  128. (subpath "/Library/Frameworks")
  129. (subpath "/private/var/db/mds")
  130. (regex #"^/Library/Preferences/com\.apple\.security")
  131. (home-literal "/.CFUserTextEncoding")
  132. (home-library-subpath "/Audio")
  133. (home-library-subpath "/ColorPickers")
  134. (home-library-subpath "/ColorSync")
  135. (subpath "/Library/Components")
  136. (home-library-subpath "/Components")
  137. (subpath "/Library/Contextual Menu Items")
  138. (subpath "/Library/Input Methods")
  139. (home-library-subpath "/Input Methods")
  140. (subpath "/Library/InputManagers")
  141. (home-library-subpath "/InputManagers")
  142. (home-library-subpath "/KeyBindings")
  143. (subpath "/Library/Keyboard Layouts")
  144. (home-library-subpath "/Keyboard Layouts")
  145. (subpath "/Library/Fonts")
  146. (home-library-subpath "/Fonts")
  147. (subpath "/Library/Spelling")
  148. (home-library-subpath "/Spelling")
  149. (subpath "/Library/PDF Services")
  150. (home-library-subpath "/PDF Services")
  151. (home-library-preferences-literal "/QuickTime Preferences")
  152. (home-library-literal "/Caches/com.apple.coreaudio.components.plist")
  153. (subpath "/Library/Audio/Sounds")
  154. (subpath "/Library/Audio/Plug-Ins/Components")
  155. (home-library-subpath "/Audio/Plug-Ins/Components")
  156. (subpath "/Library/Audio/Plug-Ins/HAL")
  157. (subpath "/Library/CoreMediaIO/Plug-Ins/DAL")
  158. (subpath "/Library/QuickTime")
  159. (home-library-subpath "/QuickTime")
  160. (subpath "/Library/Video/Plug-Ins")
  161. (home-library-subpath "/Caches/QuickTime")
  162. (literal "/Library/Application Support/CrashReporter/SubmitDiagInfo.domains")
  163. (home-library-literal "/Application Support/SyncServices/Local/ClientsWithChanges/com.apple.Keychain")
  164. (subpath "/Library/ColorSync")
  165. ;; FIXME: This should be removed when <rdar://problem/10479685> is fixed.
  166. (subpath "/Library/Keychains"))
  167. ;; Security framework
  168. (allow mach-lookup (global-name "com.apple.ocspd"))
  169. (allow file-read* file-write* (home-library-subpath "/Keychains"))
  170. (allow file-read*
  171. (subpath "/private/var/db/mds")
  172. (literal "/private/var/db/DetachedSignatures"))
  173. (allow ipc-posix-shm-read* ipc-posix-shm-write-data
  174. (ipc-posix-name "com.apple.AppleDatabaseChanged"))
  175. ;; Read-write preferences and data
  176. (allow file*
  177. ;; FIXME: This should be removed when <rdar://problem/10479685> is fixed.
  178. (home-library-subpath "/Keychains"))
  179. ;; IOKit user clients
  180. (allow iokit-open
  181. (iokit-user-client-class "IOAudioControlUserClient")
  182. (iokit-user-client-class "IOAudioEngineUserClient")
  183. (iokit-user-client-class "IOHIDParamUserClient")
  184. (iokit-user-client-class "RootDomainUserClient"))
  185. ;; Various services required by AppKit and other frameworks
  186. (allow mach-lookup
  187. (global-name "com.apple.CoreServices.coreservicesd")
  188. (global-name "com.apple.DiskArbitration.diskarbitrationd")
  189. (global-name "com.apple.FileCoordination")
  190. (global-name "com.apple.FontObjectsServer")
  191. (global-name "com.apple.FontServer")
  192. (global-name "com.apple.ImageCaptureExtension2.presence")
  193. (global-name "com.apple.PowerManagement.control")
  194. (global-name "com.apple.SecurityServer")
  195. (global-name "com.apple.SystemConfiguration.PPPController")
  196. (global-name "com.apple.SystemConfiguration.configd")
  197. (global-name "com.apple.UNCUserNotification")
  198. (global-name "com.apple.audio.VDCAssistant")
  199. (global-name "com.apple.audio.audiohald")
  200. (global-name "com.apple.audio.coreaudiod")
  201. (global-name "com.apple.cfnetwork.AuthBrokerAgent")
  202. (global-name "com.apple.cmio.VDCAssistant")
  203. (global-name "com.apple.cookied") ;; FIXME: <rdar://problem/10790768> Limit access to cookies.
  204. (global-name "com.apple.coreservices.launchservicesd")
  205. (global-name "com.apple.ocspd")
  206. (global-name "com.apple.pasteboard.1")
  207. (global-name "com.apple.pbs.fetch_services")
  208. (global-name "com.apple.tccd.system")
  209. (global-name "com.apple.tsm.uiserver")
  210. (global-name "com.apple.window_proxies")
  211. (global-name "com.apple.windowserver.active")
  212. (local-name "com.apple.tsm.portname")
  213. (global-name-regex #"_OpenStep$"))
  214. (if (equal? os-version "10.7")
  215. (allow mach-lookup
  216. (global-name "com.apple.system.DirectoryService.membership_v1")))
  217. ;; Configuration directories
  218. (allow file-read* (subpath (param "PLUGIN_PATH")))
  219. (allow file-read* (subpath (param "WEBKIT2_FRAMEWORK_DIR")))
  220. (allow file* (subpath (param "DARWIN_USER_TEMP_DIR")))
  221. (allow file* (subpath (param "DARWIN_USER_CACHE_DIR")))
  222. (allow file* (subpath (param "NSURL_CACHE_DIR")))
  223. ;; Networking
  224. (if (defined? 'system-network)
  225. (system-network)
  226. (begin
  227. (allow file-read* (literal "/Library/Preferences/com.apple.networkd.plist"))
  228. (allow mach-lookup
  229. (global-name "com.apple.SystemConfiguration.SCNetworkReachability")
  230. (global-name "com.apple.networkd"))
  231. (allow network-outbound
  232. (control-name "com.apple.netsrc")
  233. (control-name "com.apple.network.statistics"))
  234. (allow system-socket
  235. (require-all (socket-domain AF_SYSTEM)
  236. (socket-protocol 2)) ; SYSPROTO_CONTROL
  237. (socket-domain AF_ROUTE))))
  238. (allow network-outbound
  239. ;; Local mDNSResponder for DNS, arbitrary outbound TCP and UDP
  240. (literal "/private/var/run/mDNSResponder")
  241. (remote tcp)
  242. (remote udp))
  243. (allow network-inbound
  244. (local udp))
  245. ;; Open and Save panels
  246. (define (webkit-powerbox)
  247. (allow file-read* file-write* (extension "com.apple.app-sandbox.read-write"))
  248. (allow file-issue-extension
  249. (require-all
  250. (extension-class "com.apple.app-sandbox.read")
  251. (extension "com.apple.app-sandbox.read-write"))
  252. (require-all
  253. (extension-class "com.apple.app-sandbox.read-write")
  254. (extension "com.apple.app-sandbox.read-write"))))
  255. ;; Printing
  256. (define (webkit-printing)
  257. (if (defined? 'authorization-right-obtain)
  258. (allow authorization-right-obtain
  259. (right-name "system.print.operator")
  260. (right-name "system.printingmanager")))
  261. (if (defined? 'mach-register)
  262. (deny mach-register (with no-log)
  263. (global-name-regex #"^com\.apple\.ICA-[0-9]+$")))
  264. (if (defined? 'mach-task-name)
  265. (allow mach-task-name))
  266. (allow network-outbound (literal "/private/var/run/cupsd"))
  267. (allow mach-lookup
  268. (global-name "com.apple.printuitool.agent")
  269. (global-name "com.apple.printtool.agent")
  270. (global-name "com.apple.printtool.daemon"))
  271. (allow file-read*
  272. (subpath "/Library/Printers")
  273. (home-literal "/.cups/lpoptions")
  274. (home-literal "/.cups/client.conf")
  275. (literal "/private/etc/cups/client.conf")
  276. (literal "/private/etc/cups/lpoptions")
  277. (subpath "/private/etc/cups/ppd")
  278. (subpath "/private/var/run/cupsd"))
  279. (shared-preferences-read "org.cups.PrintingPrefs"))
  280. ;; Text Services Manager
  281. (allow iokit-set-properties (iokit-property "CapsLockDelayOverride"))
  282. ;; Image Capture
  283. (define (webkit-imagecapture)
  284. (allow appleevent-send (appleevent-destination "com.apple.imagecaptureextension2")))
  285. ;; Camera
  286. (define (webkit-camera)
  287. (allow mach-lookup (extension "com.apple.app-sandbox.mach"))
  288. (allow mach-lookup
  289. (global-name "com.apple.cmio.AppleCameraAssistant")
  290. ;; Apple DAL assistants
  291. (global-name "com.apple.cmio.VDCAssistant")
  292. (global-name "com.apple.cmio.AVCAssistant")
  293. (global-name "com.apple.cmio.IIDCVideoAssistant")
  294. ;; QuickTimeIIDCDigitizer assistant
  295. (global-name "com.apple.IIDCAssistant"))
  296. (allow iokit-open
  297. ;; QuickTimeUSBVDCDigitizer
  298. (iokit-user-client-class "IOUSBDeviceUserClientV2")
  299. (iokit-user-client-class "IOUSBInterfaceUserClientV2"))
  300. (allow device-camera))
  301. ;; Microphone
  302. (define (webkit-microphone)
  303. (allow device-microphone))
  304. (if (equal? os-version "10.7")
  305. (allow ipc-posix-shm)
  306. (begin
  307. (if (equal? os-version "10.8")
  308. (allow ipc-posix-shm*
  309. (ipc-posix-name "_CS_GSHMEMLOCK")
  310. (ipc-posix-name "_CS_DSHMEMLOCK")))
  311. (allow ipc-posix-shm*
  312. (ipc-posix-name-regex #"^AudioIO")
  313. (ipc-posix-name-regex #"^CFPBS:")
  314. (ipc-posix-name "com.apple.ColorSync.Gen.lock")
  315. (ipc-posix-name "com.apple.ColorSync.Disp.lock")
  316. (ipc-posix-name "com.apple.ColorSync.Gray2.2")
  317. (ipc-posix-name "com.apple.ColorSync.sRGB")
  318. (ipc-posix-name "com.apple.ColorSync.GenGray")
  319. (ipc-posix-name "com.apple.ColorSync.GenRGB")
  320. (ipc-posix-name-regex #"^com\.apple\.cs\.")
  321. (ipc-posix-name-regex #"^ls\."))
  322. (allow ipc-posix-shm-read*
  323. (ipc-posix-name-regex #"^/tmp/com\.apple\.csseed\.")
  324. (ipc-posix-name "FNetwork.defaultStorageSession")
  325. (ipc-posix-name "apple.shm.notification_center"))))
  326. ;; Silently block access to some resources
  327. (deny file-read* file-write* (with no-log)
  328. (subpath "/Network/Library")
  329. (subpath "/Network/Applications")
  330. (home-library-preferences-regex #"/com\.apple\.internetconfig(priv)?\.plist")
  331. ;; FIXME: Should be removed after <rdar://problem/9422957> is fixed.
  332. (home-library-literal "/Caches/Cache.db")
  333. ;; FIXME: Should be removed after <rdar://problem/10463881> is fixed.
  334. (home-library-preferences-literal "/com.apple.LaunchServices.QuarantineEventsV2")
  335. (home-library-preferences-literal "/com.apple.LaunchServices.QuarantineEventsV2-journal"))
  336. (deny mach-lookup (with no-log)
  337. (global-name "com.apple.FSEvents")
  338. (global-name "com.apple.coreservices.appleevents")
  339. (global-name "com.apple.dock.server")
  340. (global-name-regex #"^com\.apple\.distributed_notifications"))
  341. ;; The below rules are inserted at the end of sandbox profile compilation by overriding the finalizer.
  342. ;; The initial value of %finalize must be the last function called.
  343. (letrec
  344. ((original-%finalize %finalize)
  345. (webkit-%finalize
  346. (lambda ()
  347. (if (defined? 'vnode-type)
  348. (deny file-write-create
  349. (vnode-type SYMLINK)))
  350. ;; Reserve a namespace for additional protected extended attributes.
  351. (deny file-read-xattr file-write-xattr (xattr #"^com\.apple\.security\.private\."))
  352. ;; FIXME: Should be removed once <rdar://problem/16329087> is fixed.
  353. (deny file-write-xattr (xattr "com.apple.quarantine") (with no-log))
  354. (original-%finalize))))
  355. (set! %finalize webkit-%finalize))