Back to skill

Security audit

Llm Service Manager

Security checks for vulnerabilities and agentic risk

Overview

This skill mostly does what it claims, but it can send prompts and an API key to an environment-configured endpoint without clear validation or user-facing warning.

Install only if you are comfortable with a skill that can query local LLM services, start Ollama, pull models, and send API-mode prompts plus an optional OPENAI_API_KEY to the endpoint named by OPENAI_BASE_URL. Prefer a trusted HTTPS endpoint, avoid sensitive prompts, and review the environment variables before use.

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

Warning
Location
llm_service_manager.py:73
Finding

API Credentials and Prompts May Be Transmitted to an Arbitrary Plaintext Endpoint

Content
View full analysis

Vulnerability Details

File Location: llm_service_manager.py, lines 73-86 and 205-212
Vulnerability Type: Unvalidated API endpoint and plaintext transmission of sensitive data
Risk Level: Medium

Vulnerable Code

python
def _query_api(url: str, model: str, prompt: str, api_key: str = "") -> str:
    """向OpenAI兼容API发送查询"""
    try:
        import urllib.request
        headers = {"Content-Type": "application/json"}
        if api_key:
            headers["Authorization"] = f"Bearer {api_key}"
        body = json.dumps({
            "model": model, "messages": [{"role": "user", "content": prompt}],
            "max_tokens": 512, "temperature": 0.3
        }).encode()
        req = urllib.request.Request(f"{url}/chat/completions", data=body, headers=headers)
        with urllib.request.urlopen(req, timeout=30) as r:
            data = json.loads(r.read())
            return data["choices"][0]["message"]["content"]
python
if cmd.startswith("api:"):
    prompt = cmd[4:].strip()
    openai_url = os.environ.get("OPENAI_BASE_URL", "http://localhost:8000/v1")
    api_key = os.environ.get("OPENAI_API_KEY", "")
    model = os.environ.get("OPENAI_MODEL", "gpt-4o-mini")
    if not prompt:
        return "请输入查询内容"
    return _query_api(openai_url, model, prompt, api_key)

Technical Analysis

The value of OPENAI_BASE_URL is used as the request destination without validating its scheme, hostname, or trust level. _query_api then attaches OPENAI_API_KEY as a bearer credential and includes the complete user prompt in the request body.

Sending prompts and credentials to a configured OpenAI-compatible service is required by the declared API-query functionality. However, allowing a non-loopback endpoint to use plain HTTP is not necessary and violates secure transport expectations. On plain HTTP, an attacker with network visibility or an active man-in-the-middle position c ...[truncated 1676 chars]

Remediation
View remediation

Remediation Suggestions

  1. Parse OPENAI_BASE_URL with urllib.parse.urlparse and reject unsupported schemes.
  2. Require HTTPS for every non-loopback destination.
  3. Permit HTTP only when the parsed hostname is a validated loopback address such as 127.0.0.1, ::1, or localhost; do not rely on substring matching.
  4. Reject URLs containing embedded user information, unexpected fragments, or malformed hostnames.
  5. Maintain an explicit allowlist of trusted API origins where practical.
  6. Require user confirmation before sending credentials or prompts to a newly configured remote origin.
  7. Avoid attaching OPENAI_API_KEY to endpoints that are not explicitly trusted.
  8. Document that API-mode prompts leave the local system and may contain sensitive information.
  9. Use short-lived, narrowly scoped API credentials and provide rotation guidance in case of endpoint misconfiguration.
  10. Add tests confirming that remote http:// endpoints, malformed URLs, and untrusted destinations are rejected while loopback development endpoints remain supported.
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • Behavioral ASTexec() Call, eval() Call, Dynamic Import
  • Taint TrackingDirect Taint Flow, Variable-Mediated Taint Flow, Credential Exfiltration Chain
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
Findings (15)

Tainted flow: 'req' from os.environ.get (line 81, credential/environment) → urllib.request.urlopen (network output)

Critical
Category
Data Flow
Confidence
90% confidence
Finding

Credentials or environment variables flow to a network sink. This is a high-confidence indicator of credential exfiltration.

Content

Scanner excerpt · llm_service_manager.py (reported line 16)May include surrounding context.

python
try:
        import urllib.request
        req = urllib.request.Request("http://localhost:11434/api/tags")
        with urllib.request.urlopen(req, timeout=3) as r:
            data = json.loads(r.read())
            models = [m["name"] for m in data.get("models", [])]
            return {"running": True, "models": models, "url": "http://localhost:11434"}

Tainted flow: 'req' from os.environ.get (line 81, credential/environment) → urllib.request.urlopen (network output)

Critical
Category
Data Flow
Confidence
90% confidence
Finding

Credentials or environment variables flow to a network sink. This is a high-confidence indicator of credential exfiltration.

Content

Scanner excerpt · llm_service_manager.py (reported line 29)May include surrounding context.

python
try:
        import urllib.request
        req = urllib.request.Request("http://localhost:11434/api/tags")
        with urllib.request.urlopen(req, timeout=3) as r:
            data = json.loads(r.read())
            models = [m["name"] for m in data.get("models", [])]
            return {"running": True, "models": models, "url": "http://localhost:11434"}

Tainted flow: 'req' from os.environ.get (line 81, credential/environment) → urllib.request.urlopen (network output)

Critical
Category
Data Flow
Confidence
93% confidence
Finding

OPENAI_BASE_URL is taken from the environment and used directly to build a request target. In a hostile or multi-tenant environment, an attacker who can influence environment variables can redirect requests to an arbitrary host, causing unintended outbound connections and possible leakage of model metadata or bearer credentials if configured.

Content

Scanner excerpt · llm_service_manager.py (reported line 46)May include surrounding context.

python
try:
        import urllib.request
        req = urllib.request.Request(f"{url}/models")
        with urllib.request.urlopen(req, timeout=3) as r:
            data = json.loads(r.read())
            models = [m["id"] for m in data.get("data", [])]
            return {"running": True, "models": models, "url": url}

Tainted flow: 'req' from os.environ.get (line 81, credential/environment) → urllib.request.urlopen (network output)

Critical
Category
Data Flow
Confidence
90% confidence
Finding

Credentials or environment variables flow to a network sink. This is a high-confidence indicator of credential exfiltration.

Content

Scanner excerpt · llm_service_manager.py (reported line 63)May include surrounding context.

python
body = json.dumps({"model": model, "messages": [{"role": "user", "content": prompt}], "stream": False}).encode()
        req = urllib.request.Request("http://localhost:11434/api/chat", data=body,
                                     headers={"Content-Type": "application/json"})
        with urllib.request.urlopen(req, timeout=30) as r:
            data = json.loads(r.read())
            return data.get("message", {}).get("content", str(data))
    except Exception as e:

Tainted flow: 'req' from os.environ.get (line 81, credential/environment) → urllib.request.urlopen (network output)

Critical
Category
Data Flow
Confidence
96% confidence
Finding

The code sends user-supplied prompts and optionally an Authorization: Bearer token to a URL taken from OPENAI_BASE_URL without validation. If that environment variable is manipulated, the tool can exfiltrate sensitive prompts and API credentials to an attacker-controlled endpoint.

Content

Scanner excerpt · llm_service_manager.py (reported line 82)May include surrounding context.

python
"max_tokens": 512, "temperature": 0.3
        }).encode()
        req = urllib.request.Request(f"{url}/chat/completions", data=body, headers=headers)
        with urllib.request.urlopen(req, timeout=30) as r:
            data = json.loads(r.read())
            return data["choices"][0]["message"]["content"]
    except Exception as e:

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The skill description documents commands that query OpenAI-compatible APIs and download models, but it does not warn that prompts may leave the local machine or that commands can alter system state by starting services and storing large model files. Users may unknowingly expose sensitive data in prompts or incur unwanted changes to their environment because the operational and privacy implications are not disclosed.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The trigger list includes broad terms like "LLM" and "Ollama," which can cause the skill to activate in many unrelated conversations. Because this skill can start services, pull models, and send prompts to local or remote endpoints, unintended activation can lead to privacy exposure, unexpected network activity, or changes to system state without clear user intent.

Content

No source excerpt is available for this finding.

Internal Network Request

Medium
Category
Server-Side Request Forgery
Confidence
70% confidence
Finding

Code issues a request to a loopback, link-local, or private-range host. This can reach internal services not meant to be exposed and is a common SSRF pivot.

Content

Scanner excerpt · llm_service_manager.py (reported line 15)May include surrounding context.

python
"""检测Ollama是否运行"""
    try:
        import urllib.request
        req = urllib.request.Request("http://localhost:11434/api/tags")
        with urllib.request.urlopen(req, timeout=3) as r:
            data = json.loads(r.read())
            models = [m["name"] for m in data.get("models", [])]

Internal Network Request

Medium
Category
Server-Side Request Forgery
Confidence
70% confidence
Finding

Code issues a request to a loopback, link-local, or private-range host. This can reach internal services not meant to be exposed and is a common SSRF pivot.

Content

Scanner excerpt · llm_service_manager.py (reported line 28)May include surrounding context.

python
"""检测Ollama是否运行"""
    try:
        import urllib.request
        req = urllib.request.Request("http://localhost:11434/api/tags")
        with urllib.request.urlopen(req, timeout=3) as r:
            data = json.loads(r.read())
            models = [m["name"] for m in data.get("models", [])]

Internal Network Request

Medium
Category
Server-Side Request Forgery
Confidence
70% confidence
Finding

Code issues a request to a loopback, link-local, or private-range host. This can reach internal services not meant to be exposed and is a common SSRF pivot.

Content

Scanner excerpt · llm_service_manager.py (reported line 61)May include surrounding context.

python
"""检测Ollama是否运行"""
    try:
        import urllib.request
        req = urllib.request.Request("http://localhost:11434/api/tags")
        with urllib.request.urlopen(req, timeout=3) as r:
            data = json.loads(r.read())
            models = [m["name"] for m in data.get("models", [])]

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · llm_service_manager.py (reported line 95)May include surrounding context.

python
"""启动Ollama服务"""
    try:
        if platform.system() == "Windows":
            proc = subprocess.Popen(
                ["ollama", "serve"],
                stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
                creationflags=subprocess.CREATE_NO_WINDOW

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · llm_service_manager.py (reported line 175)May include surrounding context.

python
if not model:
            return "请指定模型名,如: ollama pull gemma3:2b"
        try:
            proc = subprocess.Popen(
                ["ollama", "pull", model],
                stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                text=True, creationflags=subprocess.CREATE_NO_WINDOW

Tainted flow: 'model' from os.environ.get (line 203, credential/environment) → subprocess.Popen (code execution)

Medium
Category
Data Flow
Confidence
65% confidence
Finding

Data from a source is assigned to a variable that is later passed to a sink, creating a variable-mediated taint flow.

Content

Scanner excerpt · llm_service_manager.py (reported line 175)May include surrounding context.

python
if not model:
            return "请指定模型名,如: ollama pull gemma3:2b"
        try:
            proc = subprocess.Popen(
                ["ollama", "pull", model],
                stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                text=True, creationflags=subprocess.CREATE_NO_WINDOW

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The api: path transmits user prompts to a configured OpenAI-compatible endpoint with no user-facing disclosure or confirmation. In skill/agent contexts, this can violate user expectations and create privacy or compliance issues, especially because the destination may be remote and environment-controlled.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
87% confidence
Finding

User-facing docstrings, command descriptions, prompts, and status/error messages throughout the file are written in Chinese with no indication that other languages are supported. This imposes a language choice on users rather than offering an explicit opt-in or alternative.

Content

No source excerpt is available for this finding.