macOS Sandbox Escape vulnerability via Terminal
Terminal.app kept certain environment variables (including PATH) when the __OSINSTALL_ENVIRONMENT variable was set, and a sandboxed app could launch Terminal with that variable and a crafted PATH. This let an attacker run code outside the app sandbox, in Terminal's context, which may already hold privacy permissions.
Published on wojciechregula.blog
In 2020 I observed a strange behavior a sandboxed macOS app may launch any application that won’t inherit the main app’s sandbox profile. It was even funnier as the sandboxed app can spawn those new apps with environment variables.
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.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely Terminal.app trusted an environment variable to decide it was in an install environment and then skipped clearing sensitive variables such as PATH, which were later used in a shell command.
Impact
Code could run outside the app sandbox in Terminal's context, which may already hold privacy (TCC) permissions; the author also showed it triggered from a Word document.
What the attacker needed
Attacker code runs in a sandboxed app; Terminal.app is present
The fix
It was fixed as CVE-2022-26696: Terminal no longer respects the install-environment variable.
How it was found
- From a sandboxed app, launch Terminal with the install-environment variable set and a crafted PATH value.
- Terminal starts, sees the install-environment variable, and keeps the supplied environment variables.
- Terminal uses the crafted PATH value in a shell command, running the attacker's code outside the sandbox.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A sandbox is a wall that stops an app from touching things it should not. Here a sandboxed app could start Terminal with a special setting that made Terminal keep a value the attacker controlled, and Terminal then ran that value as a command. The result was code running outside the wall, with Terminal's own permissions.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.