T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/soul_guardian.py:220- Finding
Policy targets can escape the workspace and access or overwrite arbitrary files
- Content
View full analysis
Path: # Preserve relative structure under approved/. return state.approved_dir / Path(rel_path) ``` ```python def detect_drift_for(state: GuardianState, baselines: dict[str, Any], relp: str) -> tuple[bool, dict[str, Any]]: abs_path = WORKSPACE_ROOT / relp if not abs_path.exists(): return True, {"error": f"Missing {relp}"} refuse_symlink(abs_path) ``` ```python def restore_one(state: GuardianState, relp: str, info: dict[str, Any]) -> dict[str, Any]: """Restore a single file to its approved snapshot. Returns: extra fields to include in audit. """ abs_path = WORKSPACE_ROOT / relp refuse_symlink(abs_path) approved_snap = approved_snapshot_path(state, relp) if not approved_snap.exists(): raise RuntimeError(f"Missing approved snapshot for {relp}") state.ensure_dirs() ts = dt.datetime.now(dt.timezone.utc).strftime("%Y%m%dT%H%M%SZ") quarantine_path = state.quarantine_dir / f"{safe_patch_tag(relp.replace('/', '_'))}.{ts}.quarantine" atomic_write_bytes(quarantine_path, read_bytes(abs_path)) # Atomic restore. atomic_write_bytes(abs_path, read_bytes(approved_snap)) return {"quarantinePath": str(quarantine_path), **info} ``` ### Technical Analysis Direct paths from `policy.json` are converted to `Path` objects without rejecting: - Absolute paths - Parent-directory components such as `..` - Paths whose canonical destination lies outside `WORKSPACE_ROOT` - Paths traversing a symlinked parent directory Joining `WORKSPACE_ROOT / relp ...[truncated 2526 chars]- Remediation
View remediation
