T09 · Insecure Skill Coding Practices
- Location
scripts/embeddings.py:29- Finding
Cross-Provider API Credential Disclosure
- Content
View full analysis
Vulnerability Details
File Location:
scripts/embeddings.py, lines 29-100
Vulnerability Type: Cross-provider credential confusion and sensitive credential disclosure
Risk Level: MediumVulnerable Code
python def get_api_key() -> Optional[str]: api_key = os.environ.get("OPENAI_API_KEY") or os.environ.get("DASHSCOPE_API_KEY") if api_key: return api_key config_path = Path.home() / ".qclaw" / "smart-cache" / "config.json" if config_path.exists(): with open(config_path, 'r', encoding='utf-8') as f: config = json.load(f) return config.get("api_key") or config.get("openai_api_key") return Nonepython class OpenAIEmbeddings(EmbeddingsProvider): def __init__(self, api_key: Optional[str] = None, model: str = "text-embedding-3-small"): self.api_key = api_key or get_api_key() self.model = model def get_embeddings(self, texts: List[str]) -> Optional[List[List[float]]]: import urllib.request import urllib.error url = "https://api.openai.com/v1/embeddings" headers = { "Content-Type": "application/json", "Authorization": f"Bearer {self.api_key}" } data = { "model": self.model, "input": texts }Technical Analysis
The OpenAI provider uses the provider-agnostic
get_api_key()function. That function returnsOPENAI_API_KEYwhen available, but silently falls back toDASHSCOPE_API_KEY. The selected credential is subsequently placed in a bearer authorization header and transmitted to the OpenAI API.Credentials for separate providers represent distinct trust boundaries. An OpenAI request should only access an explicitly configured OpenAI credential. Falling back to a DashScope credential exceeds the minimum credential privileges required by the selected provider and disclos ...[truncated 1546 chars]
- Remediation
View remediation
Remediation Suggestions
- Resolve credentials separately for each provider:
- OpenAI must read only
OPENAI_API_KEYor an OpenAI-specific configuration field. - DashScope must read only
DASHSCOPE_API_KEYor a DashScope-specific configuration field.
- OpenAI must read only
- Replace the generic configuration field with provider-bound fields such as
openai_api_keyanddashscope_api_key. - If a generic credential must remain for compatibility, require an explicit matching
embedding_providervalue before using it. - Fail closed when the selected provider's credential is unavailable rather than falling back to another provider's credential.
- Add tests confirming that
OpenAIEmbeddingsnever consumesDASHSCOPE_API_KEYand thatDashScopeEmbeddingsnever consumesOPENAI_API_KEY. - Avoid printing credentials. The existing command that displays the final four characters should also be reconsidered for shared terminal logs.
- Resolve credentials separately for each provider:
