T09 · Insecure Skill Coding Practices
- Location
scripts/grok_video_api.py:15- Finding
Bearer Credential Disclosure Through an Unvalidated API Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/grok_video_api.py, lines 15-27 and 51-52; the same authorization behavior is used at lines 81-82, 111-112, 143-144, 176-177, and 211-212.
Vulnerability Type: Credential disclosure through an unvalidated network destination
Risk Level: MediumVulnerable Code
python def __init__(self, api_key: str, base_url: str = "https://api.x.ai/v1"): """ Initialize the client. Args: api_key: xAI API key from environment or config base_url: API base URL (default: https://api.x.ai/v1) """ self.api_key = api_key self.base_url = base_url self.headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" }python url = f"{self.base_url}/videos/generations" response = requests.post(url, headers=self.headers, json=payload)Technical Analysis
The constructor accepts an arbitrary
base_urland then creates a reusable authorization header containing the caller's xAI API key. Every authenticated API operation sends that header to a URL derived from the configurable base URL.The default destination,
https://api.x.ai/v1, is appropriate and transmission of the key to xAI is necessary for the declared functionality. However, the implementation does not require HTTPS, validate the hostname, or restrict the destination to xAI. Consequently, any party capable of influencing client construction can redirect authenticated requests to an attacker-controlled server.The same issue affects video generation, image generation, editing, and job-status requests because all of these methods reuse
self.headers.Attack Path
- A victim configures the client with a valid xAI API key.
- An attacker influences application configuration, generated integration code, or another input that controls the
base_urlargument. - The attacker sets
base_urlto a server under their control, such as `https://attacker. ...[truncated 885 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove public
base_urlconfigurability if alternate endpoints are not an explicit functional requirement. - If configurability is required, parse the URL with
urllib.parse.urlparseand enforce:- The
httpsscheme. - An exact hostname allowlist, preferably only
api.x.ai. - The expected port and API path.
- No embedded username or password.
- The
- Construct the authorization header only after validating the destination.
- Revalidate the final request destination after URL composition.
- Disable cross-origin redirects for authenticated requests or strip the authorization header whenever a redirect changes the origin.
- Avoid retaining the API key in both
self.api_keyandself.headersunless both copies are required. - Add tests proving that HTTP URLs, lookalike domains, subdomain tricks, embedded credentials, and attacker-controlled hosts are rejected before a request is sent.
- Remove public
