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

Function isPathAllowed

src/main/fsHandlers.ts:21–27  ·  view source on GitHub ↗

* 验证路径是否在允许的目录内

(filePath: string, allowedDirs: string[])

Source from the content-addressed store, hash-verified

19 * 验证路径是否在允许的目录内
20 */
21function isPathAllowed(filePath: string, allowedDirs: string[]): boolean {
22 const resolvedPath = path.resolve(filePath)
23 return allowedDirs.some((dir) => {
24 const resolvedDir = path.resolve(dir)
25 return resolvedPath.startsWith(resolvedDir + path.sep) || resolvedPath === resolvedDir
26 })
27}
28
29/**
30 * 验证路径安全性

Callers 1

validatePathFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected