T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/asr.py:13
- Finding
- Unrestricted API endpoint overrides can expose credentials and sensitive content<![CDATA[ ## Vulnerability Details **File Location**: `scripts/asr.py:13-30`, `scripts/feishu_api.py:10-44`, `scripts/config.py:13-14` **Vulnerability Type**: Unvalidated security-sensitive endpoint configuration **Risk Level**: Medium ### Vulnerable Code `scripts/asr.py:13-30`: ```python base_url = get_optional('SENSEAUDIO_BASE_URL', 'https://api.senseaudio.cn').rstrip('/') self.api_url = f'{base_url}/v1/audio/transcriptions' self.api_key = get_required('SENSEAUDIO_API_KEY') self.model = get_optional('SENSEAUDIO_ASR_MODEL', 'sense-asr') def transcribe(self, audio_path: str | Path, language: str | None = 'zh') -> dict[str, Any]: path = Path(audio_path) with path.open('rb') as f: files = {'file': (path.name, f)} data: dict[str, Any] = {'model': self.model, 'response_format': 'json'} if language and self.model != 'sense-asr-deepthink': data['language'] = language resp = requests.post( self.api_url, headers={'Authorization': f'Bearer {self.api_key}'}, data=data, files=files, timeout=120, ) ``` `scripts/feishu_api.py:10-44`: ```python self.base_url = get_optional('FEISHU_BASE_URL', 'https://open.feishu.cn') self.app_id = get_required('FEISHU_APP_ID') self.app_secret = get_required('FEISHU_APP_SECRET') def tenant_access_token(self) -> str: resp = requests.post( f'{self.base_url}/open-apis/auth/v3/tenant_access_token/internal', headers={'Content-Type': 'application/json; charset=utf-8'}, json={'app_id': self.app_id, 'app_secret': self.app_secret}, timeout=30, ) body = resp.json() if not resp.ok or body.get('code', 0) != 0: raise RuntimeError(f'Feishu tenant token request failed: {body}') token = (body.get('tenant_access_token') or '').strip() if not token: raise RuntimeError(f'Feishu tenant token was empty: {body}') return token def send_text_message(self, receive_id ...[truncated 2919 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Parse configured URLs with a standard URL parser before use. 2. Require the `https` scheme for production endpoints. 3. Allow only documented trusted hostnames, such as the official SenseAudio and Feishu hosts, by default. 4. Reject URLs containing embedded credentials, fragments, unexpected ports, or non-network schemes. 5. Disable redirects for credential-bearing requests or validate every redirect target and require the same trusted origin. 6. If custom endpoints are required for development, place them behind an explicit development-only option and display a clear warning that credentials and user content will be transmitted there. 7. Consider separate low-privilege credentials for custom ASR providers. 8. Add automated tests confirming that HTTP, loopback, link-local, private-network, and unapproved external destinations are rejected. ]]>
