T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/common.py:188
- Finding
- <![CDATA[HTTPS and credential-boundary validation is not enforced across redirects]]><![CDATA[ ## Vulnerability Details **File Location**: `scripts/common.py:40-49, 188-201` **Vulnerability Type**: Improper redirect handling for credential-bearing HTTP requests **Risk Level**: Medium ### Vulnerable Code ```python def get_base_url() -> str: url = os.environ.get("MODORA_BASE_URL", DEFAULT_BASE_URL).rstrip("/") parsed = urllib.parse.urlparse(url) hostname = (parsed.hostname or "").lower() is_local = hostname in {"127.0.0.1", "localhost", "::1"} if not is_local and parsed.scheme != "https": raise SystemExit( f"Security error: remote MoDora endpoints must use HTTPS. Current value: {url}" ) return url ``` ```python def request_json( method: str, url: str, data: bytes | None = None, headers: dict[str, str] | None = None, timeout: int = 60, ) -> object: req = urllib.request.Request(url, data=data, method=method) for key, value in (headers or {}).items(): req.add_header(key, value) try: with urllib.request.urlopen(req, timeout=timeout) as resp: return parse_json_bytes(resp.read()) ``` Upload and chat requests pass credentials through this function: ```python headers={ "Content-Type": f"multipart/form-data; boundary={boundary}", **get_credential_headers(), **SKILL_HEADERS, }, ``` ### Technical Analysis `get_base_url()` validates only the initially configured URL. It requires HTTPS for a non-local hostname, but `urllib.request.urlopen()` follows redirects automatically without invoking `get_base_url()` for each redirect destination. Consequently, an initially valid HTTPS endpoint can redirect a request to: - A plaintext HTTP URL, bypassing the documented transport requirement. - A different origin that has not been approved by the user. - An attacker-controlled host. The affected upload and chat requests contain sensitive headers, including `Authorization: Bearer <API key>`, `X-Modora-Endpoint`, `X-Modora-Model`, and `X- ...[truncated 1409 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Disable automatic redirects for upload and chat requests that contain credentials. 2. If redirects are operationally required, implement a custom `HTTPRedirectHandler` that: - Rejects every HTTPS-to-HTTP redirect. - Rejects redirects to a different hostname or port. - Revalidates the scheme and destination at every redirect. - Enforces a small maximum redirect count. 3. Remove `Authorization` and all credential-bearing `X-Modora-*` headers before any redirect unless the destination is proven to be the exact same trusted origin. 4. Prefer failing closed and requiring the user to configure the final service URL directly. 5. Add automated tests for same-origin redirects, cross-origin redirects, redirect loops, and HTTPS-to-HTTP downgrade attempts. ]]>
