mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Harden unsandboxed patch filesystem access (#39659)
## Why An `apply_patch` path can be replaced with a symlink after verification, allowing an unsandboxed patch operation to reach a different file than the one that was approved. ## What changed - Add `follow_symlinks` options to executor filesystem reads, writes, metadata lookups, directory creation, and removal, including the corresponding `followSymlinks` protocol fields. - Implement no-follow filesystem operations on Unix and Windows that reject links in any path component and restrict file access to regular files. - Run `apply_patch` with symlink traversal disabled when an otherwise-required sandbox is bypassed, while retaining the existing follow-symlink default for standalone callers. ## Testing - Cover leaf and ancestor symlinks across patch add, update, delete, and move operations, including a path swap after verification. - Exercise local and remote no-follow filesystem behavior, concurrent directory creation, special-file rejection, and Windows reparse points. GitOrigin-RevId: 43fd479084891493ce13564fbd894b98f329c6dd
This commit is contained in:
1 parent
4e1a772a7d
commit
e3e5ad2847
88 files changed
+2782
-302
No files matched your search
@@ -8,7 +8,10 @@ use tokio::io;
|
||||
use crate::CopyOptions;
|
||||
use crate::CreateDirectoryOptions;
|
||||
use crate::ExecutorFileSystem;
|
||||
use crate::GetMetadataOptions;
|
||||
use crate::ReadFileOptions;
|
||||
use crate::RemoveOptions;
|
||||
use crate::WriteFileOptions;
|
||||
use crate::local_file_system::DirectFileSystem;
|
||||
use crate::protocol::FS_CANONICALIZE_METHOD;
|
||||
use crate::protocol::FS_COPY_METHOD;
|
||||
@@ -225,7 +228,13 @@ pub(crate) async fn run_direct_request(
|
||||
)),
|
||||
FsHelperRequest::ReadFile(params) => {
|
||||
let data = file_system
|
||||
.read_file(¶ms.path, /*sandbox*/ None)
|
||||
.read_file(
|
||||
¶ms.path,
|
||||
ReadFileOptions {
|
||||
follow_symlinks: params.follow_symlinks.unwrap_or(true),
|
||||
},
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await
|
||||
.map_err(map_fs_error)?;
|
||||
Ok(FsHelperPayload::ReadFile(FsReadFileResponse {
|
||||
@@ -239,7 +248,14 @@ pub(crate) async fn run_direct_request(
|
||||
))
|
||||
})?;
|
||||
file_system
|
||||
.write_file(¶ms.path, bytes, /*sandbox*/ None)
|
||||
.write_file(
|
||||
¶ms.path,
|
||||
bytes,
|
||||
WriteFileOptions {
|
||||
follow_symlinks: params.follow_symlinks.unwrap_or(true),
|
||||
},
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await
|
||||
.map_err(map_fs_error)?;
|
||||
Ok(FsHelperPayload::WriteFile(FsWriteFileResponse {}))
|
||||
@@ -250,6 +266,7 @@ pub(crate) async fn run_direct_request(
|
||||
¶ms.path,
|
||||
CreateDirectoryOptions {
|
||||
recursive: params.recursive.unwrap_or(true),
|
||||
follow_symlinks: params.follow_symlinks.unwrap_or(true),
|
||||
},
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
@@ -261,7 +278,13 @@ pub(crate) async fn run_direct_request(
|
||||
}
|
||||
FsHelperRequest::GetMetadata(params) => {
|
||||
let metadata = file_system
|
||||
.get_metadata(¶ms.path, /*sandbox*/ None)
|
||||
.get_metadata(
|
||||
¶ms.path,
|
||||
GetMetadataOptions {
|
||||
follow_symlinks: params.follow_symlinks.unwrap_or(true),
|
||||
},
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await
|
||||
.map_err(map_fs_error)?;
|
||||
Ok(FsHelperPayload::GetMetadata(FsGetMetadataResponse {
|
||||
@@ -312,6 +335,7 @@ pub(crate) async fn run_direct_request(
|
||||
RemoveOptions {
|
||||
recursive: params.recursive.unwrap_or(true),
|
||||
force: params.force.unwrap_or(true),
|
||||
follow_symlinks: params.follow_symlinks.unwrap_or(true),
|
||||
},
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
@@ -370,6 +394,7 @@ mod tests {
|
||||
let request = serde_json::to_value(FsHelperRequest::WriteFile(FsWriteFileParams {
|
||||
path: path.clone(),
|
||||
data_base64: String::new(),
|
||||
follow_symlinks: None,
|
||||
sandbox: None,
|
||||
}))?;
|
||||
assert_eq!(
|
||||
|
||||
Reference in new issue
Block a user