T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/ima_runtime/shared/client.py:16
- Finding
- Bearer API Credential Can Be Redirected to an Arbitrary Endpoint<![CDATA[ ## Vulnerability Details **File Location**: `scripts/ima_runtime/cli_parser.py:36`, `scripts/ima_runtime/cli_flow.py:235-258`, `scripts/ima_runtime/shared/client.py:16-22, 84-91, 163-168, 190-195` **Vulnerability Type**: Credential disclosure through an unrestricted API endpoint **Risk Level**: High ### Vulnerable Code ```python # scripts/ima_runtime/cli_parser.py parser.add_argument("--base-url", default=DEFAULT_BASE_URL, help="API base URL") ``` ```python # scripts/ima_runtime/cli_flow.py def run_cli(args, logger) -> int: api_key = args.api_key or os.getenv("IMA_API_KEY") if not api_key: return _fail("API key is required. Use --api-key or set IMA_API_KEY.") # ... if args.list_models: try: tree = get_product_list( args.base_url, api_key, args.task_type, language=args.language, ) except Exception as exc: return _fail(str(exc)) ``` ```python # scripts/ima_runtime/shared/client.py def make_headers(api_key: str, language: str = "en") -> dict: return { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json", "x-app-source": "ima_skills", "x_app_language": language, } ``` ```python def get_product_list( base_url: str, api_key: str, category: str, app: str = "ima", platform: str = "web", language: str = "en", ) -> list: response = requests.get( f"{base_url}/open/v1/product/list", params={"app": app, "platform": platform, "category": category}, headers=make_headers(api_key, language), timeout=30, ) ``` ```python response = requests.post( f"{base_url}/open/v1/tasks/create", json=payload, headers=make_headers(api_key), timeout=30, ) ``` ```python response = requests.post( f"{base_url}/open/v1/tasks/detail", json={"task_id": task_id}, headers=make_headers(api_key), ...[truncated 2013 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Allowlist the production API origin, including the exact scheme, hostname, and permitted port: - Scheme: `https` - Host: `api.imastudio.com` - Port: default HTTPS port only 2. Reject URL user information, fragments, non-HTTPS schemes, IP-literal hosts, and unexpected ports. 3. Disable custom base URLs in normal operation. 4. If custom endpoints are required for development, place them behind an explicit option such as `--allow-unsafe-development-endpoint`. 5. Never forward a production API key to a custom endpoint. Require a separate development credential. 6. Disable redirects for authenticated API requests, or validate the destination of every redirect before retaining the authorization header. 7. Ignore `IMA_BASE_URL` in privileged or automated production execution unless it passes the same validation. 8. Add tests confirming that bearer credentials are never sent to unapproved origins. ]]>
