T09 · Insecure Skill Coding Practices
- Location
zanna-aperta.py:222- Finding
Project Path Traversal Enables Arbitrary File Writes and Recursive Directory Deletion
- Content
View full analysis
Vulnerability Details
File Location:
zanna-aperta.py, lines 222-335
Vulnerability Type: Unrestricted path construction and filesystem access
Risk Level: CriticalVulnerable Code
python def project_create(uuid: str = "", project_name: str = "") -> Dict[str, Any]: """Crea progetto nella memoria OpenClaw""" try: project_dir = os.path.join(MEMORY_DIR, "projects", project_name or uuid) os.makedirs(project_dir, exist_ok=True) project_file = os.path.join(project_dir, "project.md") content = f"""# {project_name or uuid} **UUID:** {uuid} **Nome:** {project_name} **Stato:** Creato **Data:** {subprocess.run(['date', '-I'], capture_output=True, text=True).stdout.strip()} ## Task - [ ] Task 1 ## Note """ with open(project_file, "w") as f: f.write(content) active_file = os.path.join(MEMORY_DIR, "projects", "ACTIVE.md") with open(active_file, "a") as f: f.write(f"\n## {project_name or uuid}\n**UUID:** {uuid}\n**Stato:** Attivo\n") return {"content": [{"type": "text", "text": f"Progetto creato: {project_dir}"}]} except Exception as e: return {"isError": True, "content": [{"type": "text", "text": str(e)}]} def project_update(uuid: str = "", project_name: str = "", key: str = "", value: str = "") -> Dict[str, Any]: """Aggiorna progetto""" try: target = project_name or uuid project_path = os.path.join(MEMORY_DIR, "projects", target) project_file = os.path.join(project_path, "project.md") if os.path.exists(project_file): with open(project_file) as f: content = f.read() content += f"\n\n## Aggiornamento {key}\n{value}" with open(project_file, "w") as f: f.write(content) return {"content": [{"type": "text", "text": f"Progetto {target} aggiorna ...[truncated 2796 chars]- Remediation
View remediation
Remediation Suggestions
- Reject absolute paths and identifiers containing path separators,
.components, or..components. - Use validated opaque project identifiers rather than caller-provided filesystem paths.
- Resolve both the configured project root and candidate path with
pathlib.Path.resolve(). - Verify that the resolved candidate is a strict descendant of the project root before every read, write, creation, or deletion.
- Do not rely on string-prefix comparisons; use
Path.relative_to()or an equivalent component-aware containment check. - Refuse to follow symbolic links and ensure deletion targets are expected project directories containing valid metadata.
- Replace immediate recursive deletion with a controlled quarantine or trash operation.
- Run the MCP server under a dedicated account with write access only to its project storage.
- Add tests covering absolute paths, nested traversal, symbolic links, empty identifiers, and encoded path separators.
- Reject absolute paths and identifiers containing path separators,
