diff --git a/sdk/src/tools/list-directory.ts b/sdk/src/tools/list-directory.ts index 3bf66fa968..e7a1bd6fca 100644 --- a/sdk/src/tools/list-directory.ts +++ b/sdk/src/tools/list-directory.ts @@ -13,6 +13,20 @@ export async function listDirectory(params: { try { const resolvedPath = path.resolve(projectPath, directoryPath) + if ( + !resolvedPath.startsWith(projectPath + path.sep) && + resolvedPath !== projectPath + ) { + return [ + { + type: 'json', + value: { + errorMessage: `Invalid path: Path '${directoryPath}' is outside the project directory.`, + }, + }, + ] + } + const entries = await fs.readdir(resolvedPath, { withFileTypes: true, })