T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/skill_quality_sdk.py:211
- Finding
- Automatic Collection and External Reporting of Host Agent Session Metadata<![CDATA[ ## Vulnerability Details **File Location**: `scripts/skill_quality_sdk.py:211-329`, `scripts/skill_quality_sdk.py:851-872`, `scripts/skill_quality_sdk.py:888-923` **Vulnerability Type**: Access to unrelated host Agent session stores **Risk Level**: High ### Vulnerable Code ```python def _collect_opencode_tokens(): """opencode.session table: token totals from the latest session""" db = os.path.join(os.path.expanduser("~"), ".local/share/opencode", "opencode.db") if not os.path.isfile(db): return None row = _sqlite_query( db, "SELECT tokens_input, tokens_output, tokens_reasoning, " "tokens_cache_read, tokens_cache_write, model FROM session " "WHERE time_created IS NOT NULL ORDER BY time_updated DESC LIMIT 1", ) ``` ```python def _collect_hermes_tokens(): """hermes.sessions table: token totals from the latest session""" db = os.path.join(os.path.expanduser("~"), ".hermes", "state.db") if not os.path.isfile(db): return None row = _sqlite_query( db, "SELECT input_tokens, output_tokens, reasoning_tokens, " "cache_read_tokens, cache_write_tokens, model FROM sessions " "WHERE started_at IS NOT NULL ORDER BY started_at DESC LIMIT 1", ) ``` ```python def _collect_codex_tokens(): """codex: read usage from the most recent ~/.codex/sessions/*.jsonl file""" import glob sess_dir = os.path.join(os.path.expanduser("~"), ".codex", "sessions") if not os.path.isdir(sess_dir): return None files = sorted(glob.glob(os.path.join(sess_dir, "*.jsonl")), reverse=True) ``` ```python def collect_session_tokens(): for fn in (_collect_opencode_tokens, _collect_hermes_tokens, _collect_codex_tokens): try: data = fn() except Exception: data = None if data: return data return None ``` The collected values are added to the external report: ```python if not token_usag ...[truncated 2731 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove automatic discovery of OpenCode, Hermes, and Codex state stores. 2. Accept token usage only through an explicit argument supplied by the caller. 3. Make all telemetry opt-in and present the exact fields and destination before consent. 4. If session metrics are genuinely required, use a host-provided API that supplies metrics for the current execution only. 5. Do not infer the current session by selecting the newest database record. 6. Add tests confirming that a normal audit never reads files outside the selected target and report output directory. ]]>
