T09 · Insecure Skill Coding Practices
Warning
- Location
- bridge.py:6
- Finding
- Incomplete Redaction of Sensitive Data Before External AI Processing<![CDATA[ ## Vulnerability Details **File Location**: `bridge.py`, lines 6-13 and 25-27 **Vulnerability Type**: Incomplete sensitive-data redaction **Risk Level**: Medium ### Vulnerable Code ```python def redact_logs(text): """Simple regex to mask potential secrets in logs before AI analysis.""" patterns = [ (r'([Pp]assword|[Ss]ecret|[Tt]oken|[Aa]pi[Kk]ey)["\s:=]+[^\s,"]+', r'\1: [REDACTED]'), (r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}', '[EMAIL_REDACTED]') ] for pattern, replacement in patterns: text = re.sub(pattern, replacement, text) return text ``` ```python # Sanitize prompt (basic) safe_prompt = redact_logs(prompt) res = subprocess.run([opencode_path, "run", safe_prompt], capture_output=True, text=True, timeout=60) ``` ### Technical Analysis The bridge relies on two regular expressions to sanitize potentially sensitive prompts before providing them to the configured `opencode` reasoning service. The secret expression only recognizes values preceded by the labels `password`, `secret`, `token`, or `apikey`, with limited case variations and separators. This approach does not cover many common secret representations, including: - `Authorization: Bearer <credential>` headers - Session cookies and cookie headers - Private keys and certificate material - Database connection strings containing credentials - Cloud-provider access keys - Provider-specific API key formats - Tokens whose labels contain hyphens or underscores - Multiline or whitespace-containing secrets - Unlabeled credentials appearing in log messages Consequently, the call to `redact_logs()` does not establish that the resulting prompt is safe to transmit. The documentation's broad claim that passwords, tokens, and related data are masked may also give operators a false sense of protection. ### Attack Path 1. A diagnostic prompt or log contains sensitive data in a format not recognized by the two redaction expressions. 2. The user passes t ...[truncated 1036 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Replace the narrow label-based approach with layered secret detection covering authorization headers, cookies, private keys, connection strings, cloud credentials, and provider-specific token formats. 2. Prefer allowlist-based log selection so only fields explicitly approved for external analysis are transmitted. 3. Parse structured logs as structured data and remove sensitive fields by key rather than relying exclusively on regular expressions. 4. Detect and redact multiline secrets, including PEM-encoded private keys. 5. Require explicit operator consent before sending diagnostic content outside the local environment. 6. Clearly identify the destination provider and the categories of data that may be transmitted. 7. Add unit tests for bypass cases, including bearer tokens, database URLs, cookies, multiline secrets, mixed-case labels, and credentials containing spaces or punctuation. 8. Consider a local-only reasoning mode for environments where diagnostic data cannot leave the host. ]]>
