T09 · Insecure Skill Coding Practices
- Location
assets/strategy_template.py:4978- Finding
Arbitrary Code Execution Through Unsafe Pickle Deserialization
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
This Ptrade skill contains broad live trading, account-operation, margin/futures, and persistent state code with unclear scoping that users should review carefully before installing.
Review this as live brokerage automation, not just educational strategy notes. Do not install or copy the bundled templates into Ptrade unless you separate the examples, remove or gate fund-transfer, margin, futures, IPO, and reverse-repo actions, replace pickle state with safe serialization, and test only in a sandbox/backtest account with explicit order confirmations.
assets/strategy_template.py:4978Arbitrary Code Execution Through Unsafe Pickle Deserialization
assets/strategy_template.py:27Concatenated Template Silently Activates a Leveraged Futures Strategy
The document includes fund-transfer capabilities, which go beyond strategy assistance into direct asset movement. In a brokerage context this is especially dangerous because misuse or accidental adoption could move cash between venues/accounts and amplify loss, fraud, or operational damage beyond a single trade.
Mixing characters from multiple Unicode scripts in a single identifier is a common technique to create visually ambiguous tool names.
Mixing characters from multiple Unicode scripts in a single identifier is a common technique to create visually ambiguous tool names.
Mixing characters from multiple Unicode scripts in a single identifier is a common technique to create visually ambiguous tool names.
This finding correctly identifies that the actual content does not implement many of the claimed assistant features while instead providing executable strategy material. The main risk is misleading scope and user overtrust rather than direct code exploitation, but in a financial automation context that still has meaningful safety impact.
This finding correctly identifies that the actual content does not implement many of the claimed assistant features while instead providing executable strategy material. The main risk is misleading scope and user overtrust rather than direct code exploitation, but in a financial automation context that still has meaningful safety impact.
This finding correctly identifies that the actual content does not implement many of the claimed assistant features while instead providing executable strategy material. The main risk is misleading scope and user overtrust rather than direct code exploitation, but in a financial automation context that still has meaningful safety impact.
This finding correctly identifies that the actual content does not implement many of the claimed assistant features while instead providing executable strategy material. The main risk is misleading scope and user overtrust rather than direct code exploitation, but in a financial automation context that still has meaningful safety impact.
This finding correctly identifies that the actual content does not implement many of the claimed assistant features while instead providing executable strategy material. The main risk is misleading scope and user overtrust rather than direct code exploitation, but in a financial automation context that still has meaningful safety impact.
The skill promotes live trading automation and practical execution guidance without an explicit warning about real-money consequences. In the context of automated brokerage operations, omission of such warnings materially increases the likelihood of unsafe use, overtrust, and accidental financial harm.
The skill presents itself as a strategy assistant, but these sections expose concrete trading APIs and workflows that can be used to place real orders. In the context of retail or brokerage automation, this is dangerous because it lowers the barrier to executing financially impactful actions under the guise of 'assistance' documentation.
Bulk IPO subscription capability is not inherently malicious, but it materially expands the operational scope of the skill beyond analysis/support. That mismatch is risky because users may trigger or rely on instructions for capital deployment actions they did not expect the skill to facilitate.
The reverse-repurchase strategy and account/order/position query helpers directly interact with available cash, orders, and holdings. In a real brokerage setting, this is dangerous because it extends the skill from passive assistance into active cash deployment and sensitive account-state handling without matching scope declarations.
The file is described as a strategy template/helper, but actually contains a large catalog of directly executable strategies with order placement logic across equities, ETFs, futures, margin, and reverse repo. That mismatch expands the operational attack surface and creates a dangerous capability gap where users may invoke live trading behavior they did not reasonably expect from a helper skill.
The inclusion of margin trading, futures trading, and reverse repurchase logic goes beyond the stated quant-assistant purpose and materially increases risk. These features can create leveraged or non-cash exposures, so misuse or compromise would have amplified financial impact compared with ordinary strategy analysis tooling.
The trigger list includes generic finance phrases such as “双均线策略”, “金叉死叉”, “量化回测”, “金叉买入”, and “死叉卖出” without contextual limits. These are common terms in normal discussion of trading strategies, so the skill could activate unintentionally when a user is merely talking about markets rather than invoking this specific skill.
L04318 的注释写明“使用80%的可用资金买入”,但下一行实际赋值为 buy_value = cash * 1.0,并将全部可用现金用于买入。这里不是简单遗漏,而是注释对资金使用比例作出了与代码相反的明确表述。
技能描述强调策略辅助、生成、分析和指导,但这里会在研究路径下读写 pickle 文件保存计数状态;同文件注释中还包含维护本地财报 CSV 的实现路径。对一个以策略辅助和分析为主的技能而言,本地持久化并不是显式声明的能力,也不是该目的的明显必需项。
This code writes and later reads persistent state files (count.pkl and firstcount.pkl) under the research path, which modifies local filesystem state across runs. Although the code comments describe the mechanics, there is no user-facing confirmation, warning, or disclosure that the skill will create and maintain local files.
The code uses pickle.load() on files under NOTEBOOK_PATH without any integrity check, type restriction, or trust boundary enforcement. In Python, pickle deserialization can execute attacker-controlled code during loading, so if an attacker can replace or tamper with count.pkl they can achieve arbitrary code execution in the strategy process.
pickle.dump(0,f,-1)
try:# 从文件中读取count和firstcount的值
with open(NOTEBOOK_PATH+'count.pkl','rb') as f:
g.count = pickle.load(f)
log.info("策略重启初始化,从文件中读取本策略当前交易日: %s" % (g.count))
with open(NOTEBOOK_PATH+'firstcount.pkl','rb') as f:
g.trade_count = pickle.load(f)
This second pickle.load() reads firstcount.pkl from local storage and has the same unsafe deserialization property. Because this skill runs in a trading automation context, successful exploitation could let an attacker run arbitrary code and then place unauthorized orders, alter strategy state, or exfiltrate account information.
g.count = pickle.load(f)
log.info("策略重启初始化,从文件中读取本策略当前交易日: %s" % (g.count))
with open(NOTEBOOK_PATH+'firstcount.pkl','rb') as f:
g.trade_count = pickle.load(f)
log.info("策略重启初始化,从文件中读取本策略运行第%s个交易日" % (g.trade_count))
except Exception as e:
log.error("读取count和firstcount文件失败: %s" % (e))
record_counters overwrites local pickle files on disk during routine execution, which is a file write operation with persistent side effects. The implementation lacks a user-facing warning or explicit disclosure near the operation that strategy state is being saved locally.
This block creates and updates a local finance_data.csv cache, potentially storing sizable historical financial data on disk. While the comments explain the purpose, there is no clear user-facing disclosure that the skill will create and maintain local cache files.
L6013 明确写明“改买入委托方式为限价单”,给人以该段实现已切换为限价委托的理解。然而实际买入实现 open_position 在 L6799 直接调用 order_value(stock, vol),并未传入限价参数,也未使用对应限价接口,和注释表达的交易意图相矛盾。
This duplicated strategy section again initializes and reads local pickle state files, creating persistent filesystem side effects. The code lacks a clear warning to users that running the strategy will read/write local state files across sessions.