Preserves absolute paths in SecurityUtils

Updates path normalization to maintain absolute paths, aligning
with SettingsTab storage logic. Enhances security by ensuring
consistent path handling and preventing path traversal.

Relates to issue: obsidian-bot-review branch
This commit is contained in:
AlexKucera committed 2025-11-08 19:05:46 +01:00
1 parent d56cb98d51
commit a71b20e9ba
1 file changed
+6 -3
+6 -3
View File
@@ -117,8 +117,9 @@ export class SecurityUtils {
return false; return false;
} }
// Normalize and resolve the path to detect traversal attempts // Normalize path, but preserve absolute paths (mirrors SettingsTab storage logic)
const normalizedPath = path.normalize(outputFolder.trim()); const trimmed = outputFolder.trim();
const normalizedPath = path.isAbsolute(trimmed) ? trimmed : path.normalize(trimmed);
// Check for path traversal attempts // Check for path traversal attempts
if (normalizedPath.includes('..') || if (normalizedPath.includes('..') ||
@@ -281,7 +282,9 @@ export class SecurityUtils {
return 'Output folder is required'; return 'Output folder is required';
} }
const normalizedPath = path.normalize(outputFolder.trim()); // Normalize path, but preserve absolute paths (mirrors SettingsTab storage logic)
const trimmed = outputFolder.trim();
const normalizedPath = path.isAbsolute(trimmed) ? trimmed : path.normalize(trimmed);
if (normalizedPath.includes('..')) { if (normalizedPath.includes('..')) {
return 'Path traversal attempts (..) are not allowed'; return 'Path traversal attempts (..) are not allowed';