I'm using macOS sandboxing and file path bookmarks for the first time in an app.
One thing that's impeding my understanding is that my app seems to be able to open any folder path, regardless of sandboxing.
For example, I can access the file structure and file contents of the launch daemons path (which I assume would be off limits to a sandboxed app).
This is my app delegate that I've modified from a clean Swift UI / AppKit App Delegate project to showcase this.
import Cocoa
import SwiftUI
@main
class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow!
func applicationDidFinishLaunching(_ aNotification: Notification) {
let url = URL(fileURLWithPath: "/Library/LaunchDaemons")
if let enumerator = FileManager.default.enumerator(at: url, includingPropertiesForKeys: [.isRegularFileKey, .isDirectoryKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) {
for case let fileURL as URL in enumerator {
print(fileURL);
do {
let contents = try String(contentsOf: fileURL, encoding: .utf8)
print(contents)
} catch {
}
}
}
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
}
I have set "User Selected File" to none in the app's sandbox entitlements.
The file path and file contents are successfully printed to the console.
What am I missing here? Why is this app able to get access to this path?
FYI - I'm just running this in the Xcode debugger.