My Mac App Store utility removes Mac metadata files (._* AppleDouble files and .DS_Store) from external drives formatted exFAT or FAT32. The app is sandboxed with com.apple.security.files.user-selected.read-write and com.apple.security.files.bookmarks.app-scope. The user grants access to the volume through NSOpenPanel.
Deleting a ._ file works, except when its companion file carries com.apple.quarantine (for example, a file downloaded with Safari and copied to the drive with Finder). Then:
let partner = volume + "/Nirvana.zip" // has com.apple.quarantine
let appleDouble = volume + "/._Nirvana.zip"
removexattr(partner, "com.apple.quarantine", XATTR_NOFOLLOW) // -1, errno 1 (EPERM)
unlink(appleDouble) // -1, errno 1 (EPERM)
The same unlink succeeds from Terminal (not sandboxed, without Full Disk Access). On exFAT the extended attributes live in the ._ file, so I assume the sandbox refuses because deleting it would remove the quarantine attribute.
Tried, with no change:
- Full Disk Access granted to the app.
- Adding
com.apple.security.files.user-selected.executable(verified in the built app withcodesign -d --entitlements -).
On a real drive (a music library), about 71% of the ._ files belong to quarantined files, so this is most of what users want removed.
Is there a supported way for a sandboxed app to remove these files: an entitlement, an API, or an explicit user action? If not, can you confirm it's intended behavior, so I can explain it accurately to users?
macOS 27.2, Xcode 27.2, Apple silicon. Focused sample project available (one source file). DTS case 23240704.
Is there a supported way for a sandboxed app to remove these files: an entitlement, an API, or an explicit user action?
It is possible, though the solution may not be acceptable for your situation. You were actually on the right track here:
Adding com.apple.security.files.user-selected.executable
However, the problem is that this entitlement doesn't let you remove the quarantine xattr, but instead lets you create individual files that don't have the xattr. I'm not sure if our copy APIs will work (they maybe independently preserving the xattr), but if you open a quarantined file and write it's contents back out, you'll find that the new file doesn't contain any xattrs. However, that's obviously a lot of I/O for a relatively minor task.
Note: I haven't specifically tested this on FAT, but this does work on APFS, so if it DOESN'T work, then that's a bug in it's own right.
If not, can you confirm it's intended behavior, so I can explain it accurately to users?
Basically, it's used to track which apps have touched which files. The system then uses that information to do things like:
-
Warn the user when opening an unknown app for the first time.
-
Prevent apps from create files that can later be executed.
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware