Back to skill

Security audit

ROS2 Control Introspection

Security checks for vulnerabilities and agentic risk

Overview

The skill is mostly aligned with read-only ROS 2 introspection, but its wrapper can execute unintended local shell commands if its generated ROS setup path is tampered with or contains shell-special characters.

Install only if you trust the local ROS installation and the generated config/config.json. Review or fix the wrapper so the setup path is passed as a quoted positional argument or otherwise strictly validated before running it, and avoid running this skill in privileged shells.

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

T09 · Insecure Skill Coding Practices

Error
Location
scripts/safe_ros2_control_introspection.py:42
Finding

Shell Command Injection Through Unquoted ROS Setup Path

Content
View full analysis

Vulnerability Details

File Location: scripts/safe_ros2_control_introspection.py, lines 42–55
Vulnerability Type: OS command injection through unsafe shell-string construction
Risk Level: High

Vulnerable Code

python
ros_setup_path = config.get("ros_setup_path")

if not ros_setup_path or not os.path.isfile(ros_setup_path):
    print("Error: ROS_SETUP_PATH invalid. Run setup.sh.", file=sys.stderr)
    sys.exit(1)

# Build the environment
env_command = f"source {ros_setup_path} && env"
try:
    env_proc = subprocess.run(['bash', '-c', env_command], stdout=subprocess.PIPE, text=True, check=True)
    ros_env = {}
    for line in env_proc.stdout.splitlines():
        if '=' in line:
            key, val = line.split('=', 1)
            ros_env[key] = val

Technical Analysis

The ros_setup_path value is loaded from config/config.json and interpolated directly into a command string executed by bash -c. Because the path is neither quoted nor passed as a positional argument, shell metacharacters in the configured filename are interpreted as Bash syntax.

The os.path.isfile(ros_setup_path) check does not prevent injection. It only verifies that a file exists at the complete literal path. Unix filenames can contain spaces and shell metacharacters such as semicolons and comment characters. Consequently, a specially named existing file can satisfy this validation while its path is parsed as multiple commands by Bash.

This also contradicts the security assurance in SKILL.md that command injection is prevented through subprocess with shell=False. Although the final ROS command avoids a shell, this earlier environment-construction operation explicitly invokes bash -c.

Attack Path

  1. An attacker gains the ability to modify config/config.json or influences setup through a crafted local ROS installation path.
  2. The attacker creates a file whose path contains Bash c ...[truncated 1198 chars]
Remediation
View remediation

Remediation Suggestions

Do not interpolate the setup path into executable shell text. Supply it as a positional parameter and quote that parameter inside the fixed Bash program:

python
env_proc = subprocess.run(
    ["bash", "-c", 'source "$1" && env', "bash", ros_setup_path],
    stdout=subprocess.PIPE,
    text=True,
    check=True,
)

In addition:

  1. Resolve the setup path with Path.resolve() and require it to reside under an explicitly trusted ROS installation root.
  2. Reject configuration files that are writable by untrusted users, and ensure the generated config directory and config.json have restrictive ownership and permissions.
  3. Treat ROS setup files as executable code and only source trusted, administrator- or user-controlled files.
  4. Generate config.json with a proper JSON encoder rather than manually interpolating shell-derived values in setup.sh.
  5. Add regression tests using paths containing spaces, semicolons, command substitutions, quotes, and newline characters to verify they remain literal arguments.
  6. Update SKILL.md so its command-injection claims cover every subprocess invocation, not only the final ros2 execution.
Vulnerability Patterns
  • Behavioral ASTexec() Call, eval() Call, Dynamic Import
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (3)

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
93% confidence
Finding

The skill instructs the agent to read local files and execute a shell-based setup/workflow, but it does not declare any explicit tool scope such as permissions or allowed-tools. Even though the prose emphasizes a read-only wrapper and mentions shell=False, the agent is still being guided to source environment scripts and run local setup commands, which expands execution capability without a machine-enforced boundary.

Content

No source excerpt is available for this finding.

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
96% confidence
Finding

The wrapper constructs a shell command with source {ros_setup_path} && env and executes it via bash -c. Although ros_setup_path comes from a JSON config rather than direct CLI input, it is still unquoted/unescaped shell data; a malicious or tampered config could inject arbitrary shell syntax and execute commands before the environment is captured. In this skill context, sourcing a setup script already executes code, so trusting a configurable path significantly increases risk despite the read-only/introspection intent.

Content

Scanner excerpt · scripts/safe_ros2_control_introspection.py (reported line 53)May include surrounding context.

python
# Build the environment
    env_command = f"source {ros_setup_path} && env"
    try:
        env_proc = subprocess.run(['bash', '-c', env_command], stdout=subprocess.PIPE, text=True, check=True)
        ros_env = {}
        for line in env_proc.stdout.splitlines():
            if '=' in line:

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/safe_ros2_control_introspection.py (reported line 91)May include surrounding context.

python
cmd_array.extend(extra)

    # Execute safely without shell=True
    sys.exit(subprocess.call(cmd_array, env=ros_env))

if __name__ == "__main__":
    main()