T09 · Insecure Skill Coding Practices
- Location
scripts/run.py:75- Finding
Workspace Path Escape Allows Writes Outside the Authorized Workspace
- Content
View full analysis
None: path.mkdir(parents=True, exist_ok=True) def atomic_write_text(path: Path, content: str) -> None: ensure_dir(path.parent) fd, tmp_path = tempfile.mkstemp(prefix=path.name, dir=str(path.parent)) try: with os.fdopen(fd, "w", encoding="utf-8") as handle: handle.write(content) os.replace(tmp_path, path) except Exception: try: os.unlink(tmp_path) except OSError: pass ...[truncated 2720 chars]- Remediation
View remediation
Path: candidate = Path(rel) if candidate.is_absolute() or ".." in candidate.parts: raise ValueError(f"Unsafe workspace-relative path: {rel}") root = workspace.resolve() destination = (root / candidate).resolve(strict=False) if not destination.is_relative_to(root): raise ValueError(f"Path escapes workspace: {rel}") return destination ``` 3. Use a fixed mapping of artifact names to fixed workspace-relative paths instead of accepting arbitrary output destinations when customization is unnecessary. 4. Reject symlinked parent directories or securely traverse directories using descriptor-relative APIs where the workspace may be writable by an attacker. 5. Perform containment validation immediately before the final replacement to reduce time-of-check/time-of-use exposure. 6. Add tests for: - Absolute paths. - `../` traversal. - Nested traversal after normalization. - Symlinked parent directories. - Valid workspace-local paths. 7. Apply the same containment policy to all caller-controlled input and output paths throughout the pipeline tooling. ]]>
