MCPcopy Create free account
hub / github.com/coder/mux / resolveSkillFilePath

Function resolveSkillFilePath

src/node/services/tools/skillFileUtils.ts:30–64  ·  view source on GitHub ↗
(
  skillDir: string,
  filePath: string
)

Source from the content-addressed store, hash-verified

28}
29
30function resolveSkillFilePath(
31 skillDir: string,
32 filePath: string
33): {
34 resolvedPath: string;
35 normalizedRelativePath: string;
36} {
37 if (!filePath) {
38 throw new Error("filePath is required");
39 }
40
41 if (isAbsolutePathAny(filePath) || filePath.startsWith("~")) {
42 throw new Error(`Invalid filePath (must be relative to the skill directory): ${filePath}`);
43 }
44
45 if (filePath.startsWith("..")) {
46 throw new Error(`Invalid filePath (path traversal): ${filePath}`);
47 }
48
49 const resolvedPath = path.resolve(skillDir, filePath);
50 const relativePath = path.relative(skillDir, resolvedPath);
51
52 if (relativePath === "" || relativePath === ".") {
53 throw new Error(`Invalid filePath (expected a file, got directory): ${filePath}`);
54 }
55
56 if (relativePath.startsWith("..") || path.isAbsolute(relativePath)) {
57 throw new Error(`Invalid filePath (path traversal): ${filePath}`);
58 }
59
60 return {
61 resolvedPath,
62 normalizedRelativePath: relativePath.replaceAll(path.sep, "/"),
63 };
64}
65
66async function lstatIfExists(targetPath: string): Promise<Stats | null> {
67 try {

Callers 1

Calls 4

resolveMethod · 0.80
relativeMethod · 0.80
isAbsoluteMethod · 0.80
isAbsolutePathAnyFunction · 0.70

Tested by

no test coverage detected