T09 · Insecure Skill Coding Practices
- Location
scripts/generate_video.py:14- Finding
API Key Environment Variable Incorrectly Used as the API Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate_video.py, lines 14-15
Vulnerability Type: Endpoint confusion caused by incorrect secret/configuration variable use
Risk Level: MediumVulnerable Code
python API_KEY = os.environ.get("VIDEO_GEN_API_KEY", "") BASE_URL = os.environ.get("VIDEO_GEN_API_KEY", "https://ark.cn-beijing.volces.com/api/v3")Technical Analysis
BASE_URLis populated fromVIDEO_GEN_API_KEYrather than the documentedVIDEO_GEN_BASE_URLvariable. WhenVIDEO_GEN_API_KEYis configured, the same value is consequently used both as bearer authentication material and as the request URL prefix.Subsequent requests construct their destinations from this incorrect value:
python url = f"{BASE_URL}/video/generations"In a normal configuration, an API key is not a valid URL, so video-generation requests fail. If the value is URL-shaped, however, prompts and selected image data can be transmitted to that URL instead of the intended Volcengine endpoint. Base64 image data may therefore be exposed to an unintended server.
This does not, by itself, demonstrate theft of a valid Volcengine credential: a URL-shaped value used to redirect the request is also the value placed in the authorization header. Nevertheless, it creates an endpoint-confusion flaw, ignores the documented base URL setting, and can cause unauthorized disclosure of submitted prompts or media.
The legitimate network access and Base64 encoding are necessary for the declared remote image-to-video functionality. The vulnerability is the incorrect association between secret and endpoint configuration, not the encoding operation itself.
Attack Path
- An attacker or compromised deployment configuration supplies a URL-shaped value in
VIDEO_GEN_API_KEY, such ashttps://attacker.example. - At module initialization, both
API_KEYandBASE_URLreceive that value. - The user invokes the scrip ...[truncated 1421 chars]
- An attacker or compromised deployment configuration supplies a URL-shaped value in
- Remediation
View remediation
Remediation Suggestions
Read the endpoint from the correct environment variable:
python API_KEY = os.environ.get("VIDEO_GEN_API_KEY", "") BASE_URL = os.environ.get( "VIDEO_GEN_BASE_URL", "https://ark.cn-beijing.volces.com/api/v3", ).rstrip("/")Apply the following additional hardening:
- Parse the configured endpoint with
urllib.parse.urlparse. - Require the
httpsscheme. - Restrict the hostname to the expected Volcengine domain unless custom endpoints are an explicit requirement.
- Reject URLs containing user information, fragments, or unexpected query parameters.
- Keep authentication secrets and endpoint configuration in separate variables and never derive one from the other.
- Add startup validation that reports configuration errors without printing secret values.
- Add tests confirming that
VIDEO_GEN_API_KEYaffects only the authorization header andVIDEO_GEN_BASE_URLaffects only the destination. - Clearly warn users that prompts and selected media are transmitted to the configured remote provider.
- Consider limiting Base64 input size before reading an entire local image into memory and sending it over the network.
- Parse the configured endpoint with
