* 验证路径安全性 * @param targetPath 目标路径 * @param allowCustom 是否允许自定义路径(用于工作区)
(targetPath: string, allowCustom = false)
| 32 | * @param allowCustom 是否允许自定义路径(用于工作区) |
| 33 | */ |
| 34 | function validatePath(targetPath: string, allowCustom = false): { valid: boolean; error?: string } { |
| 35 | const allowedRoots = getAllowedFileSystemRoots(allowCustom) |
| 36 | if (isPathAllowed(targetPath, allowedRoots)) { |
| 37 | return { valid: true } |
| 38 | } |
| 39 | return { valid: false, error: '访问被拒绝:路径不在允许的范围内' } |
| 40 | } |
| 41 | |
| 42 | async function writeFileAtomically(filePath: string, content: string | Buffer): Promise<void> { |
| 43 | const dir = path.dirname(filePath) |
no test coverage detected