Skip to content

Commit 986dcfd

Browse files
Potential fix for pull request finding 'CodeQL / 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 9510a63 commit 986dcfd

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

dev_environment/demo_api_main.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,19 @@ def _handle_error(arc_dir: Path, rdi: str, arc_id: str, exc: Exception) -> None:
107107

108108
if common_root != str(base_root):
109109
# As an additional safeguard, if the computed directory is not under
110-
# OUTPUT_ROOT, force it into a fixed "errors" directory.
110+
# OUTPUT_ROOT, force it into a fixed "errors" directory and re-validate.
111111
safe_arc_dir = (base_root / "errors").resolve()
112+
try:
113+
common_root = os.path.commonpath([str(base_root), str(safe_arc_dir)])
114+
except ValueError:
115+
# In the unlikely event that commonpath still fails, log directly under
116+
# the resolved OUTPUT_ROOT itself.
117+
safe_arc_dir = base_root
118+
else:
119+
if common_root != str(base_root):
120+
# If the resolved "errors" directory is still not under OUTPUT_ROOT,
121+
# fall back to using the OUTPUT_ROOT directory itself.
122+
safe_arc_dir = base_root
112123

113124
safe_arc_dir.mkdir(parents=True, exist_ok=True)
114125
error_path = safe_arc_dir / "error.txt"

0 commit comments

Comments
 (0)