Back to skill

Security audit

Finlab

Security checks for vulnerabilities and agentic risk

Overview

This FinLab skill is mostly a trading and backtesting guide, but it also includes live broker order execution and credential handling without strong confirmation or safety boundaries.

Install only after reviewing the live-trading sections. Use an isolated locked Python environment, avoid system-wide installs, do not paste real broker credentials or tokens into chats or notebooks, keep experimental backtests at `upload=False`, and use preview-only or paper trading unless you explicitly approve the exact orders, account, quantities, and prices.

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

T08 · Insecure Dependencies

Error
Location
SKILL.md:35
Finding
Unpinned Third-Party Dependencies Are Installed and Executed<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:35-48`; related instructions at `best-practices.md:310`, `trading-reference.md:147-149`, and `trading-reference.md:183-185` **Vulnerability Type**: Unpinned dependencies and unsafe system-wide package installation **Risk Level**: High ### Vulnerable Code ```bash uv python install 3.12 # Ensure Python is available (skip if already installed) uv pip install --system "finlab>=1.5.9" 2>/dev/null || uv pip install "finlab>=1.5.9" ``` ```bash uv run --with "finlab" python3 script.py ``` Additional unpinned installation instructions include: ```bash pip install finlab --upgrade ``` ```bash pip install esun-trade ``` ```bash pip install shioaji ``` ### Technical Analysis The Skill instructs the Agent to download and execute third-party packages without pinning exact versions or verifying package hashes. The constraint `finlab>=1.5.9` permits any future matching release, while `--upgrade` and package names without versions explicitly select package contents that may change after this Skill has been audited. The `--system` option is particularly unsafe because it modifies the system Python environment instead of an isolated project environment. Installation and subsequent import can execute package-controlled build hooks, initialization code, native extensions, and runtime logic. The source code of these dependencies is not included in the audited project, so its behavior cannot be verified from this repository. This creates a software supply-chain exposure. A compromised publisher account, malicious future release, dependency confusion condition, or compromised transitive dependency could introduce arbitrary code into the execution environment. ### Attack Path 1. An attacker compromises a referenced package, its publisher account, or one of its transitive dependencies. 2. The attacker publishes a malicious release satisfying the unbounded version requirement. 3. The Agent follows the Skill and ...[truncated 1313 chars]
Remediation
<![CDATA[ ## Remediation Suggestions 1. Pin every direct dependency to a reviewed exact version, including FinLab and each broker SDK. 2. Generate and commit a lockfile containing resolved transitive versions. 3. Require cryptographic hashes for downloaded distributions where the package tooling supports them. 4. Remove `--system` and install packages only in a dedicated, least-privileged virtual environment. 5. Replace `uv run --with "finlab"` with execution against the locked environment. 6. Do not use `pip install --upgrade` in runtime Skill instructions. 7. Verify package provenance, registry configuration, publisher identity, and release signatures before updates. 8. Review dependency changes before updating the lockfile and use vulnerability and malware scanning for packages and transitive dependencies. 9. Keep broker integrations in a separate environment with access only to the credentials required for the selected broker. 10. Prevent installation scripts from receiving broker credentials by injecting credentials only after dependency installation and verification are complete. ]]>

T09 · Insecure Skill Coding Practices

Warning
Location
backtesting-reference.md:15
Finding
Backtest Reports May Be Uploaded Without Explicit User Consent<![CDATA[ ## Vulnerability Details **File Location**: `backtesting-reference.md:15-42`, `backtesting-reference.md:128-131`, and runnable examples at `backtesting-reference.md:243-253` and `backtesting-reference.md:262-282` **Vulnerability Type**: Unintended external disclosure caused by an unsafe default and inconsistent examples **Risk Level**: Medium ### Vulnerable Code The documented function signature enables uploads by default: ```python sim( position: Union[pd.DataFrame, pd.Series], resample: Union[str, None] = None, resample_offset: Union[str, None] = None, trade_at_price: Union[str, pd.DataFrame] = 'close', position_limit: float = 1, fee_ratio: float = 1.425/1000, tax_ratio: float = 3/1000, name: str = '未命名', stop_loss: Union[float, None] = None, take_profit: Union[float, None] = None, trail_stop: Union[float, None] = None, touched_exit: bool = False, retain_cost_when_rebalance: bool = False, stop_trading_next_period: bool = True, live_performance_start: Union[str, None] = None, mae_mfe_window: int = 0, mae_mfe_window_step: int = 1, market: Union[None, Market] = None, upload: bool = True, fast_mode: bool = False, notification_enable: bool = False, line_access_token: str = '' ) -> report.Report ``` The parameter documentation confirms the external action: ```markdown #### upload - **Type:** `bool` - **Default:** `True` - **Description:** Determines whether to upload the strategy performance report after simulation. ``` Runnable examples omit the safe override: ```python import pandas as pd from finlab import backtest position = pd.DataFrame({ '2330': [0, 1, 1], '1101': [0.2, 0, 0], '2454': [0.4, 0, 0] }, index=pd.to_datetime(['2021-12-31', '2022-03-31', '2022-06-30'])) report = backtest.sim(position) print(report) ``` ```python report = backtest.sim( position, resample='M', stop_loss=0.1, take_profit=0.2, name='MA Strategy with ...[truncated 2160 chars]
Remediation
<![CDATA[ ## Remediation Suggestions 1. Add `upload=False` explicitly to every backtest example, including basic examples. 2. Wrap `backtest.sim()` in a local helper that defaults to `upload=False`, even if the upstream library default remains unsafe. 3. Require explicit user consent immediately before enabling an upload. 4. Before consent, disclose the destination, categories of data transmitted, retention policy, and account visibility. 5. Treat upload approval as scoped to one named report; do not infer ongoing consent from a previous upload. 6. Add an automated documentation test that rejects `sim(...)` examples unless they explicitly include `upload=False` or are clearly marked as consented production-upload examples. 7. Reconcile contradictory guidance so the main Skill and every reference file consistently use the safe default. 8. Where supported, configure network controls to block report-upload endpoints during experimental backtesting. ]]>

T09 · Insecure Skill Coding Practices

Error
Location
SKILL.md:243
Finding
Live Broker Orders Can Be Submitted Without a Mandatory Confirmation Boundary<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:243-264`; duplicated workflow at `trading-reference.md:294-312` **Vulnerability Type**: Unsafe live financial transaction workflow **Risk Level**: High ### Vulnerable Code ```python from finlab.online.order_executor import Position, OrderExecutor from finlab.online.sinopac_account import SinopacAccount # 1. Convert report to position position = Position.from_report(report, fund=1000000) # 2. Connect broker account acc = SinopacAccount() # 3. Create executor and preview orders executor = OrderExecutor(position, account=acc) executor.create_orders(view_only=True) # Preview first # 4. Execute orders (when ready) executor.create_orders() ``` The order-execution reference repeats the same pattern: ```python # Preview orders first (recommended) executor.create_orders(view_only=True) # Execute orders executor.create_orders() ``` ### Technical Analysis Calling `executor.create_orders()` without `view_only=True` submits live broker orders. The documented workflow places this irreversible external action directly after the preview call but does not require a fresh, explicit user confirmation between the two operations. The phrase “when ready” and the recommendation to preview are advisory only. They do not provide an enforceable control. The broader execution philosophy in `SKILL.md:10-16` encourages the Agent to execute requested work rather than merely provide instructions, increasing the likelihood that the final call could be run automatically. A preview is not a substitute for authorization. A secure workflow needs a transaction-specific confirmation after the exact account, symbols, order sides, quantities, order types, prices, estimated value, and timestamp have been displayed. It should also detect whether market data or the preview has changed before submission. ### Attack Path 1. The Agent generates or receives a backtest report. 2. `Position.from_report()` converts the report into t ...[truncated 1509 chars]
Remediation
<![CDATA[ ## Remediation Suggestions 1. Make preview-only behavior the permanent default and remove the unguarded live-execution call from general examples. 2. Require a fresh, explicit confirmation after presenting: - Broker and masked account identifier. - Symbol and market. - Buy or sell side. - Quantity. - Order type and limit price. - Estimated gross value, fees, and taxes. - Data timestamp and preview expiration time. 3. Use a separate, clearly named live-execution function rather than overloading `create_orders()` with a boolean mode. 4. Require a short-lived confirmation token tied cryptographically or structurally to the exact previewed order set. 5. Reject execution if positions, prices, account state, or market-data timestamps differ from the confirmed preview. 6. Add configurable limits for total notional value, per-symbol exposure, order count, price deviation, and daily loss. 7. Require explicit approval for each account and each batch; never reuse approval across sessions. 8. Use paper-trading or sandbox accounts by default. 9. Log previews, confirmations, submissions, broker responses, and cancellations without recording secrets. 10. Provide an immediate cancellation workflow and verify broker acknowledgements after submission. ]]>
Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
Findings (18)

Missing User Warnings

High
Confidence
98% confidence
Finding
The markdown includes actionable live order execution steps, culminating in a real order placement call, without an explicit warning that this can place real trades or cause financial loss. In context, the 'Shut Up and Run It' execution philosophy makes this more dangerous by encouraging direct action rather than cautious review.

Description-Behavior Mismatch

High
Confidence
95% confidence
Finding
The file adds live trading and order execution capabilities even though the skill metadata describes an analysis/backtesting-focused assistant. In an agent setting, this scope expansion is dangerous because it can prompt credential collection and real-money trading actions that users would not reasonably expect from a research-oriented skill.

Context-Inappropriate Capability

High
Confidence
96% confidence
Finding
The documented methods create, modify, and cancel live orders, enabling direct market actions from a skill whose declared purpose is research and backtesting. This mismatch materially increases risk because an agent or user may treat the skill as safe analytical guidance while it actually facilitates real-money trading operations.

Vague Triggers

Medium
Confidence
95% confidence
Finding
The description includes broad triggers such as trading, stock market analysis, and strategy development, which can cause the skill to activate for general financial queries not specifically about FinLab. Over-broad routing can expose users to high-risk trading workflows or domain-specific assumptions in contexts where they did not request them.

Context-Inappropriate Capability

Medium
Confidence
94% confidence
Finding
The skill goes beyond backtesting/documentation and provides concrete steps to connect a real broker account and execute orders. In an agent setting, this materially increases the chance of unauthorized or insufficiently confirmed real-world financial actions, especially because the skill elsewhere emphasizes execution over explanation.

Missing User Warnings

Medium
Confidence
91% confidence
Finding
The skill documents Line notification support, including a `line_access_token` parameter, without warning that enabling notifications transmits trading-related data and requires handling a credential. This can lead users to expose sensitive strategy outputs or mishandle access tokens, especially if they copy examples into shared notebooks, logs, or source control.

Missing User Warnings

Medium
Confidence
94% confidence
Finding
The documentation states that `upload` defaults to `True`, which means strategy performance data may be transmitted to an external service without an explicit warning or opt-in at the point of use. In a quantitative trading context, uploaded reports can contain proprietary strategy logic, holdings, symbols, timing, and performance characteristics, creating confidentiality and compliance risks if users are unaware of the external transmission.

Natural-Language Policy Violations

Medium
Confidence
87% confidence
Finding
The skill documentation relies heavily on Chinese field names, category names, and example outputs throughout the file, with no indication that users can choose another language or locale. Under the stated policy, forcing a specific language or locale without user opt-in is a natural-language policy concern.

Autonomous Decision Making

Medium
Category
Excessive Agency
Content
|------|------|---------|-------------|
| `data.use_local_data_only` | bool | False | Prevent cloud downloads; use only local cache. Raises error if data not cached. |
| `data.force_cloud_download` | bool | False | Always download fresh data from cloud, ignoring cache. |
| `data.prefer_local_if_exists` | bool | False | Use local cache without checking expiry. Faster startup. |
| `data.truncate_start` | str/None | None | Filter data to start from this date (format: `'YYYY-MM-DD'`). |
| `data.truncate_end` | str/None | None | Filter data to end at this date (format: `'YYYY-MM-DD'`). |
Confidence
75% confidence
Finding
Skill enables autonomous high-impact decisions without human-in-the-loop verification. Critical operations (destructive commands, financial transactions, data deletion) should require explicit user confirmation.

Missing User Warnings

Medium
Confidence
88% confidence
Finding
The file includes numerous concrete trading and backtesting examples that can be readily copied into workflows, but it does not include an explicit educational-only / not-financial-advice disclaimer near those examples. In a quant-trading skill, users may over-trust example strategies as endorsed or suitable for deployment, increasing the risk of harmful real-world financial decisions even though no direct code-execution exploit is present.

Context-Inappropriate Capability

Medium
Confidence
95% confidence
Finding
This section instructs users to handle brokerage credentials, account passwords, certificate paths, and personal identifiers through environment variables and code examples. In the context of an agent skill, that creates a pathway for secret exposure and unauthorized account access, especially because broker integration is outside the stated purpose of the skill.

Missing User Warnings

Medium
Confidence
90% confidence
Finding
The documentation begins credential and broker-integration guidance without any explicit warning about sensitive data, financial risk, or safe secret handling. In an assistant context, this omission makes unsafe behavior more likely by normalizing direct entry of passwords and identifiers into examples.

Natural-Language Policy Violations

Low
Confidence
91% confidence
Finding
This markdown file contains substantial Traditional Chinese content in code examples and later sections, but the document never states that the skill is Taiwan/Traditional-Chinese specific or offers an alternative language. Under the policy, forcing a specific language or locale without user opt-in can be a natural-language policy violation.

Natural-Language Policy Violations

Low
Confidence
96% confidence
Finding
This section switches entirely to Traditional Chinese and includes a timezone-specific operational instruction tied to UTC+8. Because the file does not explain that the skill is region-specific or provide a language/locale alternative, this can amount to an undocumented language/locale constraint.

Missing User Warnings

Low
Confidence
79% confidence
Finding
The file explains that FinLab caches data locally and can re-download from the cloud, including examples using `data.force_cloud_download = True`, but it does not warn that these operations initiate network access and may transmit request metadata or usage context. For markdown files, behaviors affecting privacy or system/network activity should be disclosed.

Missing User Warnings

Low
Confidence
85% confidence
Finding
This markdown file describes `data.clear()` as clearing all cached data from the current storage backend and shows calling it directly, but it does not warn that this may delete locally cached files or remove data needed for offline use. For markdown files, safety-affecting behaviors that can impact user data should include a clear warning.

Natural-Language Policy Violations

Low
Confidence
84% confidence
Finding
Natural-language content and many code identifiers are presented in Chinese throughout the file, while the document does not offer an alternative language option or explain that the skill is specifically intended for a Chinese/Taiwan-market audience. Under the language/locale policy rule, forcing a specific language without user opt-in can be a policy concern unless the locale constraint is clearly documented and justified.

Natural-Language Policy Violations

Low
Confidence
76% confidence
Finding
This markdown file includes example identifiers and data fields in Chinese, such as `股價淨值比`, `當月營收`, and `ROE稅後`, without stating that the skill is Taiwan/Chinese-market specific or offering an English/localized alternative. That can create a locale/language policy concern because the documentation implicitly assumes a specific language context without user opt-in or justification.

Static analysis

No suspicious patterns detected.