T09 · Insecure Skill Coding Practices
- Location
references/code-examples.md:42- Finding
Unvalidated WebSocket Endpoint May Expose the Azure OpenAI API Key
- Content
View full analysis
Vulnerability Details
File Location:
references/code-examples.md:42-44
Vulnerability Type: Unvalidated credential destination
Risk Level: Mediumpython ws_url = settings.azure_openai_audio_endpoint.replace("https://", "wss://") + "/openai/v1" client = AsyncOpenAI(websocket_base_url=ws_url, api_key=settings.azure_openai_audio_api_key)Technical Analysis
The example obtains the service endpoint from configuration and passes the resulting WebSocket URL to an authenticated client without validating its scheme, hostname, port, or ownership. String replacement is not a security boundary and does not ensure that the destination is a legitimate Azure OpenAI resource.
If an attacker can modify
AZURE_OPENAI_AUDIO_ENDPOINTor its corresponding application setting, the application may connect to an attacker-controlled WebSocket server while supplying Azure authentication information. Configuration control is required for exploitation, but deployments commonly expose environment configuration through CI/CD variables, container settings, deployment manifests, or administrative interfaces.The same unsafe pattern is also documented in
SKILL.md:34-41andreferences/acceptance-criteria.md:33-42.Attack Path
- An attacker gains the ability to influence the configured Azure OpenAI audio endpoint, such as through a compromised deployment variable, manifest, or configuration interface.
- The attacker changes the endpoint to an attacker-controlled TLS-enabled host.
- A user or scheduled application workflow starts podcast generation.
- The code converts the configured URL into a WebSocket URL and initializes
AsyncOpenAIwith the genuine API key. - The client connects to the malicious endpoint and may transmit authentication material to that endpoint.
- The attacker captures the credential and attempts to use it against the associated Azure resource until it is revoked or expires.
Impact As
...[truncated 580 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse the endpoint with a standard URL parser rather than using string replacement.
- Require the original scheme to be
httpsand the generated scheme to bewss. - Reject URLs containing user information, fragments, unexpected query parameters, or non-approved ports.
- Allowlist the exact Azure resource hostname or a tightly controlled set of expected Azure domains, with appropriate checks that prevent deceptive suffixes.
- Keep endpoint configuration in a protected deployment secret or trusted configuration store with restricted write access and audit logging.
- Use a narrowly scoped, rotatable credential or managed identity where supported.
- Avoid logging API keys or authenticated WebSocket headers.
- Fail closed if endpoint validation fails, and add tests covering malicious hosts, malformed URLs, alternate schemes, and hostname-suffix bypasses.
