T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/lib.py:129
- Finding
- Bearer Token Disclosure Through an Unrestricted API Base URL<![CDATA[ ## Vulnerability Details **File Location**: `scripts/lib.py:129-132` and `scripts/lib.py:210-216` **Vulnerability Type**: Unrestricted credential destination and plaintext transport **Risk Level**: High ### Vulnerable Code ```python base_url = _get_env("MINERU_API_BASE_URL") or DEFAULT_BASE_URL if not urlparse(base_url).scheme: base_url = f"https://{base_url}" base_url = base_url.rstrip("/") ``` ```python def _make_client(config: Config) -> httpx.Client: return httpx.Client( timeout=config.timeout, headers={ "Authorization": f"Bearer {config.token}", "Accept": "application/json", "User-Agent": "mineru-ocr-local-api-skill/1.1.0", }, ) ``` ### Technical Analysis `MINERU_API_BASE_URL` accepts an arbitrary scheme and host. HTTPS is added only when the supplied value has no scheme; an explicitly supplied `http://` URL remains permitted. The HTTP client attaches `MINERU_API_TOKEN` as a bearer token to every API request made through that client. Consequently, an attacker who can influence the environment or runtime configuration can redirect authenticated API requests to an attacker-controlled server. If HTTP is selected, the token can also be exposed in plaintext to parties capable of observing or modifying network traffic. Custom API endpoints are a documented feature, but the implementation does not enforce transport security, verify that the destination is trusted, or warn that the production credential will be sent to the configured host. ### Attack Path 1. An attacker influences `MINERU_API_BASE_URL`, such as through a poisoned environment, deployment configuration, or wrapper script. 2. The value is set to `https://attacker.example` or `http://attacker.example`. 3. A user or agent runs the skill in API mode with `MINERU_API_TOKEN` configured. 4. `_make_client()` installs the token in the default `Authorization` header. 5. The skill submits a request to the attacker-control ...[truncated 736 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Require `https` for all API base URLs and reject `http`, file, or other schemes. 2. Allowlist the official MinerU API host by default. 3. If custom endpoints are required, place them behind an explicit opt-in configuration and display a clear warning that credentials will be sent to that host. 4. Validate normalized hostnames and ports before creating the authenticated client. 5. Create authentication headers per request only after destination validation, rather than installing the bearer token as an unconditional client-wide header. 6. Reject URLs containing embedded credentials, unexpected ports, or ambiguous hostname encodings. 7. Rotate any MinerU token that may have been used with an untrusted base URL. ]]>
