Skip to content

Commit 5aef9ae

Browse files
Potential fix for code scanning alert no. 39: Uncontrolled data used in path expression
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Steve Springett <steve@springett.us>
1 parent 1badf6b commit 5aef9ae

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

docgen/static/generate-menu.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828

2929
def validate_input_path(path):
3030
"""Ensure the input file resolves to within the script's directory."""
31+
# Resolve symlinks and remove any ".." components to get a canonical path
3132
resolved = os.path.realpath(path)
3233
try:
3334
common = os.path.commonpath([resolved, SCRIPT_DIR])
3435
except ValueError:
3536
common = None
36-
if common != SCRIPT_DIR:
37+
# Require the resolved path to be strictly inside SCRIPT_DIR (not equal to it)
38+
if common != SCRIPT_DIR or resolved == SCRIPT_DIR:
3739
print(f"ERROR: Input file must reside in {SCRIPT_DIR}", file=sys.stderr)
3840
sys.exit(1)
3941
return resolved

0 commit comments

Comments
 (0)