(destDir: string, target: string)
| 30 | * outside the project. |
| 31 | */ |
| 32 | export function assertSafeTarget(destDir: string, target: string): void { |
| 33 | if (isAbsolute(target)) { |
| 34 | throw new Error(`Unsafe target "${target}": absolute paths are not allowed.`); |
| 35 | } |
| 36 | if (/(^|[/\\])\.\.([/\\]|$)/.test(target)) { |
| 37 | throw new Error(`Unsafe target "${target}": path segments may not contain "..".`); |
| 38 | } |
| 39 | if (/^[A-Za-z]:[/\\]/.test(target)) { |
| 40 | throw new Error(`Unsafe target "${target}": Windows drive letters are not allowed.`); |
| 41 | } |
| 42 | const resolved = resolve(destDir, target); |
| 43 | const rel = relative(resolve(destDir), resolved); |
| 44 | if (rel.startsWith("..") || isAbsolute(rel)) { |
| 45 | throw new Error(`Unsafe target "${target}": resolves outside destDir ${destDir}.`); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | function isInstalledRegistryBlockComposition(item: RegistryItem, file: FileTarget): boolean { |
| 50 | return ( |
no test coverage detected