T09 · Insecure Skill Coding Practices
- Location
scripts/yufluent_api.py:19- Finding
Bearer Credential and Business Data Can Be Sent to an Arbitrary Insecure Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/yufluent_api.py:19-24, 49-61, 126-140, 218-221
Vulnerability Type: Arbitrary endpoint selection and plaintext transmission of sensitive data
Risk Level: HighComplete Code Snippet
python def normalize_api_root(base_url: str) -> str: base = (base_url or "").strip().rstrip("/") if not base: base = "http://localhost:8080/v1" if base.endswith("/v1"): return base return f"{base}/v1"python def _auth_headers(api_key: str) -> dict[str, str]: return { "Authorization": f"Bearer {api_key}", "Accept": "application/json", } def _json_headers(api_key: str) -> dict[str, str]: return {**_auth_headers(api_key), "Content-Type": "application/json"}python def _post_json( url: str, *, api_key: str, body: dict[str, Any] | None = None, timeout: float, ) -> requests.Response: kwargs: dict[str, Any] = { "headers": _json_headers(api_key) if body is not None else _auth_headers(api_key), "timeout": timeout, } if body is not None: kwargs["json"] = body return requests.post(url, **kwargs)python root = base_url or os.getenv("TOKENAPI_BASE_URL", "") url = skill_run_url(root, skill_id) try: resp = _post_json(url, api_key=key, body=payload, timeout=timeout)Technical Analysis
The client obtains its destination from the caller-controlled
base_urlargument or theTOKENAPI_BASE_URLenvironment variable. It accepts any host and scheme without requiring TLS, restricting destinations to an approved service, or validating redirect destinations.The same request includes the
TOKENAPI_KEYas a bearer credential and sends the complete optimization payload. That payload may contain campaign metrics, product information, target markets, advertising goals, and additional business context.Although transmitting these inputs to a cloud service is consistent with the Skill ...[truncated 2124 chars]
- Remediation
View remediation
Remediation Suggestions
- Require
https://for every non-loopback endpoint. Permit plaintext HTTP only for explicit development mode and only for loopback addresses such as127.0.0.1,::1, or a strictly validatedlocalhost. - Allowlist the documented production API hostname and reject arbitrary hosts by default.
- Parse URLs with a standard URL parser and reject unsupported schemes, embedded credentials, malformed ports, fragments, and ambiguous host representations.
- Disable automatic redirects for authenticated requests, or manually follow redirects only after verifying that the destination remains HTTPS and belongs to the approved hostname set.
- Never forward the
Authorizationheader across origins. - Separate production and development endpoint configuration. Avoid silently defaulting security-sensitive production use to an HTTP URL.
- Display or log the selected destination without exposing the token, allowing users to verify where sensitive data will be sent.
- Apply narrowly scoped, revocable, and short-lived API tokens where supported. Server-side authorization should constrain each token to only the operations required by this Skill.
- Document that campaign metrics and business context are transmitted to the cloud service and obtain user confirmation before transmitting especially sensitive inputs.
- Add tests covering malicious environment values, non-HTTPS destinations, cross-origin redirects, URL parsing edge cases, and authorization-header stripping.
- Require
