Skip to content

Commit 48a934e

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 cf2305f commit 48a934e

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

dev_environment/demo_api_main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,26 @@ def _generate_random_arc_id() -> str:
135135

136136
now = datetime.now(UTC).isoformat()
137137
arc_dir = output_path / arc_id
138+
139+
# Ensure the resolved target directory stays within the intended output root.
140+
output_root_resolved = output_path.resolve()
141+
arc_dir_resolved = arc_dir.resolve()
142+
common_root = Path(os.path.commonpath([str(output_root_resolved), str(arc_dir_resolved)]))
143+
if common_root != output_root_resolved:
144+
# Reject paths that would escape the output root (for example via symlinks).
145+
return {
146+
"arc_id": arc_id,
147+
"status": "error",
148+
"metadata": {
149+
"rdi": rdi,
150+
"arc_hash": "demo_hash",
151+
"status": "REJECTED",
152+
"first_seen": now,
153+
"last_seen": now,
154+
},
155+
}
156+
157+
arc_dir = arc_dir_resolved
138158
payload_path = arc_dir.with_suffix(".payload.json")
139159

140160
with open(payload_path, "w", encoding="utf-8") as handle:

0 commit comments

Comments
 (0)