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 {
|
public isPluginTempDir(dirPath: string): boolean {
|
||||||
const pluginDir = this.getPluginDir();
|
const pluginDir = this.getPluginDir();
|
||||||
// Simple string comparison for temp directory validation
|
const normalizedDirPath = normalizePath(dirPath);
|
||||||
return dirPath.startsWith(pluginDir) &&
|
const normalizedPluginDir = normalizePath(pluginDir);
|
||||||
(dirPath.includes(PLUGIN_DIRS.TEMP_IMAGES) || dirPath.includes(PLUGIN_DIRS.TEMP_PANDOC));
|
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