T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/local_file_step1_apply_upload_url.sh:27
- Finding
- Unvalidated API Base URL Can Redirect Bearer Credentials to an Attacker-Controlled Server<![CDATA[ ## Vulnerability Details **File Locations**: - `scripts/local_file_step1_apply_upload_url.sh:27-29,94-98` - `scripts/local_file_step3_poll_result.sh:7-9,41-43` - `scripts/online_file_step1_submit_task.sh:27-29,95-99` - `scripts/online_file_step2_poll_result.sh:23-25,62-64` **Vulnerability Type**: Credential disclosure through an unvalidated configurable endpoint **Risk Level**: High ### Vulnerable Code ```bash # Support MINERU_TOKEN or MINERU_API_KEY environment variables MINERU_TOKEN="${MINERU_TOKEN:-${MINERU_API_KEY:-}}" MINERU_BASE_URL="${MINERU_BASE_URL:-https://mineru.net/api/v4}" ``` The configured endpoint is subsequently used with the bearer credential: ```bash RESPONSE=$(curl -s -X POST "${MINERU_BASE_URL}/file-urls/batch" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer ${MINERU_TOKEN}" \ -d "$JSON_PAYLOAD") ``` The same pattern is present in the polling and online-submission scripts: ```bash RESPONSE=$(curl -s -X GET "${MINERU_BASE_URL}/extract-results/batch/${BATCH_ID}" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer ${MINERU_TOKEN}") ``` ```bash RESPONSE=$(curl -s -X POST "${MINERU_BASE_URL}/extract/task" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer ${MINERU_TOKEN}" \ -d "$JSON_PAYLOAD") ``` ```bash RESPONSE=$(curl -s -X GET "${MINERU_BASE_URL}/extract/task/${TASK_ID}" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer ${MINERU_TOKEN}") ``` ### Technical Analysis `MINERU_BASE_URL` is read directly from the process environment without validating its scheme, hostname, port, or path. Every authenticated API request sends `MINERU_TOKEN` or `MINERU_API_KEY` to this address in an `Authorization: Bearer` header. Environment-based endpoint configuration can be useful for testing or private deployments, but attaching a sensitive credential to an arbitrary endpoint violates least-trust principles. A malicious wrapper, compromise ...[truncated 1499 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Enforce the official endpoint by default and do not expose arbitrary endpoint replacement in normal operation: ```bash MINERU_BASE_URL="https://mineru.net/api/v4" ``` 2. If custom deployments must be supported, require an explicit opt-in and validate the endpoint with a strict allowlist: ```bash case "$MINERU_BASE_URL" in "https://mineru.net/api/v4") ;; *) echo "Error: Unapproved MinerU API endpoint" >&2 exit 1 ;; esac ``` 3. Require HTTPS and reject embedded credentials, unexpected ports, fragments, and malformed hosts. Use a proper URL parser where possible rather than a permissive shell regular expression. 4. Use separate credentials for custom or test endpoints. Never send the production MinerU token to an endpoint merely because it was supplied through an environment variable. 5. Add `curl` hardening such as `--proto '=https' --fail-with-body --show-error` and reasonable connection and request timeouts. 6. Document that overriding an authenticated service endpoint is security-sensitive, and avoid inheriting the variable from untrusted job or wrapper environments. ]]>
