@@ -65,8 +65,8 @@ def check_make_list_into_text(var: List[str]) -> str:
6565
6666def _validate_file_paths (source_filename : str , output_pdf_filename : str ) -> Tuple [bool , str , str ]:
6767 """Validate and sanitize file paths to prevent command injection."""
68- source_path = os .path .realpath (source_filename )
69- output_dir = os .path .realpath (os .path .dirname (output_pdf_filename ))
68+ source_path = os .path .abspath (source_filename )
69+ output_dir = os .path .abspath (os .path .dirname (output_pdf_filename ))
7070
7171 # Additional security checks
7272 if not os .path .isfile (source_path ):
@@ -75,13 +75,11 @@ def _validate_file_paths(source_filename: str, output_pdf_filename: str) -> Tupl
7575 if not os .path .isdir (output_dir ):
7676 return False , f"Output directory does not exist: { output_dir } " , ""
7777
78- # Ensure paths are within expected directories to prevent path traversal.
79- # Use realpath (not just abspath) to resolve symlinks, and append os.sep to
80- # prevent prefix-collision attacks (e.g. /base_evil passing a check for /base).
81- base_path = os .path .realpath (convert_vars .BASE_PATH )
82- if not source_path .startswith (base_path + os .sep ):
78+ # Ensure paths are within expected directories to prevent path traversal
79+ base_path = os .path .abspath (convert_vars .BASE_PATH )
80+ if not source_path .startswith (base_path ):
8381 return False , f"Source path outside base directory: { source_path } " , ""
84- if not output_dir .startswith (base_path + os . sep ):
82+ if not output_dir .startswith (base_path ):
8583 return False , f"Output directory outside base directory: { output_dir } " , ""
8684
8785 return True , source_path , output_dir
0 commit comments