T09 · Insecure Skill Coding Practices
- Location
generate.py:87- Finding
API Key and User Content Can Be Sent to an Arbitrary Server
- Content
View full analysis
Vulnerability Details
File Location:
generate.py, lines 87-89, 124-143, and 166-176
Vulnerability Type: Unrestricted credential destination
Risk Level: HighVulnerable 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-urlvalue 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
View remediation
Remediation Suggestions
- Remove
--base-urlfrom normal user-facing operation and use a fixed, reviewed API endpoint. - If custom deployments are necessary, enforce an explicit allowlist of approved HTTPS hostnames.
- Parse the URL with
urllib.parse.urlparseand reject:- Non-HTTPS schemes
- Embedded credentials
- Unexpected ports
- IP literals
- Private, loopback, link-local, or reserved addresses
- Disable automatic redirects for credential-bearing requests with
allow_redirects=False, or validate every redirect destination before following it. - Scope API keys to the minimum service permissions and support rapid key revocation.
- Clearly disclose which endpoint receives prompts, reference URLs, and credentials before submission.
- Remove
