Sub topic 8
How macOS marks downloaded files
This chapter assumes you can open Terminal and run a command, and that you know what an app, a disk image (.dmg) and an installer package (.pkg) are. It covers the quarantine attribute, which is the label that tells Gatekeeper a file came from outside your Mac.
What the quarantine attribute is
When a browser, mail app or chat app saves a file, it can tag the file with an extended attribute named com.apple.quarantine. An extended attribute is a small piece of metadata stored with the file, separate from its contents.
The tag does not block anything by itself. It is a flag. At first launch, Gatekeeper sees the flag and runs its checks on the app.
The flag holds a few values, separated by semicolons. These include a hex flags field, a timestamp, the name of the app that saved the file, and a unique ID.
Who applies it
The app that saves the file decides whether to apply quarantine. Safari, Chrome, Firefox, Mail and Messages normally do. Command-line tools such as curl normally do not, so a file fetched with curl carries no flag and skips the first-launch check.
Quarantine is also copied onward. If you open a quarantined .dmg, apps you drag out of it inherit the flag. If you unzip a quarantined archive, the extracted files inherit it too.
Inspecting the flag
Use xattr -l to list a file's extended attributes:
xattr -l ~/Downloads/Example.dmgA browser download usually shows output like this:
com.apple.quarantine: 0083;6745a1b2;Safari;5C1E7F20-0000-0000-0000-000000000000If the file has no extended attributes, the command prints nothing. That means the file is not quarantined. It does not mean the file is safe.
Why you should not strip the flag casually
You can remove the flag with xattr -d com.apple.quarantine. This bypasses Gatekeeper for that file. Many web tutorials suggest it to get around a "damaged" or "unidentified developer" warning.
Common errors
- Assuming no flag means safe. Files from
curl, USB drives or some network shares may carry no flag. They have not been checked. - Assuming the flag is a warning about the file. It only records where the file came from. Gatekeeper decides what happens next.
- Expecting the flag to stay forever. After a successful first launch, macOS stops running the same check on that app.
- Copying an app from a quarantined archive and expecting a clean copy. The copy is also flagged.
Exercise
You download an app with curl and run xattr -l on it. The command prints nothing. Does that tell you the app is safe, and what does it tell you about Gatekeeper?
Show answer
No, it does not show that the app is safe. It only shows that the file has no quarantine flag, because curl does not apply one. Gatekeeper's first-launch check is therefore not triggered by that flag, so you must verify the app yourself, for example with a checksum or codesign.