MCPcopy
hub / github.com/21st-dev/1code / readFileBuffer

Function readFileBuffer

src/main/lib/git/security/secure-fs.ts:305–316  ·  view source on GitHub ↗

* Read a file as a Buffer within a worktree. * * SECURITY: Enforces symlink-escape check. If the file is a symlink * pointing outside the worktree, this will throw PathValidationError. * * @throws PathValidationError with code "SYMLINK_ESCAPE" if file escapes worktree

(
		worktreePath: string,
		filePath: string,
	)

Source from the content-addressed store, hash-verified

303 * @throws PathValidationError with code "SYMLINK_ESCAPE" if file escapes worktree
304 */
305 async readFileBuffer(
306 worktreePath: string,
307 filePath: string,
308 ): Promise<Buffer> {
309 assertRegisteredWorktree(worktreePath);
310 const fullPath = resolvePathInWorktree(worktreePath, filePath);
311
312 // Block reads through symlinks that escape the worktree
313 await assertRealpathInWorktree(worktreePath, fullPath);
314
315 return readFile(fullPath);
316 },
317
318 /**
319 * Write content to a file within a worktree.

Callers

nothing calls this directly

Calls 4

assertRegisteredWorktreeFunction · 0.90
resolvePathInWorktreeFunction · 0.90
assertRealpathInWorktreeFunction · 0.85
readFileFunction · 0.85

Tested by

no test coverage detected