T09 · Insecure Skill Coding Practices
Error
- Location
- generate.py:87
- Finding
- API Key and User Content Can Be Sent to an Arbitrary Server## Vulnerability Details **File Location**: `generate.py`, lines 87-89, 124-143, and 166-176 **Vulnerability Type**: Unrestricted credential destination **Risk Level**: High ### Vulnerable Code ```python parser.add_argument("--base-url", default="https://grsai.dakka.com.cn", help="grsai API 基础 URL(默认:https://grsai.dakka.com.cn)") ``` ```python def submit_task(args): """提交生图任务""" url = f"{args.base_url}/v1/draw/nano-banana" payload = { "model": args.model, "prompt": args.prompt, "imageSize": args.resolution, "aspectRatio": args.aspect_ratio, "webHook": "-1", "shutProgress": False } if args.input_images: payload["urls"] = args.input_images headers = { "Authorization": f"Bearer {args.api_key}", "Content-Type": "application/json" } try: response = requests.post(url, json=payload, headers=headers, timeout=30) ``` ```python def poll_result(args, task_id): """轮询生图结果""" url = f"{args.base_url}/v1/draw/result" headers = { "Authorization": f"Bearer {args.api_key}", "Content-Type": "application/json" } for attempt in range(1, args.max_retries + 1): try: response = requests.post( url, json={"id": task_id}, headers=headers, timeout=30 ) ``` ### Technical Analysis The user-controlled `--base-url` value is directly incorporated into both API request URLs. No hostname allowlist, scheme restriction, certificate policy beyond the library default, or destination validation is applied before attaching the bearer token. Consequently, the script can send the following sensitive information to any destination selected through `--base-url`: - The grsai bearer API key - The complete im ...[truncated 1658 chars]
- Remediation
- ## Remediation Suggestions 1. Remove `--base-url` from normal user-facing operation and use a fixed, reviewed API endpoint. 2. If custom deployments are necessary, enforce an explicit allowlist of approved HTTPS hostnames. 3. Parse the URL with `urllib.parse.urlparse` and reject: - Non-HTTPS schemes - Embedded credentials - Unexpected ports - IP literals - Private, loopback, link-local, or reserved addresses 4. Disable automatic redirects for credential-bearing requests with `allow_redirects=False`, or validate every redirect destination before following it. 5. Scope API keys to the minimum service permissions and support rapid key revocation. 6. Clearly disclose which endpoint receives prompts, reference URLs, and credentials before submission.
