MCPcopy Create free account
hub / github.com/agegr/pi-web / isFilePathAllowed

Function isFilePathAllowed

lib/file-access.ts:54–69  ·  view source on GitHub ↗
(target: string, allowedRoots: Set<string>)

Source from the content-addressed store, hash-verified

52}
53
54export function isFilePathAllowed(target: string, allowedRoots: Set<string>): boolean {
55 for (const root of allowedRoots) {
56 const useWindowsRules = isWindowsAbsolutePath(target) || isWindowsAbsolutePath(root);
57 const resolver = useWindowsRules ? path.win32 : path;
58 const sep = useWindowsRules ? "\\" : path.sep;
59 const normalized = resolver.resolve(target);
60 const normalizedRoot = resolver.resolve(root);
61 const comparable = useWindowsRules ? normalized.toLowerCase() : normalized;
62 const comparableRoot = useWindowsRules ? normalizedRoot.toLowerCase() : normalizedRoot;
63 const rootWithSep = comparableRoot.endsWith(sep) ? comparableRoot : comparableRoot + sep;
64 if (comparable === comparableRoot || comparable.startsWith(rootWithSep)) {
65 return true;
66 }
67 }
68 return false;
69}

Callers 6

getUploadDirectoryFunction · 0.90
GETFunction · 0.90
checkCwdAllowedFunction · 0.90
GETFunction · 0.90
GETFunction · 0.90
GETFunction · 0.90

Calls 1

isWindowsAbsolutePathFunction · 0.85

Tested by

no test coverage detected