T09 · Insecure Skill Coding Practices
- Location
scripts/generate.py:42- Finding
Overbroad Credential Discovery Can Transmit an Unrelated API Key
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate.py, lines 42–83 and 116–117
Vulnerability Type: Overbroad credential access and unintended credential disclosure
Risk Level: MediumVulnerable Code
python def _load_key_from_env_and_configs(env_var: str, config_key: str) -> str | None: """Try env var → config files → .env files. Returns None if not found.""" value = os.environ.get(env_var) if value: return value config_paths = [ "config.json", os.path.expanduser("~/.openclaw/config.json"), os.path.expanduser("~/.claude/config.json"), ] for path in config_paths: if os.path.exists(path): try: with open(path) as f: data = json.load(f) if data.get(config_key): return data[config_key] except Exception: pass script_dir = os.path.dirname(os.path.abspath(__file__)) skill_dir = os.path.dirname(script_dir) env_paths = [ os.path.join(skill_dir, ".env"), ".env", os.path.expanduser("~/.env"), ] for path in env_paths: if os.path.exists(path): try: with open(path) as f: for line in f: line = line.strip() if line.startswith(f"{env_var}="): val = line.split("=", 1)[1].strip().strip('"') if val: return val except Exception: pass return Nonepython def load_glm_key() -> str: key = _load_key_from_env_and_configs("GLM_API_KEY", "api_key")The selected value is subsequently transmitted to the GLM API:
python headers = { "Content-Type": "application/json", "Authorization": f" ...[truncated 2527 chars]- Remediation
View remediation
Remediation Suggestions
- Use only provider-specific configuration names:
GLM_API_KEYorglm_api_keyOPENROUTER_API_KEYoropenrouter_api_key
- Replace the GLM lookup with:
python key = _load_key_from_env_and_configs("GLM_API_KEY", "glm_api_key") - Remove generic
api_keyfallback behavior. - Stop searching unrelated user-wide locations such as
~/.claude/config.jsonand~/.env. - Restrict file-based discovery to the documented Skill
.envand~/.openclaw/config.json, or require an explicit configuration path. - Make provider selection depend on an explicitly named provider credential rather than the existence of a generic field.
- Validate that the documentation and implementation use identical configuration names.
- Consider requiring user confirmation before using file-discovered credentials, particularly when auto-selecting a provider.
- Replace broad exception suppression with narrow error handling and non-sensitive diagnostics so configuration errors are visible without printing secret values.
- Use only provider-specific configuration names:
