security(TempDirectoryManager): Fix path traversal vulnerability with normalized path comparison
- 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 <noreply@anthropic.com>
This commit is contained in:
1 file changed
+7
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user