From 791939b65df906b1f45da0f566c847fa3932b009 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Mon, 21 Jul 2025 16:33:07 -0400 Subject: [PATCH] [ROMM-2114] Fix using symlinks on volumes --- backend/handler/filesystem/base_handler.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/handler/filesystem/base_handler.py b/backend/handler/filesystem/base_handler.py index c100c2fe0..10f0ef6e2 100644 --- a/backend/handler/filesystem/base_handler.py +++ b/backend/handler/filesystem/base_handler.py @@ -136,12 +136,21 @@ class FSHandler: if path_path.is_absolute(): raise ValueError("Path must be relative, not absolute") - # Normalize path + # Normalize path without resolving the full path yet base_path_obj = Path(self.base_path).resolve() - full_path = (base_path_obj / path_path).resolve() + full_path = base_path_obj / path_path - # Ensure path is within base directory - full_path.relative_to(base_path_obj) + try: + if full_path.is_symlink(): + # For symlinks, ensure the symlink itself is within base directory + full_path.relative_to(base_path_obj) + else: + # For regular files/dirs, ensure resolved path is within base directory + full_path.resolve().relative_to(base_path_obj) + except ValueError as exc: + raise ValueError( + f"Path {path} is outside the base directory {self.base_path}" + ) from exc return full_path