T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/trace_debuger.py:149
- Finding
- Unredacted Elasticsearch Logs Are Forwarded to an External-Capable Analysis Process<![CDATA[ ## Vulnerability Details **File Location**: `scripts/trace_debuger.py:149-164` and `scripts/trace_debuger.py:281-302` **Vulnerability Type**: Sensitive data exposure through external analysis **Risk Level**: High ### Vulnerable Code ```python logs.append({ "ts": str(ts) if ts is not None else "", "service": src.get("fields.service") or fields.get("service") or src.get("service") or "unknown", "span_id": src.get("span_id") or "", "level": src.get("level") or "", "msg": str(msg), "error": src.get("error") or "", "caller": src.get("caller") or "", "raw": src, }) ``` ```python def run_codex_analysis(repo_path: str, logs: List[Dict[str, Any]]) -> Tuple[Optional[str], Optional[str]]: if not repo_path or not os.path.isdir(repo_path): return None, "repo_path 不存在,跳过 codex 分析" # 控制上下文长度,避免提示词过大 picked = logs[:200] payload = "\n".join([json.dumps(l, ensure_ascii=False) for l in picked]) prompt = ( "这是我的日志,请根据日志结合代码帮我排查分析bug,输出bug原因及解决方案,必须保持固定的格式。\n" "固定格式如下:\n" "1) Bug原因:<...>\n" "2) 证据:<...>\n" "3) 解决方案:<...>\n\n" "日志如下(JSON Lines):\n" + payload ) try: p = subprocess.run( ["codex", "exec", prompt], cwd=repo_path, capture_output=True, text=True, timeout=240, ) ``` ### Technical Analysis Every normalized Elasticsearch record retains the complete `_source` document in the `raw` field. The script then serializes as many as 200 complete records and supplies the resulting text to `codex exec`. Elasticsearch logs may contain authorization headers, session cookies, access tokens, personal information, request and response bodies, internal hostnames, database identifiers, or proprietary application data. The implementation applies no field allowlist, secret masking, data classification, destination verification, or explicit user confirmation before invoking Codex. Althoug ...[truncated 1150 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the `raw` field from normalized records supplied to Codex. 2. Use an explicit allowlist containing only fields required for diagnosis. 3. Redact authorization headers, cookies, tokens, passwords, API keys, email addresses, and other regulated data before serialization. 4. Require explicit user approval before sending logs to an externally backed analyzer. 5. Clearly document the analysis destination, retention behavior, and data-handling policy. 6. Add a local-only mode that never invokes a network-backed model. 7. Limit both the number and maximum serialized size of records. 8. Add automated tests using representative secrets to verify that sensitive values cannot reach the Codex prompt. ]]>
