Skip to content

Commit 1badf6b

Browse files
Fixed potential security issue
Signed-off-by: Steve Springett <steve@springett.us>
1 parent 18c651a commit 1badf6b

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

docgen/static/generate-menu.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929
def validate_input_path(path):
3030
"""Ensure the input file resolves to within the script's directory."""
3131
resolved = os.path.realpath(path)
32-
if not resolved.startswith(SCRIPT_DIR + os.sep) and resolved != SCRIPT_DIR:
32+
try:
33+
common = os.path.commonpath([resolved, SCRIPT_DIR])
34+
except ValueError:
35+
common = None
36+
if common != SCRIPT_DIR:
3337
print(f"ERROR: Input file must reside in {SCRIPT_DIR}", file=sys.stderr)
3438
sys.exit(1)
3539
return resolved

0 commit comments

Comments
 (0)