mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Protect macOS Seatbelt writable root anchors (#39599)
## Why A sandboxed process could replace a writable directory root, changing the authority boundary used to construct a later sandbox policy. ## What changed - Deny unlinking or renaming directory roots granted write access by Seatbelt, while preserving replacement and deletion behavior for writable files. - Reject writable roots with nested symlink components and report these as Seatbelt preparation errors instead of network proxy failures. - Normalize writable roots before adding them to the generated Seatbelt policy. ## Testing Add coverage for symlink rejection, error classification, directory-root replacement and rename protection, newly created roots, and writable file replacement. GitOrigin-RevId: ab1ed4e55f20034bc43e028e6529d3d1f0d8181c
This commit is contained in:
1 parent
d75c85f651
commit
f6950546e5
6 files changed
+415
-25
No files matched your search
@@ -207,6 +207,8 @@ pub enum SandboxTransformError {
|
||||
},
|
||||
MissingLinuxSandboxExecutable,
|
||||
EnvironmentNetworkProxy(String),
|
||||
#[cfg(target_os = "macos")]
|
||||
SeatbeltPreparation(String),
|
||||
#[cfg(target_os = "linux")]
|
||||
Wsl1UnsupportedForBubblewrap,
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
@@ -234,6 +236,10 @@ impl std::fmt::Display for SandboxTransformError {
|
||||
Self::EnvironmentNetworkProxy(err) => {
|
||||
write!(f, "failed to prepare environment network proxy: {err}")
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
Self::SeatbeltPreparation(err) => {
|
||||
write!(f, "failed to prepare Seatbelt sandbox: {err}")
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
Self::Wsl1UnsupportedForBubblewrap => write!(f, "{WSL1_BWRAP_WARNING}"),
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
@@ -253,6 +259,8 @@ impl std::error::Error for SandboxTransformError {
|
||||
| Self::InvalidSandboxPolicyCwd { source, .. } => Some(source),
|
||||
Self::MissingLinuxSandboxExecutable => None,
|
||||
Self::EnvironmentNetworkProxy(_) => None,
|
||||
#[cfg(target_os = "macos")]
|
||||
Self::SeatbeltPreparation(_) => None,
|
||||
#[cfg(target_os = "linux")]
|
||||
Self::Wsl1UnsupportedForBubblewrap => None,
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
@@ -360,6 +368,7 @@ impl SandboxManager {
|
||||
SandboxType::MacosSeatbelt => {
|
||||
use crate::seatbelt::CreateSeatbeltCommandArgsParams;
|
||||
use crate::seatbelt::MACOS_PATH_TO_SEATBELT_EXECUTABLE;
|
||||
use crate::seatbelt::SeatbeltPreparationError;
|
||||
use crate::seatbelt::create_seatbelt_command_args_with_profile;
|
||||
|
||||
let pending = pending_sandboxed_request?;
|
||||
@@ -380,7 +389,14 @@ impl SandboxManager {
|
||||
},
|
||||
self.seatbelt_profile,
|
||||
)
|
||||
.map_err(SandboxTransformError::EnvironmentNetworkProxy)?;
|
||||
.map_err(|err| match err {
|
||||
SeatbeltPreparationError::FileSystem(message) => {
|
||||
SandboxTransformError::SeatbeltPreparation(message)
|
||||
}
|
||||
SeatbeltPreparationError::EnvironmentNetworkProxy(message) => {
|
||||
SandboxTransformError::EnvironmentNetworkProxy(message)
|
||||
}
|
||||
})?;
|
||||
let mut full_command = Vec::with_capacity(1 + args.len());
|
||||
full_command.push(MACOS_PATH_TO_SEATBELT_EXECUTABLE.to_string());
|
||||
full_command.append(&mut args);
|
||||
|
||||
Reference in new issue
Block a user