Back to skill

Security audit

stock-portfolio-zh

Security checks for vulnerabilities and agentic risk

Overview

This portfolio skill mostly matches its stated purpose, but it needs review because it can send the AISA API key to a configurable endpoint and treats model-generated prices as live financial data.

Review carefully before installing. Use a narrowly scoped AISA key, avoid setting AISA_BASE_URL unless you fully trust the endpoint, and do not rely on the displayed prices or P&L for trading or financial decisions without checking an authoritative market-data source. Expect local portfolio data to be permanently changed by remove and delete commands.

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 (2)

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/portfolio.py:57
Finding

API Credential Can Be Redirected to an Arbitrary Network Endpoint

Content
View full analysis
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) ``` ### Technical Analysis The application retrieves the sensitive `AISA_API_KEY` credential and supplies it to an OpenAI-compatible client. Although the default endpoint is `https://api.aisa.one/v1`, the destination can be replaced with any value through the undocumented `AISA_BASE_URL` environment variable. The code does not enforce HTTPS, validate the URL scheme, or restrict the hostname to an approved provider. Consequently, a compromised launcher, environment configuration, automation workflow, or wrapper script can redirect authenticated requests to an attacker-controlled server. Sending ticker symbols to the declared pricing service is necessary for the live-pricing feature. Permitting unrestricted redirection of the authentication credential, however, exceeds the minimum destination privilege required by that functionality. ### Attack Path 1. An attacker gains the ability to influence the environment used to launch the Skill, such as a shell profile, task configuration, wrapper, or CI environment. 2. The attacker sets `AISA_BASE_URL` to an endpoint under their control. 3. The user invokes the `show` command for a nonempty portfolio. 4. `fetch_prices()` calls `get_client()`, which constructs the client with the attacker-controlled base URL and the legitimate `AISA_API_KEY`. 5. The client sends an authenticated request to the attacker-controlled endpoint. 6. The attacker captures the API ...[truncated 584 chars]
Remediation
View remediation

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/portfolio.py:67
Finding

Unvalidated Ticker Values Permit LLM Prompt Injection and Price Manipulation

Content
View full analysis
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, ) content = response.choices[0].message.content.strip() # Extract JSON from possible markdown fences if "```" in content: content = content.split("```")[1] if content.startswith("json"): content = content[4:] return json.loads(content.strip()) except Exception as e: print(f"⚠️ Could not fetch live prices: {e}", file=sys.stderr) return {} ``` The unvalidated value is accepted and persisted by the following code: ```python def cmd_add(args): data = load_portfolios() pf_name = get_active_portfolio(data, args.portfolio) ticker = args.ticker.upper() asset = { "ticker": ticker, "quantity": args.quantity, "cost_basis": args.cost ...[truncated 2275 chars]
Remediation
View remediation
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (8)

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
92% confidence
Finding

The skill declares required environment access and writes portfolio state to disk, but does not define any explicit tool scope such as permissions or allowed-tools. This creates an overbroad execution surface where an agent may read environment variables and modify files without a clear least-privilege boundary, increasing the chance of unintended data exposure or filesystem changes.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
90% confidence
Finding

The visible skill title, usage guidance, examples, and operational instructions are entirely in Chinese, which implies a language-specific interaction mode. The file does not offer users a language choice or state that Chinese is optional, so it presents a locale/language constraint without opt-in.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
87% confidence
Finding

The manifest sets the skill language to "zh", which indicates a fixed language/locale choice. Under the policy, forcing a specific language without explicit user opt-in or a documented region-specific justification is a natural-language policy violation.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The documentation promises 'live pricing via AIsa API', but the implementation later sources prices by asking a chat model to generate them. In a financial portfolio skill, this can mislead users into trusting model-produced numbers as authoritative market data, causing incorrect P&L calculations and bad investment decisions.

Content

No source excerpt is available for this finding.

External Transmission

Medium
Category
Data Exfiltration
Confidence
60% confidence
Finding

Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.

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)

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
99% confidence
Finding

The code fetches prices by prompting an LLM chat completion to 'return only JSON' rather than calling a trusted pricing API. An LLM can hallucinate, be stale, or be manipulated by upstream prompt/tool behavior, so the portfolio's displayed value and P&L may be materially wrong while appearing precise and trustworthy.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
88% confidence
Finding

This code performs irreversible local data modifications by deleting assets from the stored portfolio file, but it provides no confirmation prompt or prior user-facing warning before the deletion occurs. Although the script prints a success message afterward, that does not disclose the destructive action in advance.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The delete command removes an entire portfolio from persistent local storage and immediately saves the change, but there is no confirmation prompt, cautionary log, or warning describing that this action is destructive. This is a safety-critical file modification because it permanently alters user data.

Content

No source excerpt is available for this finding.