Sub topic 9
Gatekeeper: the check at first launch
This chapter assumes you know the pieces from earlier chapters: code signing with a Developer ID, notarization, and the quarantine attribute. Here you will see how Gatekeeper combines them into one decision when you first open a downloaded app. You will also learn to reproduce that decision from Terminal.
What Gatekeeper is and when it runs
Gatekeeper is the macOS component that decides whether a piece of software may launch, based on where it came from and who vouches for it. It is not a scanner that looks for malware. It checks identity and integrity: who signed this, has it been altered, and has Apple notarized it.
Gatekeeper normally runs only in these situations:
- The first time you open an app that carries the
com.apple.quarantineattribute. - When a quarantined app, plug-in, or installer package is opened by another path, such as double-clicking a
.pkg. - When an app's contents change in a way that breaks its signature.
After an app passes once, macOS removes the quarantine flag and does not run the full check on every launch. Malware detection on later launches is the job of XProtect, covered in the next chapter.
The decision flow
Gatekeeper applies the policy you chose in System Settings, under Privacy & Security. The two standard options are "App Store" and "App Store and identified developers". The second is the default.
Each branch maps to a different kind of failure:
| Check | What it proves | Typical failure |
|---|---|---|
| Signature valid, contents intact | Nothing changed since signing | App was modified or a download was corrupted |
| Developer ID certificate | A known, registered developer signed it | Unsigned app, or signed with an ad-hoc identity |
| Notarization | Apple's automated scan accepted this exact build | Developer skipped notarization |
| Revocation | The certificate or build has not been withdrawn by Apple | Developer certificate revoked after abuse |
Notarization lookups and stapling
Gatekeeper learns whether an app is notarized in one of two ways. A developer can staple the notarization ticket to the app, which lets Gatekeeper accept it offline. Otherwise Gatekeeper contacts Apple's servers to look up the ticket. A notarized app with no stapled ticket therefore needs an internet connection on first launch to pass cleanly.
You can check whether a ticket is attached:
xcrun stapler validate /Applications/Example.appA successful run reports that the validate action worked. An error saying the app does not have a ticket stapled means it relies on the online lookup. That is not a security problem by itself, and many legitimate developers ship this way.
Reproducing the decision with spctl
The spctl tool asks the same policy engine that Gatekeeper uses. You can run it on an app before you ever double-click it.
spctl --assess --type execute --verbose=4 /Applications/Example.appThe result shows the verdict and the source of approval. These are the outputs you will meet most often:
acceptedwithsource=Mac App Store: the app came through App Store review.acceptedwithsource=Notarized Developer ID: signed by a registered developer and notarized by Apple.rejectedwithsource=Unnotarized Developer ID: signed, but Apple has no notarization record for it.rejectedwithsource=no usable signature: the app is unsigned or its signature is broken.
A shell exit status of 0 means accepted, and a non-zero status means rejected. That makes spctl easy to use in a script:
#!/bin/bash
# Usage: ./assess.sh /Applications/Example.app
app="$1"
if spctl --assess --type execute "$app" 2>/dev/null; then
echo "Gatekeeper would allow: $app"
else
echo "Gatekeeper would block: $app"
fiUse --type install for installer packages, since packages are assessed against a different policy than apps.
Quarantine decides whether Gatekeeper looks at all
Gatekeeper only evaluates items that carry the quarantine attribute. Browsers, Mail, Messages, AirDrop, and most other apps that download files apply it. You can see it directly:
xattr -l ~/Downloads/Example.dmgThe output includes a line like com.apple.quarantine: 0083;...;Safari;, which records the flag, a timestamp, and the app that downloaded the file. The attribute is copied onto the app inside a mounted disk image when you drag it out, which is why a fresh install triggers the check.
Files fetched with tools that do not set the flag, such as curl in Terminal, are not quarantined and are not assessed by Gatekeeper at first launch. This is a gotcha rather than a feature. A file arriving by a non-quarantining route has skipped the check you were counting on, so run codesign and spctl on it yourself.
App translocation
If you open a quarantined app directly from ~/Downloads or from a mounted disk image without moving it, macOS may run it from a randomized, read-only location. This is called app translocation (also Gatekeeper path randomization). It prevents an app from loading helper files that sit next to it in the download folder, which could be tampered with.
The visible symptom is that the app cannot find its own bundled resources or cannot update itself, and its path in the Terminal looks like /private/var/folders/.../AppTranslocation/.... The fix is to drag the app into /Applications using Finder and open it from there.
Reading Gatekeeper dialogs
The wording of the dialog tells you which check failed:
- "Apple could not verify that it is free of malware": the app is not notarized, or its notarization could not be confirmed.
- "is damaged and can't be opened": the signature no longer matches the contents. The file may be corrupted, tampered with, or an incomplete download. Delete it and download it again from the official source.
- "cannot be opened because the developer cannot be verified": no valid Developer ID signature.
- "was blocked to protect your Mac": Apple's malware data identifies the item as known bad. Do not override this one.
On current macOS versions, a blocked app is not opened through a Control-click shortcut. You attempt to open it, then go to System Settings, Privacy & Security, and choose "Open Anyway" in the Security section. This requires an administrator password and is available shortly after the failed attempt. The next chapters cover when that is reasonable.
Limits of Gatekeeper
- It trusts identity, not intent. A notarized app can still be unwanted software, because notarization is an automated scan.
- It checks at first launch. An app that changes later in a way that keeps its signature valid is not re-checked.
- It does not cover files you create or run in Terminal without quarantine.
- It is only as good as your policy setting. Allowing the App Store alone is stricter and blocks all web downloads.
Exercise
You downloaded Example.app with curl, copied it to /Applications, and it opened without any Gatekeeper dialog. Does this mean Gatekeeper approved it? Which two commands would you run to find out whether it would pass?
Show answer
No. Files fetched with curl do not get the com.apple.quarantine attribute, so Gatekeeper never assessed the app at launch. You can confirm with xattr -l /Applications/Example.app, which will show no quarantine entry. To see what Gatekeeper's policy would say, run spctl --assess --type execute --verbose=4 /Applications/Example.app, and optionally codesign --verify --deep --strict --verbose=2 /Applications/Example.app to check the signature.
Exercise
A downloaded app shows the message "is damaged and can't be opened". Which Gatekeeper check most likely failed, and what should you do?
Show answer
The signature and contents check failed: the app's contents no longer match its signature. Do not override the warning. Delete the file and download it again from the developer's official site, then compare its checksum with the published value.