T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/agent_skill.py:19
- Finding
- Configurable Authenticated Endpoint and Optional TLS Verification Bypass<![CDATA[ ## Vulnerability Details **File Location**: `scripts/agent_skill.py`, lines 19-24, 95-117, and 662-669 **Vulnerability Type**: Unrestricted authentication endpoint combined with optional TLS verification bypass **Risk Level**: High ### Complete Code Snippet ```python # SSL context — verification ON by default. Opt-out via LOVART_INSECURE_SSL=1 # for users behind corporate proxies/VPNs that do TLS interception. _ssl_ctx = ssl.create_default_context() if os.environ.get("LOVART_INSECURE_SSL") == "1": _ssl_ctx.check_hostname = False _ssl_ctx.verify_mode = ssl.CERT_NONE ``` ```python def _request(self, method: str, path: str, body=None, params=None, retries: int = None) -> dict: if retries is None: retries = 3 if method == "GET" else 1 url = f"{self.base_url}{path}" if params: url += "?" + urllib.parse.urlencode(params) data = json.dumps(body).encode() if body is not None else None last_err = None idempotency_key = uuid.uuid4().hex if method == "POST" else None for attempt in range(retries): # Re-sign on each attempt (timestamp freshness) headers = self._sign(method, path) headers["Content-Type"] = "application/json" headers["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) LovartAgentSkill/1.0" if idempotency_key: headers["Idempotency-Key"] = idempotency_key req = urllib.request.Request(url, data=data, headers=headers, method=method) try: with urllib.request.urlopen(req, timeout=self.timeout, context=_ssl_ctx) as resp: result = json.loads(resp.read().decode()) break ``` ```python # Read from env vars, fall back to CLI args env_base_url = os.environ.get("LOVART_BASE_URL", "https://lgw.lovart.ai") env_ak = os.environ.get("LOVART_ACCESS_KEY", "") env_sk = os.environ.get("LOVART_SECRET_KEY", "") parser = argparse.ArgumentParser(description="Lovart Agent OpenAPI Skill") parse ...[truncated 3396 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Pin the production API origin** - Permit only `https://lgw.lovart.ai`. - Reject HTTP, unexpected ports, user-information components, malformed hostnames, and unapproved subdomains. - If development endpoints are necessary, require an explicit development build or separately protected configuration. 2. **Remove the insecure TLS mode** - Remove `LOVART_INSECURE_SSL`. - For enterprise TLS inspection, support a user-provided CA bundle while retaining certificate and hostname verification. - Never use `ssl.CERT_NONE` in production. 3. **Control redirects** - Disable redirects for authenticated API calls unless required. - If redirects are supported, validate every target against the same HTTPS origin allowlist. - Ensure authentication headers are never forwarded to a different origin. 4. **Protect credentials** - Remove or discourage `--ak` and `--sk`. - Read credentials from a protected environment, operating-system credential store, or file with restrictive permissions. - Avoid printing credentials or including them in exception messages. 5. **Separate network trust contexts** - Use distinct verified SSL contexts for API requests and artifact retrieval. - Do not allow one environment option to disable verification for every outbound connection. 6. **Add startup validation** - Parse the configured URL with `urllib.parse.urlsplit`. - Fail closed before constructing any authenticated request if the origin is not explicitly approved. ]]>
