T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/yotta_logs.py:118
- Finding
- Credential-Bearing URLs Bypass Default Secret Redaction<![CDATA[ ## Vulnerability Details **File Location**: `scripts/yotta_logs.py:118-136` **Vulnerability Type**: Sensitive information disclosure through incomplete output redaction **Risk Level**: Medium ### Vulnerable Code ```python def redact(text): """把疑似密钥 / token / 口令打码(默认开启;--no-redact 关闭)。""" if not text: return text text = _PEM_RE.sub("[PRIVATE KEY REDACTED]", text) text = _URL_USERPASS_RE.sub(r"\1\2:***@", text) chunks = _URL_RE.split(text) # 奇数下标为 URL,原文保留(路径不算密钥) out = [] for i, chunk in enumerate(chunks): if i % 2 == 1: out.append(chunk) continue chunk = _KNOWN_KEY_RE.sub("***", chunk) chunk = _JWT_RE.sub("***", chunk) chunk = _BEARER_RE.sub("Bearer ***", chunk) chunk = _ASSIGN_RE.sub(lambda m: m.group(1) + "=***", chunk) chunk = _LONG_TOKEN_RE.sub("***", chunk) out.append(chunk) return "".join(out) ``` ### Technical Analysis The redaction function divides its input into URL and non-URL chunks using `_URL_RE`. Every URL chunk is then appended directly to the result without applying the known-key, JWT, bearer-token, assignment, or long-token redaction rules. The preceding `_URL_USERPASS_RE` only masks conventional URL user information such as: ```text https://user:password@example.com/ ``` It does not protect secrets stored in URL query parameters, fragments, or path components. For example, the following values can remain visible: ```text https://example.com/callback?token=sk-example-secret https://example.com/api/eyJ...eyJ...signature https://example.com/download/very-long-sensitive-token ``` This behavior conflicts with the documented guarantee that search and session output is redacted by default. Because agent session logs commonly include request URLs, callback URLs, signed download links, and debugging output, the flaw can expose credentials even when the user has not selected `--no-redact`. ### Attack Path 1. A se ...[truncated 1310 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Do not exempt complete URLs from secret detection. Parse each URL and redact its sensitive components before returning it. Recommended hardening steps: 1. Use `urllib.parse.urlsplit`, `parse_qsl`, `urlencode`, and `urlunsplit` to process URLs structurally. 2. Continue masking URL passwords in the authority component. 3. Replace values of sensitive query parameters such as `token`, `key`, `api_key`, `access_token`, `secret`, `signature`, `sig`, `password`, and `auth`. 4. Apply known-key, JWT, bearer-token, and long-token detection to path and fragment components. 5. Preserve ordinary host names and non-sensitive paths so URLs remain useful for historical lookup. 6. Handle malformed URLs conservatively by applying the general redaction expressions to the entire matched value. 7. Add regression tests covering: - API keys in query parameters; - JWTs in paths and fragments; - Signed URLs; - Percent-encoded credentials; - Multiple query parameters; - URL user information; - Benign URLs that should remain readable. A safe implementation should redact the URL before appending it rather than using `out.append(chunk)` directly. ]]>
