Back to skill

Security audit

Civitai API

Security checks for vulnerabilities and agentic risk

Overview

This is a straightforward Civitai API helper with disclosed token use, though users should handle generated download URLs as secrets.

Install only if you are comfortable storing a Civitai API token for this helper. Keep the .env file limited to the Civitai token when possible, and treat generated download URLs as credentials because they may contain the token.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (1)

T09 · Insecure Skill Coding Practices

Note
Location
scripts/civitai.py:14
Finding

Overbroad ingestion of secrets from workspace environment files

Content
View full analysis
None: candidates = [start / ".env", start.parent / ".env"] for env_path in candidates: if not env_path.exists(): continue for raw_line in env_path.read_text(encoding="utf-8").splitlines(): line = raw_line.strip() if not line or line.startswith("#") or "=" not in line: continue key, value = line.split("=", 1) os.environ.setdefault(key.strip(), value.strip()) return ``` ### Technical Analysis The declared functionality requires only the `CIVITAI_API_KEY` value. However, `load_env_file()` reads every assignment from the first matching `.env` file and copies all parsed values into the process environment. The search covers both the script directory and its parent directory. Consequently, a shared workspace `.env` file may cause unrelated database credentials, cloud keys, access tokens, or other secrets to be loaded even though the Skill does not need them. This violates least-privilege principles by granting the running process access to a broader secret set than required. The current reviewed implementation uses only `CIVITAI_API_KEY`, relies exclusively on Python standard-library imports, and does not spawn child processes or transmit unrelated environment variables. Therefore, no present end-to-end exfiltration path for those additional secrets was identified. Nevertheless, placing them in process-global state unnecessarily increases exposure to diagnostics, future code changes, subsequently imported code, or child processes added later. ### Attack Path 1. A user or automation stores several credentials in a shared `.env` file located in the script directory or its parent. 2. The user invokes `scripts/civit ...[truncated 1378 chars]
Remediation
View remediation
str | None: for env_path in (start / ".env", start.parent / ".env"): if not env_path.is_file(): continue for raw_line in env_path.read_text(encoding="utf-8").splitlines(): line = raw_line.strip() if not line or line.startswith("#") or "=" not in line: continue key, value = line.split("=", 1) if key.strip() == "CIVITAI_API_KEY": return value.strip() return None return None ``` 2. Keep the token in a local variable rather than copying file contents into the process-global environment: ```python token = os.getenv("CIVITAI_API_KEY") or load_civitai_token(script_dir) ``` 3. Document the precise `.env` lookup locations and recommend restrictive file permissions. 4. Avoid passing tokens through `--token` where practical because command-line arguments can be retained in shell history or exposed through process inspection. 5. Continue restricting requests containing authorization headers to the fixed HTTPS Civitai origin. If redirects are supported, ensure authorization data cannot be forwarded to another host. 6. Warn users before printing token-bearing download URLs, and offer a safer mode that writes the URL to a permission-restricted file or performs the download without displaying the credential. ]]>
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (4)

Credential Access

High
Category
Privilege Escalation
Confidence
60% confidence
Finding

Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Content

Scanner excerpt · scripts/civitai.py (reported line 15)May include surrounding context.

python
def load_env_file(start: Path) -> None:
    candidates = [start / ".env", start.parent / ".env"]
    for env_path in candidates:
        if not env_path.exists():
            continue

Credential Access

High
Category
Privilege Escalation
Confidence
60% confidence
Finding

Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Content

Scanner excerpt · scripts/civitai.py (reported line 134)May include surrounding context.

python
pass

    parser = argparse.ArgumentParser(description="Query the Civitai public REST API.")
    parser.add_argument("--token", default=os.getenv("CIVITAI_API_KEY"), help="Civitai API token. Defaults to CIVITAI_API_KEY from .env or the environment.")

    subparsers = parser.add_subparsers(dest="command", required=True)

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
94% confidence
Finding

The skill instructs use of environment secrets (CIVITAI_API_KEY), local file access (.env), and outbound network access to a public API, but it does not declare any explicit tool scope such as permissions or allowed-tools. That mismatch weakens least-privilege controls and can let an agent invoke broader capabilities than a reviewer or platform policy expects, increasing the chance of unintended secret exposure or network use.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The script constructs a download URL with the API token in the query string and prints it directly to stdout. Query-string credentials are easily exposed through shell history, terminal logs, process capture, CI logs, or copy/paste sharing, so this can leak the bearer-equivalent token beyond the intended user.

Content

No source excerpt is available for this finding.