T09 · Insecure Skill Coding Practices
Error
- Location
- index.py:73
- Finding
- Configurable API Endpoints Can Exfiltrate Bearer Credentials<![CDATA[ ## Vulnerability Details **File Location**: `index.py`, lines 73-108 **Vulnerability Type**: Unvalidated credential-bearing network destinations **Risk Level**: High ### Vulnerable Code ```python def render_image(self, text): """Generate image via Templated.io""" tpl_info = self.tpl_cfg.get('templates', {}).get(self.brand, {}) tpl_id = tpl_info.get('template_id') if not tpl_id: print("No template configured") return None headers = { "Authorization": f"Bearer {self.tpl_cfg.get('api_key')}", "Content-Type": "application/json" } data = { "template": tpl_id, "layers": {"text": {"text": text[:150]}}, "file_type": "png" } try: r = requests.post( self.tpl_cfg.get('endpoint', 'https://api.templated.io/v1/render'), headers=headers, json=data, timeout=60 ) ``` ```python def publish_post(self, image_data, caption): """Publish via UploadPost API""" headers = {"Authorization": f"Bearer {self.upload_cfg.get('api_key')}"} files = {"photos": ("post.png", image_data, "image/png")} data = {"caption": caption} try: r = requests.post( self.upload_cfg.get('endpoint', 'https://api.upload-post.com/api/upload_photos'), headers=headers, files=files, data=data, timeout=60 ) return r.json() ``` ### Technical Analysis The Templated.io and UploadPost destinations are obtained directly from externally supplied JSON configuration files. The implementation sends bearer credentials to these destinations without validating the URL scheme, hostname, port, resolved address, or redirect destination. Although communication with these APIs is necessary for the declared social-media publishing functionality, allowing credential-bearing requests to arbitrary configurable hosts exceeds minimum privilege. Anyone able to provide or modify either configuration file can replace an expected A ...[truncated 1573 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove endpoint overrides from untrusted runtime configuration and use fixed constants for the production API origins. 2. If custom endpoints are operationally required, enforce exact HTTPS allowlists, such as `api.templated.io` and `api.upload-post.com`. 3. Reject non-HTTPS schemes, embedded URL credentials, fragments, unexpected ports, malformed hostnames, and hosts outside the allowlist. 4. Disable redirects for credential-bearing requests with `allow_redirects=False`, or validate every redirect destination before following it. 5. Separate endpoint configuration from secret configuration and restrict both files with least-privilege filesystem permissions. 6. Use provider-scoped, minimally privileged API keys and rotate all credentials if an untrusted configuration may already have been used. 7. Store credentials in a secret manager or protected environment variables rather than in general-purpose JSON configuration. 8. Add tests confirming that attacker-controlled endpoints, alternate ports, subdomain tricks, and HTTP URLs are rejected before an authorization header is created or transmitted. ]]>
