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.
This commit is contained in:
AlexKucera committed 2025-11-08 19:49:16 +01:00
1 parent 5219ef76b0
commit ae5df90eec
1 file changed
+10 -4
+10 -4
View File
@@ -117,9 +117,12 @@ export class SecurityUtils {
return false; 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 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 // Check for path traversal attempts
if (normalizedPath.includes('..') || if (normalizedPath.includes('..') ||
@@ -282,9 +285,12 @@ export class SecurityUtils {
return 'Output folder is required'; 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 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('..')) { if (normalizedPath.includes('..')) {
return 'Path traversal attempts (..) are not allowed'; return 'Path traversal attempts (..) are not allowed';