MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / resolveProjectFile

Function resolveProjectFile

src/ui-server/security.ts:294–317  ·  view source on GitHub ↗
(projectRoot: string, relativePath: string)

Source from the content-addressed store, hash-verified

292 * the path escapes the root by traversal or symlink.
293 */
294export function resolveProjectFile(projectRoot: string, relativePath: string): string {
295 if (typeof relativePath !== 'string' || relativePath.trim() === '') {
296 throw new PathRefusalError('No file path was given.');
297 }
298 if (!isUsableSourcePath(relativePath)) {
299 throw new PathRefusalError(`Refusing to read an unusable path: ${relativePath}`);
300 }
301
302 // Sensitive-directory refusal, same list the MCP entry points use. Checked on
303 // the ROOT rather than the leaf: a root of `/etc` makes every path under it
304 // sensitive, and a leaf check would have to enumerate the world.
305 const rootError = validateProjectPath(projectRoot);
306 if (rootError) throw new PathRefusalError(rootError);
307
308 if (path.isAbsolute(relativePath)) {
309 throw new PathRefusalError(`Refusing to read an absolute path: ${relativePath}`);
310 }
311
312 const absolute = validatePathWithinRoot(projectRoot, relativePath);
313 if (!absolute) {
314 throw new PathRefusalError(`Refusing to read a path outside the project: ${relativePath}`);
315 }
316 return absolute;
317}

Callers 11

annotateWhenFunction · 0.90
resolveFunction · 0.90
loadFileFunction · 0.90
resolveRequestedFileFunction · 0.90
readIndexedFileTextFunction · 0.90
hasDriftedOnDiskFunction · 0.90
readFileShapeFunction · 0.90
trailsDirectoryFunction · 0.90
trailPathFunction · 0.90
mentionsOfFunction · 0.90
ui-server.test.tsFile · 0.90

Calls 3

validateProjectPathFunction · 0.90
validatePathWithinRootFunction · 0.90
isUsableSourcePathFunction · 0.85

Tested by

no test coverage detected