Back to skill

Security audit

stock-portfolio-zh-aisa

Security checks for vulnerabilities and agentic risk

Overview

This is a coherent portfolio tool, but it needs Review because it stores financial holdings locally and can send the AISA API key and ticker list to an environment-selected API endpoint without clear disclosure.

Review this before installing if your portfolio data or AISA key are sensitive. Use it only in an environment where AISA_BASE_URL is unset or explicitly trusted, protect the CLAWDBOT_STATE_DIR state directory, and treat remove/delete commands as permanent. A safer version would constrain the API endpoint, pin dependencies, and require confirmation before destructive changes.

Vulnerability Patterns
  • Insecure DependenciesIntroduces malicious components through unsafe dependency sources
  • 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
Findings (2)

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/portfolio.py:63
Finding

API Credential Can Be Redirected to an Arbitrary Network Endpoint

Content
View full analysis

Vulnerability Details

File Location: scripts/portfolio.py, lines 63–96
Vulnerability Type: T09: Insecure Skill Coding Practices
Risk Level: Medium

Affected code:

python
def get_client() -> OpenAI:
    api_key = os.environ.get("AISA_API_KEY")
    if not api_key:
        print("❌ Error: AISA_API_KEY environment variable is not set.", file=sys.stderr)
        sys.exit(1)
    base_url = os.environ.get("AISA_BASE_URL", "https://api.aisa.one/v1")
    return OpenAI(api_key=api_key, base_url=base_url)


def fetch_prices(tickers: list[str]) -> dict[str, float]:
    """Fetch current prices for a list of tickers via AIsa API."""
    if not tickers:
        return {}
    client = get_client()
    model = os.environ.get("AISA_MODEL", "gpt-4o")
    ticker_str = ", ".join(tickers)
    prompt = (
        f"Fetch the current live price for each of these tickers: {ticker_str}\n\n"
        "Return ONLY a JSON object with ticker symbols as keys and current prices (numbers) as values.\n"
        "Example: {\"AAPL\": 195.50, \"BTC-USD\": 67234.10}\n"
        "No explanation. JSON only."
    )
    try:
        response = client.chat.completions.create(
            model=model,
            messages=[
                {"role": "system", "content": "You are a financial data fetcher. Use your tools to get current prices and return only JSON."},
                {"role": "user", "content": prompt},
            ],
            temperature=0,
        )

Technical Analysis

The application reads the sensitive AISA_API_KEY credential from the environment and passes it to an OpenAI-compatible client. However, the destination used by that client is independently controlled through the AISA_BASE_URL environment variable.

The code does not require HTTPS, validate the configured hostname, restrict the destination to an approved AISA domain, or warn the user when the default service has b ...[truncated 1954 chars]

Remediation
View remediation

Remediation Suggestions

  1. Remove the runtime endpoint override if custom AISA-compatible services are not a documented requirement:
    python
    return OpenAI(
        api_key=api_key,
        base_url="https://api.aisa.one/v1",
    )
    
  2. If endpoint customization is required, parse the URL and enforce:
    • HTTPS only.
    • An explicit hostname allowlist.
    • No embedded username or password.
    • An approved port and path.
  3. Require explicit user confirmation before sending an AISA credential to any nondefault endpoint.
  4. Use a separate credential for custom endpoints rather than forwarding AISA_API_KEY.
  5. Document exactly which portfolio information leaves the local system.
  6. Treat remote price data as untrusted: validate that the response is a JSON object containing only requested tickers and finite, nonnegative numeric prices.

T08 · Insecure Dependencies

Note
Location
scripts/portfolio.py:2
Finding

Broad and Unpinned Runtime Dependency

Content
View full analysis

Vulnerability Details

File Location: scripts/portfolio.py, lines 2–7
Vulnerability Type: T08: Insecure Dependencies
Risk Level: Low

Affected code:

python
# /// script
# requires-python = ">=3.10"
# dependencies = [
#     "openai>=1.0.0",
# ]
# ///

Technical Analysis

The inline runtime metadata permits any openai package release at or above version 1.0.0. No upper bound, exact version, lockfile, or integrity hash is present in the audited project.

When the script is run through a dependency-resolving launcher such as uv run, the selected package version may therefore change over time without a corresponding reviewed change to the Skill. This creates a supply-chain and reproducibility risk because the dependency executes in the same process context as the Skill and handles both the AISA_API_KEY and outbound network requests.

This finding does not establish that the current openai package is malicious. The weakness is that future package resolution is insufficiently constrained for a dependency entrusted with sensitive authentication material.

Attack Path

  1. A user invokes the script in an environment where its inline dependencies must be resolved.
  2. The package resolver selects a future release satisfying openai>=1.0.0.
  3. That release is malicious, compromised, or contains a security regression.
  4. The dependency executes locally when imported and when the API client is created.
  5. Malicious dependency code can read process-accessible data, including AISA_API_KEY, alter network requests, manipulate responses, or perform actions with the operating-system permissions of the invoking user.

Impact Assessment

Exploitation would grant malicious dependency code the same local privileges as the user running the Skill. Within that scope, it could access environment variables, read files permitted to that user, make outbound network requests, and manipulate por ...[truncated 219 chars]

Remediation
View remediation

Remediation Suggestions

  1. Pin the dependency to an exact, reviewed version:
    python
    # dependencies = [
    #     "openai==<reviewed-version>",
    # ]
    
  2. Generate and commit a lockfile where supported by the execution workflow.
  3. Use cryptographic package hashes and require hash verification during installation.
  4. Resolve packages only from an explicitly configured, trusted package index.
  5. Establish a controlled dependency-update process that includes source review, vulnerability scanning, and functional testing before changing the pinned version.
  6. Run the Skill with minimal filesystem and network permissions so that compromise of a dependency has a reduced impact.
Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
Findings (11)

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
90% confidence
Finding

The skill declares access to an API key and describes reading/writing a local state file, but it does not specify any explicit tool scope such as permissions or allowed-tools. That omission can cause the agent to invoke the skill with broader-than-necessary capabilities or without clear enforcement boundaries, increasing the risk of unintended file or environment access.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
92% confidence
Finding

The top-level description says to use the skill whenever a user wants to add holdings, view performance, rename a portfolio, or review profit/loss, but it does not define narrow trigger phrases or clear exclusion boundaries. Ambiguous activation criteria can lead to accidental invocation in unrelated finance conversations, causing unnecessary access to local state or API-backed actions.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

从标题、说明到示例请求,文档整体仅以中文呈现,且 skill 名称含“zh”,暗示语言被预设为中文,但未说明这是可选项,也未提供用户语言选择。若技能面向通用用户而非明确限定中文场景,这属于未征得用户同意的语言约束。

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
90% confidence
Finding

The '何时使用' section repeats a broad activation rule without sufficiently constraining the skill's scope. In an agent setting, vague routing guidance increases the chance of misfires into a stateful skill that can persist data locally and use credentials, which makes accidental use more security-relevant than a purely informational skill.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The manifest sets the skill language to "zh" with no accompanying indication that the user can opt into another language or that the skill is specifically limited to a Chinese-only context. This creates a natural-language policy concern because it enforces a locale/language choice by configuration alone.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The script metadata identifies the skill as 'stock-portfolio-zh', but persisted data is stored under the 'stock-analysis' namespace. This can cause cross-skill data confusion, unintended sharing or overwrite of another skill's state, and weakens isolation assumptions if multiple skills run in the same state directory.

Content

No source excerpt is available for this finding.

External Transmission

Medium
Category
Data Exfiltration
Confidence
89% confidence
Finding

The skill transmits portfolio tickers to an external API endpoint, and the base URL is overrideable via an environment variable. Although intended for live pricing, this creates a real data egress path and could redirect requests to an attacker-controlled host if the runtime environment is compromised or misconfigured; in this financial context, even ticker holdings can reveal sensitive investment interests.

Content

Scanner excerpt · scripts/portfolio.py (reported line 77)May include surrounding context.

python
if not api_key:
        print("❌ Error: AISA_API_KEY environment variable is not set.", file=sys.stderr)
        sys.exit(1)
    base_url = os.environ.get("AISA_BASE_URL", "https://api.aisa.one/v1")
    return OpenAI(api_key=api_key, base_url=base_url)

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
91% confidence
Finding

The delete operation permanently removes portfolio data immediately after a name match, with no confirmation, dry-run, or recovery mechanism. In an agent context, where actions may be triggered from natural-language requests or ambiguous intent, this increases the chance of irreversible data loss from mistakes or prompt confusion.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The delete command removes an entire portfolio from persistent local storage and immediately saves the modified file. Although the script prints a success message afterward, there is no confirmation prompt, pre-delete warning, or other disclosure before the irreversible action occurs.

Content

No source excerpt is available for this finding.

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
88% confidence
Finding

The documentation mentions the default state path, but it does not prominently warn users that portfolio data will be persisted locally. Silent or poorly surfaced persistence can expose sensitive financial holdings or trading history to other local users, backups, or later workflows that read repository files.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Low
Category
Not specified by scanner
Confidence
90% confidence
Finding

The docstring says data is stored at a fixed local path, but the implementation actually honors CLAWDBOT_STATE_DIR and then appends a different namespace. This mismatch can mislead operators about where sensitive portfolio data resides, causing mistaken trust, incomplete cleanup, or accidental exposure when the environment redirects storage to a shared or less-protected location.

Content

No source excerpt is available for this finding.