T09 · Insecure Skill Coding Practices
- Location
scripts/delete_subsession.py:24- Finding
Path Traversal Enables Arbitrary Local File Deletion and Index Modification
- Content
View full analysis
str: if agent_id: return agent_id if session_key: m = SESSION_KEY_RE.match(session_key) if m: return m.group("agent") raise SystemExit("Could not determine agent id; pass --agent-id.") ``` ```python def find_session_id(data: Any, session_key: Optional[str], session_id: Optional[str]) -> str: if session_id: return session_id if not session_key: raise SystemExit("Provide --session-key or --session-id.") entry = data.get(session_key) if not isinstance(entry, dict) or not entry.get("sessionId"): raise SystemExit(f"Session key not found in sessions.json: {session_key}") return entry["sessionId"] ``` ```python agent_id = infer_agent_id(args.session_key, args.agent_id) sessions_dir = Path.home() / ".openclaw" / "agents" / agent_id / "sessions" sessions_json = sessions_dir / "sessions.json" if not sessions_json.exists(): raise SystemExit(f"sessions.json not found: {sessions_json}") data = load_json(sessions_json) target_session_id = find_session_id(data, args.session_key, args.session_id) file_candidates = [ sessions_dir / f"{target_session_id}.jsonl", sessions_dir / f"{target_session_id}.trajectory.jsonl", sessions_dir / f"{target_session_id}.trajectory-path.json", ] ``` ```python if args.execute: for path in file_candidates: if path.exists(): path.unlink() if index_changed: sessions_json.write_text(json.dumps(pruned, ensure_ascii=False, indent=2) + "\n") ``` ### Technical Analysis The script accepts `--agent-id` and `--session-id` as path-forming input without validating their synt ...[truncated 2792 chars]- Remediation
View remediation
