T09 · Insecure Skill Coding Practices
- Location
- scripts/make-pdf-safe.py:187
- Finding
- Arbitrary API Endpoint Override Exposes PDF Content and Bearer Credentials<![CDATA[ ## Vulnerability Details **File Location**: `scripts/make-pdf-safe.py:30`, `scripts/make-pdf-safe.py:35`, `scripts/make-pdf-safe.py:57-61`, `scripts/make-pdf-safe.py:79-83`, and `scripts/make-pdf-safe.py:187-189` **Vulnerability Type**: Unrestricted destination override for sensitive network requests **Risk Level**: High ### Vulnerable Code ```python DEFAULT_BASE_URL = "https://api.xss-cross-service-solutions.com/solutions/solutions" CREATE_PATH = "/api/41" def make_headers(api_key: str) -> Dict[str, str]: return {"Authorization": f"Bearer {api_key}"} ``` ```python url = base_url.rstrip("/") + CREATE_PATH headers = make_headers(api_key) with open(pdf_path, "rb") as f: files = {"file": (os.path.basename(pdf_path), f, "application/pdf")} resp = requests.post(url, headers=headers, files=files, timeout=timeout_s) ``` ```python url = base_url.rstrip("/") + f"/api/{job_id}" headers = make_headers(api_key) resp = requests.get(url, headers=headers, timeout=timeout_s) ``` ```python ap.add_argument( "--base-url", default=os.getenv("SOLUTIONS_BASE_URL", DEFAULT_BASE_URL), help="Base URL override", ) ``` ### Technical Analysis The script permits the API destination to be overridden through either the `--base-url` argument or the `SOLUTIONS_BASE_URL` environment variable. It does not validate the URL scheme, hostname, port, or path before attaching the Bearer credential and uploading the complete PDF. The declared functionality only requires communication with the documented Solutions API host. Allowing an unrestricted destination therefore exceeds the minimum network privilege necessary for the Skill. An attacker who can influence command arguments, environment variables, a wrapper script, or deployment configuration can redirect requests to an attacker-controlled endpoint. That endpoint receives: - The complete PDF document in a multipart upload. - The Solutions API Bearer credential in the `Authorization` header. - Subsequen ...[truncated 1579 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove `--base-url` and `SOLUTIONS_BASE_URL` if alternate service endpoints are not essential. 2. If endpoint configuration is required, parse the URL and enforce: - The `https` scheme. - An exact allowlisted hostname. - The expected port. - A controlled path prefix. - No embedded username or password. 3. Reject IP literals, loopback addresses, link-local addresses, and private-network destinations unless explicitly required. 4. Disable automatic redirects or validate every redirect target before forwarding the Authorization header. 5. Never forward credentials across origins. 6. Separate endpoint selection from credential use so credentials are issued only to a trusted, configured service identity. 7. Clearly notify users before uploading a document to a third party and identify the exact destination. 8. Add automated tests proving that HTTP URLs, unapproved hosts, deceptive subdomains, and cross-origin redirects are rejected. ]]>
