T09 · Insecure Skill Coding Practices
- Location
scripts/safe_ros2_control_execution.py:43- Finding
Untrusted ROS setup script execution and shell injection through an unquoted configuration path
- Content
View full analysis
/dev/null) if [ -z "$ROS2_BIN" ]; then echo "Error: ros2 not found in PATH. Please source your ROS 2 environment before running setup." exit 1 fi ROS_SETUP_PATH="$(dirname "$(dirname "$ROS2_BIN")")/setup.bash" ``` ### Technical Analysis The wrapper reads `ros_setup_path` from `config/config.json` and interpolates it directly into a command executed using `bash -c`. Although `os.path.isfile()` verifies that the referenced path exists, it does not make the path safe for shell interpretation. A valid filename can contain spaces and shell metacharacters, causing Bash to interpret portions of the configured value as additional syntax. More fundamentally, the referenced file is intentionally sourced as executable shell code. `scripts/setup.sh` determines this trusted setup file from whichever `ros2` executable appears first in the caller-controlled `PATH`. It does not canonicalize the result or verify that the executable and derived `setup.bash` belong to a trusted, administrator-owned ROS installation. The final ROS command uses an argument array and does not use `shell=True`, but that protection does not apply to the earlier environment-initialization command. Consequently, the documentation's ...[truncated 1896 chars]- Remediation
View remediation
` directory. 3. During setup, use `command -v ros2`, canonicalize the result, and reject executables or setup files located in user-writable or unexpected directories. 4. Verify ownership and permissions for the ROS executable, its installation directory, and `setup.bash`. For system installations, require administrator ownership and reject files writable by untrusted users or groups. 5. Protect `config/config.json` with restrictive permissions and write it atomically. Treat every value read from it as untrusted configuration rather than as executable shell input. 6. Prefer constructing the required ROS environment without sourcing dynamically selected shell code. If this cannot be avoided, configure the trusted setup file explicitly rather than inferring it from `PATH`. 7. Add regression tests covering paths containing spaces, semicolons, command substitutions, quotes, and newline characters, as well as tests ensuring that untrusted ROS installation roots are rejected. ]]>
