MCPcopy Create free account
hub / github.com/microsoft/AI-Engineering-Coach / assertTrustedPath

Function assertTrustedPath

src/core/parser-shared.ts:23–37  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

21 * contain path traversal sequences. Throws if the path is unsafe.
22 */
23export function assertTrustedPath(filePath: string): void {
24 const normalized = path.resolve(filePath);
25
26 // Reject path traversal
27 const segments = filePath.replaceAll('\\', '/').split('/');
28 if (segments.includes('..')) {
29 throw new Error(`Path traversal detected: ${filePath}`);
30 }
31
32 const trustedRoots = getTrustedRoots();
33 const isTrusted = trustedRoots.some(root => normalized.startsWith(root + path.sep) || normalized === root);
34 if (!isTrusted) {
35 throw new Error(`Path is outside trusted directories: ${filePath}`);
36 }
37}
38
39function getTrustedRoots(): string[] {
40 const roots: string[] = [];

Callers 9

sqliteQueryFunction · 0.90
sqliteExecAsyncFunction · 0.90
readJsonSafeFunction · 0.90
parseCodexSessionFileFunction · 0.90
parseClaudeSessionFileFunction · 0.90
readFileFunction · 0.90
forEachJsonlLineFunction · 0.90
forEachJsonlLineAsyncFunction · 0.90
extractSessionImagesFunction · 0.90

Calls 1

getTrustedRootsFunction · 0.85

Tested by

no test coverage detected