Applying sandbox-exec around Safari with a single click
Isolating it
To a certain degree it makes sense to allow the web-browser accessing all readable files on the system. But JUST to a certain degree. Todays threats evolve to target web-browsers' interactive functions. Safari has vulnerabilities.
In any case the following restriction-set is just an experiment. sandbox-exec is an Apple utility that isolates certain services and applications since MacOS Leopard. Maybe it won't be there tomorrow. It's not officially documented and developers aren't encouraged to use sandbox.h jet, as far as I know. Nevertheless the Google NativeClient project is going to use it as the "Outer Sandbox" as far as I'm concerned.
The Launcher
Create the following Apple-Script:
do shell script "sandbox-exec -f /Users/wishi/policies/sandbox-safari.sb /Applications/Safari.app/Contents/MacOS/Safari"
Change the pathname after the -f parameter. I guess your Safari, if you aren't using version 4 in the developer preview, is in /Applications. If you're using the version 4 preview: I just tested it with 3.2.1. Latter works fine.
The .sb policy
You can find similar policy files at several places. I didn't create this entirely. - just stole here and there ;).
(version 1)
(debug deny) ; Use (debug all) to see every action)
(allow network-outbound)
(allow signal)
(allow ipc-posix-shm) ; Needed for POSIX shared memory
;(allow process-exec (regex #"^/Applications/Safari.app/*"))
(allow sysctl-read)
(allow file-read-metadata)
(allow signal)
(allow process*)
;(allow mach*)
(allow mach-lookup)
;(allow process-exec (regex "^/System/Library/CoreServices/*"))
;; Allow to read these files:
(allow file-read*
(regex
#"^/Users/wishi/$"
#"^/Users/wishi/Downloads"
#"^/Users/wishi/Library"
#"^/Users/wishi/Public"
#"^/Users/wishi/Sites"
#"^/Applications/Safari.app"
#"^/Library/*"
#"^/System/Library/*"
#"^/usr/lib/*"
#"^/usr/share/*"
#"^/private/*"
#"^/dev/*"
)
)
;; Allow to write these files:
(allow file-write*
(regex
#"^/Users/wishi/Downloads/*"
#"^/Volumes/foo/bar/*"
#"^/Users/wishi/Library/.*"
#"^/private/var/*"
#"^/dev/dtracehelper"
)
)
(deny default)
Change the path stuff according to your system setup. Your username isn't wishi. So your Home-directory differs.
Save this file in ~/policies for example. Now save the Apple-Script as a .app-program with the Scripteditor.app. Move the program to /Applications, drag it into the Dock. Ready!
Have fun,
wishi

Post new comment