Sub topic 9
Gatekeeper: the check at first launch
This chapter assumes you know what quarantine is (the previous chapter) and the basics of code signing and notarization. You should be able to run a command in Terminal.
What Gatekeeper does
Gatekeeper is the macOS component that decides whether an app may run. It acts when you open a quarantined app for the first time. It does not scan the whole disk, and it does not keep re-checking apps you already approved.
Gatekeeper combines three questions:
- Is the code signature valid, and has the app been modified since it was signed?
- Was the app signed by an identified developer, or does it come from the Mac App Store?
- Does Apple's notarization service know the app, meaning a ticket is attached or Gatekeeper can look one up online?
The first-launch flow
After the app launches once, macOS removes the quarantine flag. Later launches skip the dialog.
Policy settings
Open System Settings, then Privacy & Security, and look for the option that controls which sources are allowed. The choices are:
- App Store: only apps from the Mac App Store.
- App Store and identified developers: also apps signed with a Developer ID and notarized. This is the default.
There is no "anywhere" option in the interface. Overriding a block for a single app is covered in the chapter on blocked apps.
Asking Gatekeeper directly
You can query the policy without launching anything:
spctl --assess --type execute --verbose=4 /Applications/Example.appAn approved app prints accepted and a source= line, such as source=Notarized Developer ID or source=Mac App Store. A rejected app prints rejected and, usually, a reason. The command returns exit status 0 on acceptance, so you can use it in scripts.
Common errors and gotchas
- "Apple could not verify ... is free of malware": the app is signed but not notarized, or Apple's check could not complete. Treat this as a prompt to vet the source again.
- "... is damaged and can't be opened": this often means the signature no longer matches the contents. The cause may be a corrupted or tampered download. Compare the checksum before trying again.
- App Translocation: if you run a quarantined app straight from the disk image or the Downloads folder, macOS may run it from a randomized read-only location. The app can then fail to find its own resources. Drag it to Applications first, then open it.
- Files without quarantine: tools like
curldo not add the quarantine attribute. Gatekeeper's first-launch prompt will not appear, so nothing checks the file for you. Verify those downloads manually. - A passed check is not a safety guarantee: notarization is an automated scan. A malicious developer can still be notarized, so the source still matters.
Exercise
You download a tool with curl, unpack it, and it runs without any Gatekeeper dialog. Why, and what should you do?
Show answer
curl does not set the com.apple.quarantine attribute, so Gatekeeper's first-launch check never triggers. Verify the file yourself with a checksum, codesign --verify, and spctl --assess before running it.