MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / assertSafeTarget

Function assertSafeTarget

packages/cli/src/registry/installer.ts:32–47  ·  view source on GitHub ↗
(destDir: string, target: string)

Source from the content-addressed store, hash-verified

30 * outside the project.
31 */
32export 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
49function isInstalledRegistryBlockComposition(item: RegistryItem, file: FileTarget): boolean {
50 return (

Callers 2

installItemFunction · 0.85
installer.test.tsFile · 0.85

Calls 1

resolveFunction · 0.85

Tested by

no test coverage detected