Skip to content

Commit ce4233c

Browse files
authored
Merge pull request #81 from karam-ajaj/alert-autofix-6
Potential fix for code scanning alert no. 6: Uncontrolled data used in path expression
2 parents 20e304a + ed3a659 commit ce4233c

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

config/scripts/app.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,12 @@ def event_generator():
277277
safe_container = validate_container_name(container)
278278
cmd = ["docker", "logs", "-f", "--tail", "10", safe_container]
279279
else:
280-
filepath = f"{LOGS_DIR}/{filename}"
280+
base_dir = os.path.abspath(LOGS_DIR)
281+
filepath = os.path.normpath(os.path.join(base_dir, filename))
282+
# Ensure the resolved path stays within the logs directory
283+
if os.path.commonpath([base_dir, filepath]) != base_dir:
284+
yield "data: [ERROR] Invalid log file path\n\n"
285+
return
281286
if not os.path.exists(filepath):
282287
yield f"data: [ERROR] File not found: {filepath}\n\n"
283288
return

0 commit comments

Comments
 (0)