T09 · Insecure Skill Coding Practices
- Location
scripts/run.py:76- Finding
Unrestricted API Endpoint Can Disclose Credentials and Medical Data
- Content
View full analysis
Vulnerability Details
File Location:
scripts/run.py, lines 76–82, with attacker-controlled configuration accepted at line 204 and passed to the request at lines 260–268
Vulnerability Type: Unrestricted transmission of credentials and sensitive data to a user-configurable endpoint
Risk Level: HighVulnerable Code
python req = Request( api_url, data=json.dumps(payload, ensure_ascii=False).encode("utf-8"), headers={ "Content-Type": "application/json", "Authorization": f"Bearer {appkey}", }, ) resp = urlopen(req, timeout=timeout)The endpoint is exposed as an unrestricted command-line argument:
python p.add_argument("--api-url", default=DEFAULT_API_URL, help="OpenAI compatible endpoint URL")The unvalidated value and sensitive inputs are then passed to
call_llm:python out["answer"] = call_llm( api_url=args.api_url, model=args.model, appkey=args.appkey, system_prompt=args.system_prompt, user_prompt=user_prompt, temperature=float(args.temperature), timeout=int(args.timeout), )Technical Analysis
The
--api-urlargument permits an arbitrary URL, but the program does not validate its scheme, hostname, port, resolved IP address, or redirect destination.call_llmsends anAuthorization: Bearerheader containing the supplied API key and a JSON body containing the complete medical question to this destination.Consequently, an attacker who controls the command invocation, configuration, wrapper script, or instructions copied by a user can redirect the request to an attacker-controlled endpoint. That endpoint receives both the credential and the potentially sensitive clinical content.
The unrestricted URL also creates a server-side request forgery-like primitive in execution environments where the skill has access to internal or loopback services. Actual access remains limited to destinations reachable with the process's existing network privileges. Re ...[truncated 1920 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove
--api-urlif endpoint customization is not a strict functional requirement, and use only the trusted constant endpoint. - If customization is required, validate the parsed URL before constructing the request:
- Require the
httpsscheme. - Permit only explicitly approved hostnames and ports.
- Reject URLs containing embedded credentials.
- Reject loopback, link-local, private, multicast, reserved, and unspecified IP destinations unless explicitly required.
- Require the
- Resolve the hostname and verify every resolved address against the network policy. Account for DNS rebinding by validating the destination used for the actual connection.
- Disable automatic redirects or validate each redirect target against the same scheme, hostname, port, and IP allowlist.
- Ensure the
Authorizationheader is never forwarded when a redirect changes the origin. - Separate credentials by endpoint. Do not send a production API key to any endpoint other than the service for which it was issued.
- Add automated tests confirming rejection of:
- Plain HTTP URLs.
- Unapproved external hosts.
- Loopback and private-network addresses.
- Redirects to unapproved destinations.
- URLs with embedded credentials.
- Continue instructing users to de-identify medical content, but do not rely on documentation as the primary control; enforce trusted destinations in code.
- Revoke and rotate any API key that may previously have been transmitted to an untrusted endpoint.
- Remove
