T09 · Insecure Skill Coding Practices
- Location
scripts/http_capture.py:199- Finding
Streaming Capture Persists Unredacted Request URLs and Potential API Credentials
- Content
View full analysis
None: """Emit a single errors.jsonl entry noting a streaming call we couldn't price.""" try: from errors import log_error log_error("http_capture", f"skipped stream: provider={provider} url={url}", hint="Use track_openai / track_anthropic for streaming coverage.") except Exception: pass ``` `scripts/errors.py:21-23, 33-50`: ```python LOG_DIR = Path(os.environ.get("CW_LOG_DIR", Path.home() / ".cost-watchdog")) LOG_DIR.mkdir(parents=True, exist_ok=True) ERRORS_LOG = LOG_DIR / "errors.jsonl" MAX_LINES = 5000 def log_error(component: str, error: Union[str, BaseException], *, hint: Optional[str] = None, extra: Optional[dict] = None) -> None: """Append one error entry. Never raises.""" try: if isinstance(error, BaseException): detail = "".join(traceback.format_exception_only(type(error), error)).strip() tb = "".join(traceback.format_tb(error.__traceback__)) else: detail = str(error) tb = "" entry = { "ts": time.time(), "component": component, "error": detail, "traceback": tb, "hint": hint or "", "extra": extra or {}, } line = js ...[truncated 2976 chars]- Remediation
View remediation
str: parsed = urlsplit(raw_url) return urlunsplit((parsed.scheme, parsed.netloc, parsed.path, "", "")) ``` 2. **Apply explicit query-parameter redaction** if operational diagnostics require selected parameters. Use an allowlist of known-safe parameter names rather than a denylist. At minimum, redact names such as `key`, `api_key`, `apikey`, `token`, `access_token`, `signature`, `sig`, and `credential`. 3. **Sanitize exception messages and tracebacks** before storing them. Replace credential-like query values, authorization tokens, bearer tokens, and provider-key formats with a fixed marker such as `[REDACTED]`. 4. **Enforce restrictive filesystem permissions:** - Create `~/.cost-watchdog` with mode `0700`. - Create `errors.jsonl`, `usage.jsonl`, cache files, and state files with mode `0600`. - Validate and correct permissions for pre-existing paths. - Reject symlinks or unexpected non-regular files before writing security-sensitive logs. 5. **Minimize logged data.** A streaming-gap entry only needs the provider and sanitized endpoint path. Do not store query strings, fragments, headers, request bodies, prompts, or response content. 6. **Add regression tests** that submit URLs containing representative secret parameters and verify that neither the secret values nor complete query strings appear in `errors.jsonl`. 7. **Document local telemetry sensitivity and retention.** Provide a command to clear error logs and define a bounded retention policy for potentially sensitive diagnostic records. ]]>
