T09 · Insecure Skill Coding Practices
- Location
src/embedder.py:43- Finding
Configurable Embedding Endpoint Can Expose API Credentials and Query Data
- Content
View full analysis
Vulnerability Details
File Location:
src/config_loader.py:44-52,58-63;src/embedder.py:43-46,67-70
Vulnerability Type: Unvalidated external service endpoint and credential disclosure
Risk Level: MediumVulnerable Code
python # src/config_loader.py:44-52 if Path(config_path).exists(): try: with open(config_path, 'r', encoding='utf-8') as f: file_config = json.load(f) # Update configuration for key, value in file_config.items(): snake_key = camel_to_snake(key) if hasattr(config, snake_key): setattr(config, snake_key, value) except Exception as e: print(f"Configuration loading failed: {e}")python # src/config_loader.py:58-63 if not config.embedding_api_key: if config.embedding_provider == "dashscope": config.embedding_api_key = os.getenv("DASHSCOPE_API_KEY", "") elif config.embedding_provider == "openai": config.embedding_api_key = os.getenv("OPENAI_API_KEY", "")python # src/embedder.py:43-46 if provider == "dashscope": self.client = openai.OpenAI( api_key=api_key, base_url=base_url )python # src/embedder.py:67-70 response = self.client.embeddings.create( model=self.model, input=text )Technical Analysis
The
embeddingBaseUrlconfiguration value is accepted without validating its scheme, hostname, port, or relationship to the selected provider. The application subsequently creates an authenticated OpenAI-compatible client using that value.When the embedding request is made, the client sends both authentication information and the user's query to the configured endpoint. If an attacker or compromised deployment process changes
config.json, the endpoint can be redirected to an attacker-controlled server.The shipped configuration uses the official DashScope HTTPS ...[truncated 1469 chars]
- Remediation
View remediation
Remediation Suggestions
- Define an explicit allowlist of endpoint origins for each supported provider:
- DashScope:
https://dashscope.aliyuncs.com - OpenAI: the official OpenAI API origin
- DashScope:
- Require HTTPS and reject plaintext HTTP, embedded credentials, unexpected ports, redirects to unapproved hosts, and malformed URLs.
- Treat custom endpoints as a separate provider mode that requires explicit administrator approval.
- Do not automatically attach environment-provided production credentials to a custom endpoint.
- Protect
config.jsonwith restrictive file permissions and verify its ownership before loading it. - Consider signing centrally distributed configuration files or validating them against an administrator-managed policy.
- Avoid returning sensitive HTTP-client exception details where they may disclose endpoint or authentication information.
- Define an explicit allowlist of endpoint origins for each supported provider:
