Skip to content

Commit a0d3c57

Browse files
committed
fix(run-validation): double-resolve symlinks in containment check (F009 S5)
1 parent 01671a5 commit a0d3c57

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

scripts/e2b/run_validation.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,26 +399,22 @@ def get_reports_root() -> Path:
399399

400400

401401
def _path_is_inside(child: Path, parent: Path) -> bool:
402-
try:
403-
child.relative_to(parent)
404-
except ValueError:
405-
return False
406-
return child != parent
402+
return child != parent and child.is_relative_to(parent)
407403

408404

409405
def clean_output_dir(output_dir: Path, console: Console) -> None:
410-
reports_root = get_reports_root().expanduser().absolute()
406+
reports_root = get_reports_root().expanduser().resolve()
411407
clean_target = output_dir.expanduser().resolve()
412408
if not _path_is_inside(clean_target, reports_root):
413409
raise ValueError(
414410
f"Refusing to clean output outside repo reports/: {clean_target} "
415411
f"is not inside {reports_root}"
416412
)
417413

418-
if output_dir.exists():
414+
if clean_target.exists():
419415
console.print(f"[yellow]WARN[/] wiping existing output directory {clean_target}")
420-
shutil.rmtree(output_dir)
421-
output_dir.mkdir(parents=True, exist_ok=True)
416+
shutil.rmtree(clean_target)
417+
clean_target.mkdir(parents=True, exist_ok=True)
422418

423419

424420
def create_run_output_dir(

0 commit comments

Comments
 (0)