MCPcopy Create free account
hub / github.com/promptfoo/promptfoo / resolveAndValidate

Function resolveAndValidate

src/util/agent/fsOperations.ts:27–33  ·  view source on GitHub ↗

* Resolve a requested path relative to rootDir and validate it is within * the sandbox (symlink-safe). Returns the resolved absolute path.

(requested: string, rootDir: string)

Source from the content-addressed store, hash-verified

25 * the sandbox (symlink-safe). Returns the resolved absolute path.
26 */
27async function resolveAndValidate(requested: string, rootDir: string): Promise<string> {
28 const resolved = path.resolve(rootDir, requested);
29 if (!(await isPathWithinDir(resolved, rootDir))) {
30 throw new Error(`Path traversal rejected: ${requested}`);
31 }
32 return resolved;
33}
34
35/**
36 * Write a file relative to rootDir.

Callers 4

writeFileFunction · 0.85
readFileFunction · 0.85
listDirectoryFunction · 0.85
grepFilesFunction · 0.85

Calls 2

isPathWithinDirFunction · 0.90
resolveMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…