T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/_lf_output.py:143
- Finding
- Sensitive API responses are persisted with unsafe filesystem defaults<![CDATA[ ## Vulnerability Details **File Location**: `scripts/_lf_output.py:28-54, 143-169` **Vulnerability Type**: Sensitive data exposure through insecure local storage **Risk Level**: High ### Vulnerable Code ```python def _lf_root() -> str: cached = _LF_SESSION_CACHE.get("_root") if cached: return cached candidates = [] acpx = (os.environ.get("ACPX_WORKSPACES") or "").strip() if acpx: acpx = acpx.split(os.pathsep)[0].strip() if acpx: candidates.append(os.path.join(acpx, "linkfox")) candidates.append(os.path.join(os.getcwd(), "linkfox")) candidates.append(os.path.join(os.path.expanduser("~"), "linkfox")) candidates.append(os.path.join(_lf_tempfile.gettempdir(), "linkfox")) for root in candidates: try: os.makedirs(root, exist_ok=True) probe = os.path.join(root, ".write_probe") with open(probe, "w", encoding="utf-8") as f: f.write("") os.remove(probe) except OSError: continue root = os.path.abspath(root) _LF_SESSION_CACHE["_root"] = root return root ``` ```python def emit_result(result, slug=SLUG, inline=False): """落盘完整响应到 linkfox/<date>/<session>/data/<slug>-<ts>.json;大响应只打印摘要。无缓存。""" serialized = json.dumps(result, ensure_ascii=False, indent=2) ts = _lf_time.time() date_str = _lf_time.strftime("%Y-%m-%d", _lf_time.localtime(ts)) sid = _lf_session_id(ts) root = _lf_root() session_dir = os.path.join(root, date_str, sid) os.makedirs(session_dir, exist_ok=True) _lf_ensure_meta(root, session_dir, date_str, sid, ts) data_dir = os.path.join(session_dir, "data") os.makedirs(data_dir, exist_ok=True) out = os.path.join(data_dir, f"{slug}-{int(ts * 1_000_000)}.json") try: with open(out, "w", encoding="utf-8") as f: f.write(serialized) print(f"Saved full response: {out} ({len(serialized)} bytes)") ex ...[truncated 3123 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Disable response persistence by default, especially for authorization and token-management endpoints. 2. Require an explicit command-line option or trusted configuration setting before writing responses to disk. 3. Recursively redact fields whose names or values indicate credentials, including: - `accessToken` - `refreshToken` - `Authorization` - OAuth `state` - Cookies and nested token objects 4. Avoid persisting raw HTTP error bodies unless they have been sanitized. 5. Create storage directories with mode `0700` and files with mode `0600`. 6. Use exclusive, symlink-resistant creation, such as `os.open` with `O_CREAT | O_EXCL | O_NOFOLLOW` where supported. 7. Validate that all resolved paths remain under the intended storage root. 8. Implement a documented retention period and secure cleanup for authentication-related records. 9. Print only a sanitized summary to stdout and avoid printing complete small responses automatically. ]]>
