T09 · Insecure Skill Coding Practices
- Location
scripts/seedream_image_generate.py:153- Finding
API Bearer Token Disclosed in Console Output
- Content
View full analysis
Vulnerability Details
File Location:
scripts/seedream_image_generate.py, lines 153–162
Vulnerability Type: Plaintext credential exposure through logging
Risk Level: HighVulnerable Code
python # 打印完整请求入参 print("\n" + "="*80) print("📤 完整 API 请求入参:") print("="*80) print(f"URL: {url}") print(f"Headers: {json.dumps(_get_headers(), indent=2, ensure_ascii=False)}") print(f"Request Body: {json.dumps(body, indent=2, ensure_ascii=False)}") print("="*80 + "\n") async with httpx.AsyncClient(timeout=float(timeout)) as client: response = await client.post(url, headers=_get_headers(), json=body)The printed headers are generated by the following code at lines 95–104:
python def _get_headers() -> dict: """ Build API request headers """ if not API_KEY: raise ValueError( "Please set ARK_API_KEY or MODEL_IMAGE_API_KEY or MODEL_AGENT_API_KEY environment variable" ) return { "Content-Type": "application/json", "Authorization": f"Bearer {API_KEY}", }Technical Analysis
The script serializes and prints the complete HTTP header dictionary immediately before making an API request. Because
_get_headers()places the configured API key directly into theAuthorizationheader, the output contains the plaintext bearer token.The credential can consequently be retained in terminal output, CI/CD logs, orchestration logs, monitoring platforms, Agent transcripts, or other systems that capture standard output. The request body is also printed and may expose user prompts, reference-image URLs, and generation settings.
Bearer tokens generally confer access based on possession. An attacker does not need to recover a password or bypass another authentication control after obtaining the logged token.
Attack Path
- An operator configures
ARK_API_KEY,MODEL_IMAGE_API_KEY, orMODEL_AGENT_API_KEY. - The operator or an automated Agent invokes image generation.
- `_g ...[truncated 1065 chars]
- An operator configures
- Remediation
View remediation
Remediation Suggestions
- Remove all logging of complete request headers. Authorization headers must never be written to standard output or routine application logs.
- If diagnostic header logging is necessary, construct a sanitized copy and replace sensitive values before serialization:
python safe_headers = { "Content-Type": "application/json", "Authorization": "Bearer [REDACTED]", } print(f"Headers: {json.dumps(safe_headers, indent=2)}")- Disable verbose URL, header, and request-body logging by default. Place sanitized diagnostics behind an explicit debug option.
- Redact sensitive request-body fields, including prompts and reference-image URLs, or avoid logging the body entirely.
- Rotate any API keys used while the vulnerable logging behavior was active, especially if output was retained by shared terminals, CI systems, Agent transcripts, or centralized logging services.
- Review existing logs and transcripts for exposed keys, restrict access to those records, and delete them according to the applicable retention policy.
- Add automated tests or static-analysis rules that reject logging of
Authorization, API-key, token, and credential values.
