T09 · Insecure Skill Coding Practices
- Location
matlab_bridge.py:233- Finding
MATLAB Command Injection Through Unescaped Script Arguments
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
This MATLAB bridge does what it says, but it gives broad local code-execution and file-write power without enough scoping or guardrails.
Install only if you trust the users and inputs that will reach this skill. Run it in a low-privilege environment with a dedicated input/output directory, avoid passing untrusted file names, labels, template parameters, or script arguments, and review generated .mat, JSON, CSV, and plot outputs because sensitive workspace data may be saved by default.
matlab_bridge.py:233MATLAB Command Injection Through Unescaped Script Arguments
templates.py:154MATLAB Code Injection Through Unsanitized Template Parameters
The skill advertises direct MATLAB code execution, running .m scripts, file I/O, and command-line invocation, yet it declares no explicit tool scope or permission boundaries. That creates an unsafe mismatch between documented capabilities and governance, increasing the chance the agent can read, write, or execute beyond user expectations, especially because MATLAB execution can trigger arbitrary file access and shell-like side effects through the host environment.
The skill states that charts and data are automatically saved to a default local directory, but it does not prominently warn that invoking the skill causes filesystem writes. This can surprise users, overwrite prior results, leak sensitive processed data to disk, or leave artifacts on shared machines, which is especially relevant for research and engineering datasets.
Skill enumerates or reads other installed skills. Access to other skills' SKILL.md files or the skills directory reveals prompt instructions, capabilities, and secrets that should be invisible to peer skills.
| 文件 | 路径 | 说明 |
|------|------|------|
| 技能文档 | `skills/matlab-bridge/SKILL.md` | 完整使用说明 |
| 主脚本 | `skills/matlab-bridge/matlab_bridge.py` | MATLAB桥接核心类 |
| 模板库 | `skills/matlab-bridge/templates.py` | 常用MATLAB代码模板 |
| 快速执行 | `skills/matlab-bridge/matlab_quick.py` | 命令行快速调用 |
The example trigger phrases are very broad and read like natural requests to the agent, without clear activation boundaries or confirmation requirements. In a skill that can execute MATLAB code and scripts, this increases the chance of unintended invocation or prompt-based routing into code execution workflows from ordinary user phrasing.
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
"""检查MATLAB是否可用"""
try:
cmd = [self.matlab_path, '-batch', "disp('OK')"]
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
return 'OK' in result.stdout or result.returncode == 0
except:
return False
The skill is explicitly designed to execute arbitrary MATLAB code provided by the caller, but it does so without any safety interlocks, trust checks, or user-facing warning about the consequences. In this context, the danger is elevated because MATLAB is a powerful execution environment that can read/write files, invoke system commands, process sensitive data, and create persistent artifacts on the host.
This call launches MATLAB to execute code derived from untrusted input via execute(code: str), which writes attacker-supplied MATLAB code into a temporary .m file and runs it. In skill context, this is the core feature, but it still enables arbitrary code execution inside the MATLAB environment, including filesystem access, external command execution, network operations, and abuse of licensed local resources.
f"cd('{temp_dir}'); {temp_name}"
]
result = subprocess.run(
cmd,
capture_output=capture_output,
text=True,
The bridge persists result JSON and, by default, the entire MATLAB workspace to disk in a shared output directory without clear disclosure or retention controls. This can unintentionally store sensitive input data, derived results, credentials loaded into the workspace, or proprietary models, increasing the risk of data leakage and cross-run exposure.
This subprocess call runs MATLAB with a command string assembled from script_path and args, both of which may be user-controlled. Although Python is not invoking a shell, the MATLAB -batch command string can still be syntactically broken or extended through unsafely embedded values, especially string arguments and directory/script names containing quotes, enabling arbitrary MATLAB command injection and execution.
]
try:
result = subprocess.run(
full_cmd,
capture_output=True,
text=True,
The file's natural-language title, comments, and docstrings are presented exclusively in Chinese, indicating a fixed language/locale choice. There is no indication that users can opt into another language or that the locale restriction is explicitly justified as region-specific.
This Python file contains natural-language descriptions, prompts, and help text in Chinese, beginning with the module docstring and continuing throughout user-facing output. Because the skill forces a specific language without user opt-in or a documented justification that it is region-specific, it conflicts with the language/locale policy criteria.
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
# 尝试执行 matlab 命令
try:
result = subprocess.run(
["matlab", "-batch", "disp('MATLAB_IS_AVAILABLE')"],
capture_output=True,
text=True,
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
print(" 状态: ✓ MATLAB 命令可用")
# 获取版本信息
version_result = subprocess.run(
["matlab", "-batch", "disp(version)"],
capture_output=True,
text=True,
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
print(f"\n2. 许可证检查")
try:
result = subprocess.run(
["matlab", "-batch", "license('test', 'MATLAB')"],
capture_output=True,
text=True,
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
"""
try:
result = subprocess.run(
["matlab", "-batch", test_code],
capture_output=True,
text=True,
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
"""
try:
result = subprocess.run(
["matlab", "-batch", test_code],
capture_output=True,
text=True,
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
"""
try:
result = subprocess.run(
["matlab", "-batch", test_code],
capture_output=True,
text=True,
The markdown explicitly states that all generated charts and data are saved under D:\Personal\OpenClaw\matlab-outputs\, including images, .mat files, and JSON results. This is a user-data and filesystem-impacting behavior, but the README does not include any caution or disclosure about automatic file creation, persistence, or potential overwriting/accumulation of outputs.
The description text is entirely in Chinese and does not indicate that other languages are supported or that Chinese is a justified region-specific requirement. Per the policy rule, forcing a specific language without user opt-in can be a natural-language policy violation.
All user-facing instructions and invocation examples in this file are presented only in Chinese, including the directive for how to address the system. That can constitute a language/locale policy issue when no user opt-in or alternative language choice is offered.
Natural-language strings throughout the file, including the module description and CLI help, are presented in Chinese only. This imposes a specific language on users without opt-in or explanation, which fits the locale/language policy violation criteria.
This Python skill presents its description, usage instructions, and runtime status messages entirely in Chinese, with no indication that the user can choose another language. That creates a natural-language locale policy issue because the skill imposes a specific language experience without documented opt-in or justification.
The script writes a generated plot to a fixed absolute path on the local filesystem, which can create unintended side effects outside the immediate test context. Hardcoded output locations may overwrite existing files, leak artifacts into sensitive directories, or fail unpredictably across environments, especially when the skill is run with elevated privileges or on multi-user systems.