T09 · Insecure Skill Coding Practices
- Location
scripts/douyin_search.py:88- Finding
Unconditional Logging of Raw API Response Data
- Content
View full analysis
Vulnerability Details
File Location:
scripts/douyin_search.py, lines 88–89
Vulnerability Type: Uncontrolled exposure of API response data through debug output
Risk Level: LowComplete Code Snippet:
python resp = requests.post(TIKHUB_SEARCH_URL, json=payload, headers=headers, timeout=30) print(f"DEBUG: status_code={resp.status_code}") print(f"DEBUG: response_text={resp.text[:500]}") resp.raise_for_status()Technical Analysis
The script unconditionally prints the first 500 characters of every TikHub API response to standard output. This occurs regardless of whether the user requested raw output with
--raw.API responses may contain search data, provider diagnostics, request identifiers, account-related metadata, or detailed error information. Printing the raw response bypasses the script's normal formatting and data-minimization behavior. It can also contaminate output expected to contain only formatted text or JSON, causing downstream parsers to fail.
The bearer token itself is placed in the HTTPS
Authorizationheader and is not directly printed by the shown code. Sending it to the fixed TikHub endpoint is necessary for the declared API-backed search functionality. The confirmed issue is the unnecessary disclosure of response content after the request.Attack Path
- A user or Agent invokes the script to perform a TikHub search.
- TikHub, an intermediary affecting the response, or an abnormal upstream condition causes sensitive, attacker-controlled, or misleading information to appear within the first 500 response characters.
- Lines 88–89 print that content to standard output without requiring a debug option.
- An Agent transcript, automation pipeline, terminal logger, or centralized log collector records the output.
- Anyone with access to those records may obtain the exposed response data. In addition, attacker-controlled response text may mislead consumers that treat co ...[truncated 721 chars]
- Remediation
View remediation
Remediation Suggestions
-
Remove the unconditional debug statements:
python # Remove these statements: # print(f"DEBUG: status_code={resp.status_code}") # print(f"DEBUG: response_text={resp.text[:500]}") -
If diagnostics are operationally necessary, require an explicit
--debugoption and send diagnostics to standard error so standard output remains machine-readable. -
Log only minimal metadata, such as the HTTP status code and response length. Do not log raw response bodies by default:
python if debug: print( f"DEBUG: status_code={resp.status_code}, " f"response_length={len(resp.content)}", file=sys.stderr, ) -
Redact authorization values, tokens, cookies, request identifiers, and account metadata from any optional diagnostic output.
-
Keep verbose logs disabled by default and document that enabling them may expose API-returned data.
-
Add tests verifying that normal and
--rawmodes produce no unsolicited debug prefixes or response excerpts.
-
