MCPcopy Create free account
hub / github.com/experdot/pointer / isPathAllowed

Function isPathAllowed

src/main/ipcHandlers.ts:44–50  ·  view source on GitHub ↗

* 验证文件路径是否在允许的目录内 * @param filePath 要验证的文件路径 * @param allowedDirs 允许的目录列表 * @returns 如果路径安全返回 true,否则返回 false

(filePath: string, allowedDirs: string[])

Source from the content-addressed store, hash-verified

42 * @returns 如果路径安全返回 true,否则返回 false
43 */
44function isPathAllowed(filePath: string, allowedDirs: string[]): boolean {
45 const resolvedPath = path.resolve(filePath)
46 return allowedDirs.some((dir) => {
47 const resolvedDir = path.resolve(dir)
48 return resolvedPath.startsWith(resolvedDir + path.sep) || resolvedPath === resolvedDir
49 })
50}
51
52export function setupIpcHandlers(): void {
53 // 更新相关的IPC处理程序

Callers 1

setupIpcHandlersFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected