Sub topic 8
How macOS marks downloaded files
This chapter assumes you can open Terminal and run a command. You should also know that Gatekeeper is the check macOS runs when you first open an app. The chapter covers the quarantine attribute, which is the mark that tells Gatekeeper a file came from outside your Mac.
What the quarantine attribute is
When a quarantine-aware program saves a file from the internet, macOS attaches a small piece of metadata to it. This metadata is an extended attribute named com.apple.quarantine. An extended attribute is a name and value pair stored with a file by the file system, separate from the file's contents. Finder, Spotlight and xattr can read these attributes.
The quarantine attribute does not scan or judge the file. It records that the file arrived from somewhere untrusted and has not yet been approved. Gatekeeper reads the attribute when you open the file and decides whether to run its checks.
Who applies the mark
The program that writes the file decides whether to apply quarantine. Programs that normally do:
- Web browsers such as Safari, Chrome and Firefox.
- Mail, Messages and AirDrop, for attachments and received files.
- Other apps that opt in with the
LSFileQuarantineEnabledkey in theirInfo.plist.
Programs that usually do not:
- Command-line tools such as
curl,scpandgit. - Package managers that fetch files themselves.
- Files copied from a USB drive or a network share, where no download event happened.
This gap has practical consequences. A file fetched with curl carries no quarantine mark, so Gatekeeper's first-launch check does not apply to it. That is why instructions that tell you to pipe a download into a shell deserve extra suspicion. The operating system is not protecting you in that path.
Reading the attribute
Use xattr to list attributes. The -l flag prints each name with its value.
xattr -l ~/Downloads/Example.dmgA quarantined file shows something like this:
com.apple.quarantine: 0083;6560a1b0;Safari;8F1D6C5E-3A52-4B7A-9C0E-2D4F1A6B7C88The value has four fields separated by semicolons:
| Field | Example | Meaning |
|---|---|---|
| Flags | `0083` | Hexadecimal status bits. They record, for example, whether the user has already approved the file. |
| Timestamp | `6560a1b0` | Download time in hexadecimal Unix seconds. |
| Agent | `Safari` | The app that saved the file. |
| Event ID | `8F1D6C5E-...` | A UUID that links to a record in a download history database. |
You can decode the first fields with a short script. It splits the value and converts the hexadecimal timestamp to a readable date.
from datetime import datetime, timezone
value = "0083;6560a1b0;Safari;8F1D6C5E-3A52-4B7A-9C0E-2D4F1A6B7C88"
flags, stamp, agent, event_id = value.split(";")
downloaded = datetime.fromtimestamp(int(stamp, 16), tz=timezone.utc)
print(f"Flags: {flags}")
print(f"Saved by: {agent}")
print(f"Downloaded: {downloaded.isoformat()}")
print(f"Event ID: {event_id}")To print only the raw value, use xattr -p com.apple.quarantine <path>.
The download history database
The event ID points to a record in a SQLite database at ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2. Each record notes the agent, the time, and often the URL the file came from. In that database, timestamps use the Core Data epoch, which starts on 1 January 2001, not the Unix epoch.
You can read this history to find out where a suspicious file came from. Terminal may need Full Disk Access to open the file. The database also holds a record of your download history, so treat it as private data. Clearing it does not remove the attribute from files already downloaded.
What happens at first launch
When you open a quarantined app, Gatekeeper reads the attribute and runs its checks. These include the code signature, the notarization status and a malware scan by XProtect. If the checks pass, you see the familiar prompt that names the source and asks whether to open the app. After you approve, macOS updates the flags in the attribute so the prompt does not appear again.
The check happens when you first open the file, not at download time. A file can sit in Downloads for months and be checked only when you launch it. Later launches skip the prompt, which means a modified app can run unchecked if it still carries an approved flag. Other protections cover that case, but the quarantine prompt does not.
How the mark spreads
Quarantine is useful only if it stays with the content. Some propagation is built in:
- Opening a downloaded disk image mounts it. Apps you copy out of that image from Finder inherit the quarantine mark.
- Archive Utility copies the mark onto files it extracts from a downloaded ZIP.
- Some third-party archive tools do not copy the mark, so extracted files may arrive unmarked.
Copying a file between volumes can also change which attributes survive. A file system that does not support extended attributes, such as FAT, cannot store the mark in the usual way. If a workflow strips marks silently, a downloaded app may skip Gatekeeper's first-launch check without any visible sign.
Removing the mark
You can delete the attribute with xattr. The -d flag deletes one attribute and -r applies the change to everything inside a folder, which an app bundle needs.
xattr -dr com.apple.quarantine /Applications/Example.appCommon errors and edge cases
- The attribute is missing on a file you downloaded. The saving app may not apply quarantine, or an archive tool may have dropped it. Treat the file as unchecked and verify it yourself.
xattrprints nothing. The file has no extended attributes at all, which is normal for files you created.- The mark reappears after you remove it. Re-downloading, or copying from a still-quarantined source, applies it again.
- The app opens without a prompt but you downloaded it. It may have arrived through a path that skips quarantine, such as
curlor a package manager. This does not mean the app is safe. - Permission denied when removing the mark. Apps in
/Applicationsthat you do not own may needsudo. Check first that you meant to modify that app.
Exercise
You download a tool with curl and open it. Gatekeeper shows no quarantine prompt. Why, and what should you do before running it?
Show answer
curl does not apply the com.apple.quarantine attribute, so Gatekeeper has no mark that triggers its first-launch check. Verify the file yourself before running it. Compare its checksum with the one the developer publishes, and run codesign --verify and spctl --assess on the app.
Exercise
What do the four fields in a quarantine value like 0083;6560a1b0;Safari;8F1D6C5E-... represent, and how would you find the download date?
Show answer
They are the flags, the download timestamp in hexadecimal Unix seconds, the name of the saving app, and an event ID that links to the download history database. To get the date, convert the hexadecimal timestamp to decimal, for example with int(stamp, 16) in Python, and read it as Unix time.