T09 · Insecure Skill Coding Practices
- Location
cloud_transcriber.py:25- Finding
Cross-provider disclosure of an OpenAI API credential to Alibaba DashScope
- Content
View full analysis
str: """获取 API Key(优先 DASHSCOPE_API_KEY,其次 OPENAI_API_KEY)""" key = os.environ.get("DASHSCOPE_API_KEY") or os.environ.get("OPENAI_API_KEY") if not key: raise ValueError( "未找到 API Key,请设置环境变量 DASHSCOPE_API_KEY 或 OPENAI_API_KEY\n" "例如: export DASHSCOPE_API_KEY=sk-xxxxxxxx" ) return key ``` ```python policy_url = "https://dashscope.aliyuncs.com/api/v1/uploads" headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } params = { "action": "getPolicy", "model": model } resp = requests.get(policy_url, headers=headers, params=params, timeout=30) ``` ```python submit_url = "https://dashscope.aliyuncs.com/api/v1/services/audio/asr/transcription" headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json", "X-DashScope-Async": "enable", "X-DashScope-OssResourceResolve": "enable" } request_body = { "model": model, "input": { "file_urls": [oss_url] }, "parameters": { "language_hints": language_hints or ["zh"] } } resp = requests.post(submit_url, headers=headers, json=request_body, timeout=30) ``` The URL-based transcription path repeats this behavior: ```python api_key = api_key or _get_api_key() submit_url = "https://dashscope.aliyuncs.com/api/v1/services/audio/asr/transcription" headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json", "X-DashScope-Async": "enable" } ``` ### Technical Analysis The credential selection function treats `OPENAI_API_KEY` as a fallback for `DASHSCOPE_API_KEY`. However, every authenticated request made by this module targe ...[truncated 1841 chars]- Remediation
View remediation
str: key = os.environ.get("DASHSCOPE_API_KEY") if not key: raise ValueError( "DASHSCOPE_API_KEY is required for Alibaba DashScope transcription." ) return key ``` 2. Bind credentials explicitly to providers. If additional providers are supported later, use separate clients, endpoints, and credential variables for each provider. 3. Update `README.md` and `SKILL.md` to remove all instructions suggesting that `OPENAI_API_KEY` can be used as a DashScope credential. 4. Require callers supplying `api_key` directly to select or confirm the intended provider. 5. Avoid including credentials in exceptions, debug logs, or telemetry. 6. Advise affected users who previously invoked this fallback to rotate their OpenAI API keys and review account usage. ]]>
