MCPcopy Create free account
hub / github.com/agent-tower/core / assertNotInternalPath

Function assertNotInternalPath

packages/server/src/routes/files.ts:109–124  ·  view source on GitHub ↗
(...candidates: Array<string | null | undefined>)

Source from the content-addressed store, hash-verified

107}
108
109async function assertNotInternalPath(...candidates: Array<string | null | undefined>) {
110 const roots = await getProtectedInternalRoots();
111
112 for (const candidate of candidates) {
113 if (!candidate) continue;
114 const resolved = path.resolve(candidate);
115 const real = await resolveExistingPath(resolved);
116 const paths = real && real !== resolved ? [resolved, real] : [resolved];
117
118 if (paths.some((item) => roots.some((root) => isSameOrChildPath(item, root)))) {
119 const err: any = new Error('Internal Agent Tower files are not accessible');
120 err.code = 'INTERNAL_PATH_FORBIDDEN';
121 throw err;
122 }
123 }
124}
125
126async function resolveInWorkingDir(workingDir: string, userPath: string | undefined) {
127 const baseReal = await fs.realpath(workingDir);

Callers 2

resolveInWorkingDirFunction · 0.85
filesRoutesFunction · 0.85

Calls 3

resolveExistingPathFunction · 0.85
isSameOrChildPathFunction · 0.70

Tested by

no test coverage detected