Skip to content

Commit d83fa75

Browse files
authored
Merge pull request #2410 from OWASP/revert-2346-fix/path-prefix-collision-v2
Revert "fix: prevent path prefix collision in _validate_file_paths"
2 parents a7e5995 + 24343b4 commit d83fa75

File tree

7 files changed

+6
-8
lines changed

7 files changed

+6
-8
lines changed

.clusterfuzzlite/build.sh

100644100755
File mode changed.

copi.owasp.org/rel/env.sh.eex

100644100755
File mode changed.

copi.owasp.org/rel/overlays/bin/migrate

100644100755
File mode changed.

copi.owasp.org/rel/overlays/bin/migrate.bat

100644100755
File mode changed.

copi.owasp.org/rel/overlays/bin/server

100644100755
File mode changed.

copi.owasp.org/rel/overlays/bin/server.bat

100644100755
File mode changed.

scripts/convert.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def check_make_list_into_text(var: List[str]) -> str:
6565

6666
def _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

Comments
 (0)