T09 · Insecure Skill Coding Practices
- Location
gen_image.js:15- Finding
TLS Certificate Verification Disabled for API Requests
- Content
View full analysis
Vulnerability Details
File Location:
gen_image.js:15-19
Vulnerability Type: Improper certificate validation
Risk Level: HighVulnerable Code
javascript const client = new OpenAI({ apiKey: apiKey, baseURL: process.env.BASE_URL || process.env.API_BASE_URL || 'https://api.openai.com/v1', httpAgent: new https.Agent({ rejectUnauthorized: false }) });Technical Analysis
The HTTPS agent is configured with
rejectUnauthorized: false, which disables validation of the server's TLS certificate. The client consequently cannot reliably authenticate the API server.An attacker capable of intercepting network traffic, controlling a proxy, manipulating DNS, or presenting a forged certificate could terminate the TLS connection without possessing a certificate trusted by the host. Requests made through the OpenAI client may contain the API key in an authorization header, as well as the user's image-generation prompt.
This condition is especially dangerous because the same client configuration supports an environment-controlled API base URL.
Attack Path
- A victim invokes
gen_image.json an attacker-controlled network or through a malicious proxy. - The attacker intercepts the connection and presents an arbitrary or forged TLS certificate.
- The script accepts the certificate because verification is disabled.
- The OpenAI client sends the API request, including the API credential and prompt, through the intercepted connection.
- The attacker captures the credential and prompt and may return a manipulated API response.
- The stolen credential can be reused within the permissions and usage limits associated with that API key.
Impact Assessment
Successful exploitation may disclose the OpenAI API key and private user prompts. The attacker could consume the victim's API quota, incur charges, access API resources authorized to the key, or manipulate the generated response.
...[truncated 196 chars]
- A victim invokes
- Remediation
View remediation
Remediation Suggestions
Remove the custom agent so that the Node.js runtime performs standard certificate validation:
javascript const client = new OpenAI({ apiKey, baseURL: 'https://api.openai.com/v1' });If a private certificate authority is operationally required, configure an explicit trusted CA certificate instead of disabling validation globally. Production deployments should also:
- Require HTTPS for every configured API endpoint.
- Keep the operating system and Node.js trust stores current.
- Avoid global TLS bypasses such as
NODE_TLS_REJECT_UNAUTHORIZED=0. - Rotate the API key if the vulnerable implementation has operated on untrusted networks.
- Use a restricted API key with appropriate usage and spending limits.
