MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / resolveSafeTarget

Function resolveSafeTarget

apps/vis/server/src/lib/zip-import.ts:35–42  ·  view source on GitHub ↗
(root: string, entryName: string)

Source from the content-addressed store, hash-verified

33 * writers refuse to emit `..` entries.
34 */
35export function resolveSafeTarget(root: string, entryName: string): string | null {
36 const absRoot = resolve(root);
37 const rootPrefix = absRoot + sep;
38 const rel = entryName.replaceAll('\\', '/');
39 const target = resolve(absRoot, rel);
40 if (target !== absRoot && !target.startsWith(rootPrefix)) return null;
41 return target;
42}
43
44/**
45 * Extract every file entry of `zipBuffer` under `destDir`, returning the list

Callers 2

extractZipFunction · 0.85

Calls 1

resolveFunction · 0.50

Tested by

no test coverage detected