T09 · Insecure Skill Coding Practices
- Location
scripts/download_video.py:45- Finding
API Key Can Be Transmitted to an Untrusted or Plaintext Backend
- Content
View full analysis
Vulnerability Details
File Location:
scripts/download_video.py:45-48, 77-88, 110-118;scripts/download_video_simple.py:16-22, 30-31, 47-50, 70-74
Vulnerability Type: Unvalidated credential-bearing network destination
Risk Level: MediumVulnerable Code
From
scripts/download_video.py:python def get_base_url(config=None): """获取 API 基础 URL""" if config is None: config = load_config() return config.get("download_tool_base_url", DEFAULT_BASE_URL)python def create_download_task(url, api_key, base_url): endpoint = f"{base_url}/sys/openapi/download" headers = { "Content-Type": "application/json", "X-Api-Key": api_key } data = { "url": url } response = requests.post( endpoint, json=data, headers=headers, timeout=30 )python def check_download_status(task_id, api_key, base_url): endpoint = f"{base_url}/sys/openapi/download/status/{task_id}" headers = { "X-Api-Key": api_key } response = requests.get( endpoint, headers=headers, timeout=30 )The automatically executed script contains the same pattern:
python api_key = config.get('download_tool_api_key') base_url = config.get( 'download_tool_base_url', 'https://www.datamass.cn/ai-back' ) headers = { 'X-Api-Key': api_key, 'Content-Type': 'application/json' } quota_url = f"{base_url}/sys/openapi/quota" response = requests.get(quota_url, headers=headers, timeout=10) download_url = f"{base_url}/sys/openapi/download" data = {"url": video_url} response = requests.post( download_url, json=data, headers=headers, timeout=10 ) status_url = f"{base_url}/sys/openapi/download/status/{task_id}" response = requests.get(status_url, headers=headers, timeout=10)...[truncated 2640 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse
download_tool_base_urlwithurllib.parse.urlparsebefore making any request. - Require the
httpsscheme for remote hosts. - Permit plaintext HTTP only for explicit loopback development addresses such as
127.0.0.1orlocalhost, and require a clearly named opt-in setting. - Allowlist
www.datamass.cnfor normal hosted-service operation. - Require explicit user confirmation before sending credentials to any custom hostname.
- Reject URLs containing embedded credentials, unexpected ports, fragments, malformed hostnames, or non-HTTP schemes.
- Disable automatic redirects for authenticated requests, or validate every redirect destination and remove
X-Api-Keywhenever the hostname changes. - Store the API key in a dedicated credential store or environment-based secret mechanism rather than a general-purpose JSON file.
- Validate that
download_tool_api_keyis present before constructing authenticated headers in both scripts. - Document that a custom backend receives the API key, video URLs, quota requests, and task identifiers.
- Parse
