T09 · Insecure Skill Coding Practices
- Location
scripts/gpt_image2.py:95- Finding
Unrestricted API Endpoint Can Expose Credentials and Sensitive Image Data
- Content
View full analysis
Vulnerability Details
File Location:
scripts/gpt_image2.py, lines 95–106, 170–221, 251, and 303
Vulnerability Type: Unvalidated destination URL and transmission of bearer credentials
Risk Level: HighVulnerable Code
python def get_base_url(cli_value: str | None = None, config: dict | None = None) -> str: """Priority: CLI > config.base_url > GPT_IMAGE2_BASE_URL env > default""" if cli_value: return cli_value.rstrip("/") if config is None: config = {} if config.get("base_url"): return config["base_url"].rstrip("/") env_val = os.environ.get("GPT_IMAGE2_BASE_URL", "") if env_val: return env_val.rstrip("/") return DEFAULT_BASE_URLpython def _curl_auth_header(api_key: str) -> str: """Write Authorization header to a temp curl-config file. Caller must unlink.""" fd, path = tempfile.mkstemp(suffix=".headers") with os.fdopen(fd, "w") as f: f.write(f'-H "Authorization: Bearer {api_key}"\n') return pathpython url = f"{base_url}/images/generations"python url = f"{base_url}/images/edits"Technical Analysis
The API base URL can originate from the
--base-urlargument, a configuration file, or theGPT_IMAGE2_BASE_URLenvironment variable. The value is used without validating its scheme, hostname, port, embedded credentials, or trust level.Every request to the resulting endpoint includes an
Authorization: Bearerheader containing the resolved API key. Generation requests also transmit the prompt, while edit requests can transmit the prompt, source image, and mask. Consequently, a malicious or accidentally unsafe endpoint receives both the credential and potentially private user content.In particular, the implementation permits:
- Plain HTTP endpoints, exposing credentials and content to network interception.
- Arbitrary attacker-controlled HTTPS host ...[truncated 1673 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse the endpoint with
urllib.parse.urlparseand reject malformed URLs. - Require the
httpsscheme. Permit plain HTTP only through an explicit, prominently warned development-only option. - Use an allowlist containing the official API hostname by default.
- Require explicit user confirmation or a dedicated
--allow-third-party-endpointoption before sending credentials to other hosts. - Reject URLs containing embedded usernames or passwords, fragments, control characters, and unsupported schemes.
- Consider binding credentials to specific endpoints so an OpenAI credential is never automatically sent to a relay host.
- Document that custom endpoints receive prompts, credentials, source images, and masks.
- Add automated tests covering HTTP URLs, malformed URLs, embedded credentials, unexpected ports, redirects, and unapproved hosts.
- Consider disabling or tightly controlling redirects so a trusted endpoint cannot redirect an authenticated request to an untrusted destination.
- Parse the endpoint with
