T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/session-catchup.py:80- Finding
Cross-Agent Session Store Access Exceeds Least Privilege
- Content
View full analysis
list[str]: out: list[str] = [] xdg = os.environ.get("XDG_DATA_HOME") or str(Path.home() / ".local" / "share") db_path = Path(xdg) / "opencode" / "opencode.db" if not db_path.is_file(): return out try: with sqlite3.connect(f"file:{db_path}?mode=ro", uri=True) as conn: cur = conn.cursor() cur.execute("PRAGMA table_info(session)") cols = [r[1] for r in cur.fetchall()] if "directory" not in cols: return out cur.execute( "SELECT id, time_created FROM session WHERE directory = ? ORDER BY time_created DESC LIMIT 1", (str(cwd),), ) row = cur.fetchone() if row: age_min = (time.time() - row[1]) / 60 out.append(f"[catchup] OpenCode session {row[0]}, last touched {age_min:.0f} min ago") except sqlite3.Error: pass return out CODEX_READ_CAP = 256 * 1024 def _codex_catchup(cwd: Path) -> list[str]: out: list[str] = [] codex_dir = Path.home() / ".codex" / "sessions" if not codex_dir.is_dir(): return out files = sorted(codex_dir.glob("*.json"), key=lambda p: p.stat().st_mtime, reverse=True) cwd_str = str(cwd) for f in files[:10]: try: with f.open("rb") as fh: blob = fh.read(CODEX_READ_CAP) data = json.loads(blob.decode("utf-8", errors="replace")) except (OSError, json.JSONDecodeError, UnicodeDecodeError): continue if isinstance(data, dict) and data.get("cwd") == cwd_str: age_min = (time.time() - f.stat().st_mtime) / 60 out.app ...[truncated 2311 chars]- Remediation
View remediation
