MCPcopy
hub / github.com/AutoMaker-Org/automaker / isPathWithinDirectory

Function isPathWithinDirectory

libs/platform/src/security.ts:95–103  ·  view source on GitHub ↗
(resolvedPath: string, directoryPath: string)

Source from the content-addressed store, hash-verified

93 * Returns true only if resolvedPath is within directoryPath
94 */
95export function isPathWithinDirectory(resolvedPath: string, directoryPath: string): boolean {
96 // Get the relative path from directory to the target
97 const relativePath = path.relative(directoryPath, resolvedPath);
98
99 // If relative path starts with "..", it's outside the directory
100 // If relative path is absolute, it's outside the directory
101 // If relative path is empty or ".", it's the directory itself
102 return !relativePath.startsWith('..') && !path.isAbsolute(relativePath);
103}
104
105/**
106 * Get the configured allowed root directory

Callers 1

isPathAllowedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected