From ae5df90eecd3dfd0e703e0186d0696345c6fd686 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Sat, 8 Nov 2025 19:49:16 +0100 Subject: [PATCH] Rejects absolute paths in vault exports Updates path normalization to disallow absolute paths, ensuring exports remain within the vault. Enhances security by rejecting path traversal attempts. Aligns with obisidian-bot-review branch requirements. --- src/core/SecurityUtils.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/core/SecurityUtils.ts b/src/core/SecurityUtils.ts index 68d4eb1..24c6289 100644 --- a/src/core/SecurityUtils.ts +++ b/src/core/SecurityUtils.ts @@ -117,13 +117,16 @@ export class SecurityUtils { return false; } - // Normalize path, but preserve absolute paths (mirrors SettingsTab storage logic) + // Normalize path (reject absolute paths so exports stay inside the vault) const trimmed = outputFolder.trim(); - const normalizedPath = path.isAbsolute(trimmed) ? trimmed : path.normalize(trimmed); - + if (path.isAbsolute(trimmed)) { + return false; + } + const normalizedPath = path.normalize(trimmed); + // Check for path traversal attempts - if (normalizedPath.includes('..') || - normalizedPath.startsWith('/') || + if (normalizedPath.includes('..') || + normalizedPath.startsWith('/') || normalizedPath.startsWith('\\') || normalizedPath.includes('\x00')) { return false; @@ -282,10 +285,13 @@ export class SecurityUtils { return 'Output folder is required'; } - // Normalize path, but preserve absolute paths (mirrors SettingsTab storage logic) + // Normalize path (reject absolute paths so exports stay inside the vault) const trimmed = outputFolder.trim(); - const normalizedPath = path.isAbsolute(trimmed) ? trimmed : path.normalize(trimmed); - + if (path.isAbsolute(trimmed)) { + return 'Absolute paths are not allowed - use relative paths from vault root'; + } + const normalizedPath = path.normalize(trimmed); + if (normalizedPath.includes('..')) { return 'Path traversal attempts (..) are not allowed'; }