T09 · Insecure Skill Coding Practices
- Location
scripts/prana_skill_client.py:464- Finding
Configurable Network Endpoint Can Exfiltrate API Credentials, Identity Data, and User Content
- Content
View full analysis
Vulnerability Details
File Location:
scripts/prana_skill_client.py:28, 216-263, 350-368, 407-420, 464-477, 502
Vulnerability Type: Unrestricted credential-bearing network destination
Risk Level: HighVulnerable Code
python DEFAULT_PRANA_BASE = os.environ.get("NEXT_PUBLIC_URL", "https://www.prana.chat/")python def _build_api_keys_fetch_url(base_url: str) -> str: """ 组装 GET /api/v1/api-keys 完整 URL。 查询参数(与 Prana 服务端一致):account_id、email、phone_number;均可从环境变量注入。 若全无则服务端会为随机新用户签发 key(见 api_keys_api.get_api_keys)。 """ root = base_url.rstrip("/") path = f"{root}/api/v1/api-keys" q: Dict[str, str] = {} aid = (os.environ.get("ACCOUNT_ID") or os.environ.get("PRANA_ACCOUNT_ID") or "").strip() if aid: q["account_id"] = aid email = (os.environ.get("PRANA_API_KEYS_EMAIL") or os.environ.get("EMAIL") or "").strip() if email: q["email"] = email phone = ( os.environ.get("PHONE_NUMBER") or os.environ.get("PRANA_PHONE") or os.environ.get("phone_number") or "" ).strip() if phone: q["phone_number"] = phone if q: path = f"{path}?{urlencode(q)}" return path def fetch_prana_api_keys_via_get(base_url: str) -> Optional[Tuple[str, str]]: """ 调用 Prana GET /api/v1/api-keys(无需 JWT),解析 data.api_key 的 public_key、secret_key。 """ url = _build_api_keys_fetch_url(base_url) req = urllib.request.Request(url, method="GET") try: with urllib.request.urlopen(req, timeout=API_KEYS_FETCH_TIMEOUT_SEC) as resp: text = resp.read().decode("utf-8")python base = (prana_base_url or os.environ.get("NEXT_PUBLIC_URL") or DEFAULT_PRANA_BASE or "").strip() if base and not _is_mock_mode() and not _auto_fetch_api_key_disabled(): fetched = fetch_prana_api_keys_via_get(base) if fetched: pub, ...[truncated 4399 chars]- Remediation
View remediation
Remediation Suggestions
- Pin production requests to an explicit allowlist of trusted HTTPS origins, such as the official Prana API hostname.
- If custom deployments are required, disable custom endpoints by default and require a deliberate development or enterprise opt-in.
- Parse the URL before use and reject unsupported schemes, embedded credentials, malformed hosts, unexpected ports, fragments, and non-HTTPS production URLs.
- Apply the same destination validation to initial requests, fallback result requests, and automatic credential acquisition.
- Restrict or disable cross-origin redirects for requests carrying credentials. Revalidate the destination after every redirect and never forward
x-api-keyto a different origin. - Stop reading generic
EMAIL,PHONE_NUMBER,phone_number, andACCOUNT_IDenvironment variables. Use only namespaced variables such asPRANA_ACCOUNT_ID,PRANA_EMAIL, andPRANA_PHONE. - Require explicit user consent before transmitting identity attributes or the contents of a user message.
- Clearly disclose in the Skill description that all submitted task content is processed by a remote service.
- Consider separating credential acquisition from Skill invocation so routine execution cannot silently collect identity data or create credentials.
- Add automated tests confirming that untrusted hosts, plain HTTP URLs, and cross-origin redirects are rejected before any credential or user content is transmitted.
