Skip to main content
3Nsofts logo3Nsofts
Security & Compliance

Notarize and Staple a Mac App for Offline First Launch

A Developer ID release workflow covering nested signing, Hardened Runtime, app and DMG stapling, Gatekeeper checks and a clean offline Mac test.

By Ehsan Azish · 3NSOFTS··6 min read

A release can pass notarization and still fail its first launch on an offline Mac. Check the app and its distribution container separately, and test the exact downloaded artifact.

This guide is for developers distributing a native Mac app outside the Mac App Store. It uses a Developer ID app inside a DMG. Installer packages, plug-in hosts, system extensions, and privileged helpers need their own signing and installation review.

Release diagram showing an app stapled before packaging and a finished DMG stapled afterward.

The image summarizes the ticket sequence. Both staples follow a successful notarization submission. A stapled ticket removes a network dependency for that ticket lookup; it does not guarantee that every first-launch check will succeed.

Contents

Separate the security checks

Developer ID signing identifies the developer and seals the signed code and resources. Hardened Runtime adds runtime protections against certain injection and memory-tampering techniques. Notarization submits the software to Apple's automated checks. Stapling attaches its ticket to a supported artifact. Gatekeeper evaluates downloaded software on the user's Mac. App Sandbox constrains runtime access according to the sandbox rules and entitlements. A notarized Developer ID app may be unsandboxed. Apple distribution signing · Hardened Runtime · App Sandbox

Do not label notarization as a security audit of the application's behavior. Its result is one release gate. It does not establish that the app is harmless or that its permissions match user expectations. Apple notarization overview

Review the entitlement set

Start with an exported Release build. Review each executable target separately, including XPC services and extensions. Ask why each exception is needed. Remove development-only get-task-allow. Review JIT, unsigned executable memory, and disabled library validation carefully if your runtime needs them.

A framework generally should not receive the same application entitlements as its host. An XPC service or helper has its own process requirements. Sign nested code from the inside outward, then sign the outer app. Prefer Xcode's export workflow for a complex bundle. Avoid using codesign --deep to conceal an incomplete signing plan; the verification command can use it to inspect nested code. Apple distribution signing

Build a reproducible release pipeline

The script below is a template for a simple app. Replace the identity and paths. It assumes a Developer ID identity is already installed and a notarytool Keychain profile named release-notary is configured. Do not put passwords into the script.

The two nested paths are examples. Remove them only if your app has no such components. Add every actual executable target in dependency order. Give the helper its own reviewed entitlements.

#!/bin/bash
set -euo pipefail

APP="build/Release/Example.app"
IDENTITY="Developer ID Application: Example Team (TEAMID)"
PROFILE="release-notary"
STAGE="build/distribution"
DMG="build/Example.dmg"

# Examples: sign inner code before its containing app.
codesign --force --timestamp --options runtime \
  --sign "$IDENTITY" \
  "$APP/Contents/Frameworks/ExampleCore.framework"
codesign --force --timestamp --options runtime \
  --entitlements ReleaseHelper.entitlements \
  --sign "$IDENTITY" \
  "$APP/Contents/XPCServices/ExampleHelper.xpc"
codesign --force --timestamp --options runtime \
  --entitlements ReleaseApp.entitlements \
  --sign "$IDENTITY" "$APP"

codesign --verify --deep --strict --verbose=2 "$APP"
codesign --display --entitlements :- "$APP"

ditto -c -k --sequesterRsrc --keepParent \
  "$APP" build/Example-notary.zip
xcrun notarytool submit build/Example-notary.zip \
  --keychain-profile "$PROFILE" --wait
# Continue only after the service reports Accepted.
xcrun stapler staple "$APP"
xcrun stapler validate "$APP"

# Use a fresh staging directory for each release.
mkdir "$STAGE"
ditto "$APP" "$STAGE/Example.app"
hdiutil create -volname Example -srcfolder "$STAGE" \
  -format UDZO "$DMG"
codesign --timestamp --sign "$IDENTITY" "$DMG"
xcrun notarytool submit "$DMG" \
  --keychain-profile "$PROFILE" --wait
# Again, require Accepted before publishing.
xcrun stapler staple "$DMG"
xcrun stapler validate "$DMG"

spctl --assess --type execute --verbose=4 "$APP"
spctl --assess --type open \
  --context context:primary-signature --verbose=4 "$DMG"
shasum -a 256 "$DMG"

Check the submission's returned status, not merely that the upload completed. For unattended CI, use --output-format json, parse the status field, and explicitly require Accepted before proceeding. Download the notary log by its submission ID when the status is Invalid or when warnings need investigation. A local stapler success is useful evidence, but still perform the clean-machine check below. Apple custom notarization workflow

Why submit a ZIP first? It lets the service inspect the app, then lets you attach the resulting ticket to that app before it enters the final DMG. ZIP archives do not themselves support stapling. Stapling the finished DMG afterward covers the outer container as well. Hash the final, stapled DMG, because that is the artifact customers receive. Apple packaging guidance

What can still go wrong

You package an earlier app. Compare the mounted DMG's bundle version, signing identity, and stapler result with your release record. A passing check on the app in your build folder says little about a different app in the downloaded DMG.

You change signed content. Editing Info.plist, replacing a framework, or running an asset tool after signing can invalidate the seal. Finish content changes before signing. Stapling is the supported ticket-attachment operation.

A plug-in fails after launch. A valid main app does not prove its library-validation exceptions and third-party plug-ins work. Exercise those features from the distributed build.

The test machine already trusts the artifact. Previous launches and online ticket retrieval can hide a first-run dependency. Use a fresh VM snapshot or a separate test account and machine as appropriate.

The notary service accepts the upload but reports Invalid. Retain the submission ID and inspect its log. Fix the named code or entitlement issue and rebuild; do not repeatedly re-submit unchanged software hoping for a different answer.

Test a clean offline first launch

  1. Download the exact public DMG using a browser on a clean test Mac. Preserve quarantine metadata.
  2. Disconnect that Mac before mounting and first opening the app. Use a fresh test environment without earlier launches of this release.
  3. Mount the DMG, validate its ticket, copy the app to Applications, and validate the app's ticket.
  4. Launch through Finder. Record the Gatekeeper result and any app permission prompts.
  5. Exercise a representative feature, quit, and relaunch. Repeat online on another clean snapshot.
  6. Record macOS version, CPU architecture, app build, final DMG SHA-256, and results. Test the oldest supported macOS as well as the current one.

Keep the installation route intact during this test. Removing quarantine or disabling Gatekeeper changes the question being tested. These commands and steps are release guidance, not evidence that your particular signed build has passed.

For runtime permissions after installation, continue with security-scoped bookmarks, Keychain queries, and clipboard expiry.

References

Expanded from Ehsan's original notarization post.

Authoritative References