MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / ensureUserPathIsValidAndSecurelyAccessible

Function ensureUserPathIsValidAndSecurelyAccessible

lib/models/files.ts:602–616  ·  view source on GitHub ↗
(userId: string, path: string)

Source from the content-addressed store, hash-verified

600 * @param path - The relative path (user-provided) to check
601 */
602export async function ensureUserPathIsValidAndSecurelyAccessible(userId: string, path: string): Promise<void> {
603 const userRootPath = join(await AppConfig.getFilesRootPath(), userId, '/');
604
605 const fullPath = join(userRootPath, path);
606
607 const resolvedFullPath = `${resolve(fullPath)}/`;
608
609 // Normalize path separators for consistent comparison on Windows
610 const normalizedUserRootPath = userRootPath.replaceAll('\\', '/');
611 const normalizedResolvedFullPath = resolvedFullPath.replaceAll('\\', '/');
612
613 if (!normalizedResolvedFullPath.startsWith(normalizedUserRootPath)) {
614 throw new Error('Invalid file path');
615 }
616}
617
618/**
619 * Ensures the file share path is valid and securely accessible (meaning it's not trying to access files outside of the file share's root directory).

Callers 14

handlerFunction · 0.90
postFunction · 0.90
getFunction · 0.90
listMethod · 0.85
createMethod · 0.85
listMethod · 0.85
createMethod · 0.85
updateMethod · 0.85
getMethod · 0.85
getPathEntriesFunction · 0.85
renameDirectoryOrFileFunction · 0.85

Calls 1

getFilesRootPathMethod · 0.80

Tested by

no test coverage detected