From c4062d66b0397e5613d09ebb5f7d9c4b53fea800 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Thu, 25 Sep 2025 16:29:54 +0200 Subject: [PATCH] security(TempDirectoryManager): Fix path traversal vulnerability with normalized path comparison MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replaced vulnerable string operations (startsWith/includes) with normalized path comparison - Uses normalizePath() for proper cross-platform path normalization - Constructs explicit temp directory paths for precise validation - Prevents path traversal attacks like '../../../etc/passwd' or similar - Ensures directory validation is based on actual path structure, not string matching - Maintains functionality while improving security posture 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/core/TempDirectoryManager.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/TempDirectoryManager.ts b/src/core/TempDirectoryManager.ts index 9cfaaf7..896f29f 100644 --- a/src/core/TempDirectoryManager.ts +++ b/src/core/TempDirectoryManager.ts @@ -102,8 +102,12 @@ export class TempDirectoryManager { */ public isPluginTempDir(dirPath: string): boolean { const pluginDir = this.getPluginDir(); - // Simple string comparison for temp directory validation - return dirPath.startsWith(pluginDir) && - (dirPath.includes(PLUGIN_DIRS.TEMP_IMAGES) || dirPath.includes(PLUGIN_DIRS.TEMP_PANDOC)); + const normalizedDirPath = normalizePath(dirPath); + const normalizedPluginDir = normalizePath(pluginDir); + const tempImagesDir = normalizePath([normalizedPluginDir, PLUGIN_DIRS.TEMP_IMAGES].join('/')); + const tempPandocDir = normalizePath([normalizedPluginDir, PLUGIN_DIRS.TEMP_PANDOC].join('/')); + + return normalizedDirPath.startsWith(tempImagesDir) || + normalizedDirPath.startsWith(tempPandocDir); } } \ No newline at end of file