T09 · Insecure Skill Coding Practices
- Location
scripts/lowrank_compress.py:99- Finding
Unsafe NumPy Archive Deserialization with Pickle Enabled
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
The skill mostly matches its local Ollama compression purpose, but it includes an unsafe compressed-file loader and automatic local process launching that merit review before installation.
Review the Python scripts before installing, use an isolated virtual environment with pinned dependencies, and do not load compressed .npz/.npy files from untrusted sources unless allow_pickle is removed. Expect the launch helper to run local Ollama commands and potentially leave an Ollama service running.
scripts/lowrank_compress.py:99Unsafe NumPy Archive Deserialization with Pickle Enabled
SKILL.md:30Unpinned Third-Party Dependency Installation
External input (network, user) flows to a code execution sink. This enables remote code execution or command injection.
break
# 调用 ollama
result = subprocess.run(
["ollama", "run", model, user_input],
capture_output=True, text=True, timeout=120
)
Using shell=True causes the shell to interpret the command string, which is a classic command-injection sink. Although this script currently builds command strings from fixed literals rather than CLI arguments, the utility function normalizes an unsafe pattern across the codebase and skill context, making later misuse likely and potentially leading to arbitrary OS command execution.
def run_cmd(cmd, timeout=5):
"""执行命令并返回输出"""
try:
result = subprocess.run(
cmd, shell=True, capture_output=True,
text=True, timeout=timeout
)
Skill selects an external model or provider that may use a different account or billing plan than the operator expects. Undisclosed model switches can cause unexpected cost or quota consumption.
下一步:
1. 安装 Ollama: https://ollama.com
2. 下载模型: ollama pull llama3
3. 使用压缩启动: python scripts/launch_compressed.py --model llama3 --compress
""")
Using shell=True for a simple status check is an avoidable tool-parameter abuse pattern because it grants shell interpretation where none is needed. In an agent or automation context, even constant shell commands are more dangerous because future refactors or environmental influence can turn a harmless check into command execution exposure.
def check_ollama_running() -> bool:
"""检查 Ollama 是否在运行"""
result = subprocess.run(
"tasklist | findstr ollama",
shell=True, capture_output=True, text=True
)
The skill documentation is written entirely in Chinese, including headings, usage guidance, warnings, and examples, with no indication that users may choose another language or that the skill is intended only for a Chinese-speaking context. This can violate language/locale policy when a skill imposes a specific language without user opt-in or documented justification.
The entire skill description is written in Chinese, with no indication that other languages are supported or that the locale restriction is intentional and justified. Under the language/locale policy, forcing a specific language without user opt-in can be a natural-language policy violation.
This code file contains natural-language strings that force a specific language/locale for all users, including the module docstring and runtime messages. Under the policy, locale-specific language is only acceptable when users can opt in or when the restriction is explicitly justified, neither of which is present here.
The helper executes arbitrary shell command strings via subprocess.run(..., shell=True). In this file the current callers use hardcoded commands, so immediate exploitability is limited, but the wrapper is generic and unsafe by design: any future or indirect use with user-controlled input would enable command injection and arbitrary command execution.
def run_cmd(cmd, timeout=5):
"""执行命令并返回输出"""
try:
result = subprocess.run(
cmd, shell=True, capture_output=True,
text=True, timeout=timeout
)
This Python file contains natural-language documentation and user-facing output entirely in Chinese, beginning with the module docstring. Under the policy, forcing a specific language without user opt-in is a locale/language policy violation unless the tool is clearly documented as region-specific, which is not stated here.
This uses shell=True to execute a shell pipeline, which unnecessarily invokes the Windows shell and increases command-execution risk. Although the command string is constant and not directly user-controlled here, shell invocation expands the attack surface and can be abused via environment manipulation, shell behavior, or future code changes that introduce untrusted input.
def check_ollama_running() -> bool:
"""检查 Ollama 是否在运行"""
result = subprocess.run(
"tasklist | findstr ollama",
shell=True, capture_output=True, text=True
)
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
try:
# Windows: 启动 ollama serve
subprocess.Popen(
["ollama", "serve"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
break
# 调用 ollama
result = subprocess.run(
["ollama", "run", model, user_input],
capture_output=True, text=True, timeout=120
)
The argparse description, help strings, and other runtime messages are all written in Chinese, with no option for users to choose another language. Because this is user-facing natural language in a general-purpose script, it constitutes a language policy issue under the stated rules.
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
# 列出模型
if args.list_models:
print("已下载的模型:")
subprocess.run(["ollama", "list"])
return
# 启动 Ollama
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
else:
# 直接运行(单次查询)
try:
result = subprocess.run(cmd, timeout=120)
sys.exit(result.returncode)
except Exception as e:
print(f"运行出错: {e}")
This finding describes the same unsafe behavior in the file-loading path: the method appears to load compressed numeric data, but it enables pickle-capable deserialization. That mismatch is dangerous because callers may reasonably assume the routine is safe for ordinary data files when it can actually deserialize attacker-controlled objects.
The loader calls numpy.load with allow_pickle=True on a user-supplied filepath, which permits deserialization of pickled object arrays. If an attacker can supply or replace the .npz/.npy file, loading it may execute arbitrary code during deserialization, making this a genuine insecure deserialization issue.
def load_compressed(self, filepath: str):
"""从文件加载压缩数据"""
data = np.load(filepath, allow_pickle=True)
self.U = data["U"]
self.S = data["S"]
self.Vt = data["Vt"]
The markdown states that the skill can '一键启动压缩模式' by changing Ollama startup parameters, but it does not warn the user about possible configuration impact or that local runtime behavior may be altered. For a markdown file, configuration-affecting behavior should be disclosed when it could affect system integrity or runtime setup.
This is a natural-language policy issue because the file forces a specific language for its title and description, and the same pattern continues in user-visible strings throughout the script. There is no indication that the tool is region-specific or that users can opt into another language.
The file’s user-facing description and instructional text are written entirely in Chinese, and the script’s visible CLI/demo output and error guidance continue that assumption. Under the policy, language constraints should either offer user choice or be clearly justified as region-specific; this file does neither.