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:
pakrym-oai authored and copyberry committed 2026-08-20 08:10:08 +00:00
1 parent 4e1a772a7d
commit e3e5ad2847
88 files changed
+2782 -302

No files matched your search

@@ -68,7 +68,7 @@ impl FsRequestProcessor {
let path = PathUri::from_abs_path(&params.path);
let bytes = self
.file_system()?
.read_file(&path, /*sandbox*/ None)
.read_file(&path, Default::default(), /*sandbox*/ None)
.await
.map_err(map_fs_error)?;
Ok(FsReadFileResponse {
@@ -87,7 +87,7 @@ impl FsRequestProcessor {
})?;
let path = PathUri::from_abs_path(&params.path);
self.file_system()?
.write_file(&path, bytes, /*sandbox*/ None)
.write_file(&path, bytes, Default::default(), /*sandbox*/ None)
.await
.map_err(map_fs_error)?;
Ok(FsWriteFileResponse {})
@@ -103,6 +103,7 @@ impl FsRequestProcessor {
&path,
CreateDirectoryOptions {
recursive: params.recursive.unwrap_or(true),
follow_symlinks: true,
},
/*sandbox*/ None,
)
@@ -118,7 +119,7 @@ impl FsRequestProcessor {
let path = PathUri::from_abs_path(&params.path);
let metadata = self
.file_system()?
.get_metadata(&path, /*sandbox*/ None)
.get_metadata(&path, Default::default(), /*sandbox*/ None)
.await
.map_err(map_fs_error)?;
Ok(FsGetMetadataResponse {
@@ -163,6 +164,7 @@ impl FsRequestProcessor {
RemoveOptions {
recursive: params.recursive.unwrap_or(true),
force: params.force.unwrap_or(true),
follow_symlinks: true,
},
/*sandbox*/ None,
)