MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / assertWithinRoot

Function assertWithinRoot

src/git/shadow.ts:18–25  ·  view source on GitHub ↗
(rootDir: string, filePath: string)

Source from the content-addressed store, hash-verified

16}
17
18function assertWithinRoot(rootDir: string, filePath: string): string {
19 const resolved = resolve(rootDir, filePath);
20 const normalizedRoot = resolve(rootDir) + "/";
21 if (!resolved.startsWith(normalizedRoot) && resolved !== resolve(rootDir)) {
22 throw new Error(`Path traversal denied: "${filePath}" resolves outside root directory`);
23 }
24 return resolved;
25}
26
27async function ensureDataDir(rootDir: string): Promise<string> {
28 const dataPath = join(rootDir, DATA_DIR);

Callers 2

createRestorePointFunction · 0.85
restorePointFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected