T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/kv_store.py:14- Finding
Undocumented credential-file access with credential transmission to a configurable endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/kv_store.py, lines 14-38
Vulnerability Type: Undocumented credential access and credential egress
Risk Level: MediumVulnerable Code:
python def get_api_key() -> str: """Resolve API key from env or common locations.""" key = os.environ.get("SILICONFLOW_API_KEY") if key: return key # Try reading from file keyfile = os.path.expanduser("/userdata/硅基流动api-key") if os.path.exists(keyfile): return open(keyfile).read().strip() raise RuntimeError( "SILICONFLOW_API_KEY not set. Set env var or place key at /userdata/硅基流动api-key" ) BASE_URL = os.environ.get("SILICONFLOW_BASE_URL", "https://api.siliconflow.cn/v1") MODEL = os.environ.get("EMBED_MODEL", "BAAI/bge-m3") DEFAULT_THRESHOLD = 0.85 def embed(texts: list[str], api_key: str) -> np.ndarray: """Get embeddings from SiliconFlow API.""" resp = requests.post( f"{BASE_URL}/embeddings", headers={"Authorization": f"Bearer {api_key}"}, json={"model": MODEL, "input": texts, "encoding_format": "float"}, timeout=30, )Technical Analysis
The program automatically reads a credential from the fixed path
/userdata/硅基流动api-keywhenSILICONFLOW_API_KEYis absent. This filesystem access is not disclosed inSKILL.md, which instead documents the differently namedKV_EMBED_API_KEY,KV_EMBED_BASE_URL, andKV_EMBED_MODELvariables.The recovered credential is subsequently inserted into a bearer Authorization header and sent to
SILICONFLOW_BASE_URL. Because that URL is configurable and the implementation does not require HTTPS or validate the destination host, the credential and embedding input can be transmitted to an unintended or untrusted endpoint.Sending key or query text to an embedding provider is necessary for the declared remote-embedding functionality. However, silently ...[truncated 1536 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the implicit
/userdata/硅基流动api-keyfallback. If file-based credentials are required, add an explicit--credential-fileoption or environment variable and require deliberate user configuration. - Align the implementation with the documented
KV_EMBED_API_KEY,KV_EMBED_BASE_URL, andKV_EMBED_MODELnames. - Require an
https://base URL by default and reject plaintext HTTP unless the user enables an explicit, clearly labeled development override. - Validate or allowlist the intended embedding-provider hostname where operationally feasible.
- Display a clear notice that
putkeys andsearchqueries are transmitted to the configured third-party provider. - Ensure credentials are not logged, included in exceptions, or forwarded to a different host during redirects. Consider disabling redirects for embedding requests or explicitly validating every redirect target.
- Use a
with open(...)context manager when reading an explicitly configured credential file and verify that its permissions are suitably restrictive.
- Remove the implicit
