(targetPath: string)
| 43 | * 检查路径是否安全(不在系统关键目录下) |
| 44 | */ |
| 45 | export function isPathSafe(targetPath: string): boolean { |
| 46 | const normalizedTarget = targetPath.toLowerCase().replace(/\//g, '\\') |
| 47 | |
| 48 | for (const dangerous of DANGEROUS_PATHS) { |
| 49 | const normalizedDangerous = dangerous.toLowerCase().replace(/\//g, '\\') |
| 50 | if (normalizedTarget.startsWith(normalizedDangerous)) { |
| 51 | return false |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return true |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * 检查目录是否为空或包含 ChatLab 标记与关键结构 |
no outgoing calls
no test coverage detected