Sandboxed app can't delete AppleDouble (._) files of quarantined files on exFAT, even with user-selected access.

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 with codesign -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.

Answered by DTS Engineer in 916312022

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

Accepted Answer

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

Thank you, Kevin, that’s very helpful. I’ll test the read-and-rewrite approach on exFAT with com.apple.security.files.user-selected.executable and report back here, including whether the AppleDouble file disappears when the original is replaced. Understood about the purpose of the quarantine attribute; I’ll keep it on anything executable regardless.

Thanks again, Kevin. Your suggestion works on exFAT, with one extra step. With com.apple.security.files.user-selected.executable, a plain read/write copy renamed over the original has no quarantine and no attributes. Shortly afterwards, kMDItemDownloadedDate and kMDItemWhereFroms reappeared on the new file (not the quarantine), which recreated the AppleDouble file. Since the file is no longer quarantined, the sandboxed app could then delete the ._ file, and it stayed gone. Do you know what re-applies those two metadata attributes, and whether that’s expected?

Understood about the purpose of the quarantine attribute; I’ll keep it on anything executable regardless.

As a side comment, I don't actually think its inherently "wrong" for an app to strip quarantine, even for executables and other "dangerous" files. What really matter here is that the app is clear about what it's doing and that directly aligns with the users overall intent. As a trivial example, I think it's totally reasonable for a tool that used to prepare data for broader or cross platform distribution to strip this kind of data. It does have a totally legitimate role, but that doesn't mean it's worth leaving in place to confuse my Smart (but fairly dumb) Picture Frame.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Thanks, Kevin, that’s a helpful way to frame it. Our use case is exactly that: preparing external drives for TVs, consoles and other non-Mac devices, so we’ll make the feature opt-in and explain clearly what it removes. If you have any insight into what re-applies kMDItemDownloadedDate and kMDItemWhereFroms after the rewrite, I’d be glad to hear it, but no worries if not.