Skip to content

Commit 55520ac

Browse files
Potential fix for code scanning alert no. 16: Uncontrolled data used in path expression
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 4315695 commit 55520ac

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

opendrift_leeway_webgui/leeway/views.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,12 @@ def get(self, request, path):
143143
base_dir = Path(settings.SIMULATION_OUTPUT).resolve()
144144

145145
# Only allow a flat filename — no directory traversal or path separators
146-
if "/" in path or "\\" in path:
146+
candidate = Path(path)
147+
# Reject anything that is not a simple name (e.g. contains directories or is absolute)
148+
if candidate.name != path or candidate.is_absolute():
147149
raise Http404
148150

149-
file_path = (base_dir / path).resolve()
151+
file_path = (base_dir / candidate).resolve()
150152

151153
# Ensure the resolved path is inside the simulation output directory
152154
try:

0 commit comments

Comments
 (0)