MCPcopy Index your code
hub / github.com/coder/mux / ensurePathContained

Function ensurePathContained

src/node/services/tools/skillFileUtils.ts:92–107  ·  view source on GitHub ↗
(
  containmentRoot: string,
  candidatePath: string,
  options?: { allowMissing?: boolean }
)

Source from the content-addressed store, hash-verified

90 * escape.
91 */
92export async function ensurePathContained(
93 containmentRoot: string,
94 candidatePath: string,
95 options?: { allowMissing?: boolean }
96): Promise<string> {
97 const containmentRootReal = await fsPromises.realpath(containmentRoot);
98 const candidateReal = options?.allowMissing
99 ? await resolveRealPathAllowMissing(candidatePath)
100 : await fsPromises.realpath(candidatePath);
101
102 if (!isPathInsideRoot(containmentRootReal, candidateReal)) {
103 throw new Error("Path resolves outside containment root after symlink resolution.");
104 }
105
106 return candidateReal;
107}
108
109async function resolveRealPathAllowMissing(targetPath: string): Promise<string> {
110 const missingSegments: string[] = [];

Callers 4

readSkillDescriptorFunction · 0.90
createAgentSkillListToolFunction · 0.90

Calls 2

isPathInsideRootFunction · 0.85

Tested by

no test coverage detected