Skip to main content
Vulnerability Database/CVE-2024-42002

CVE-2024-42002: ROS 2 ros2topic Command Injection Vulnerability

CVE-2024-42002 is a code injection flaw in ROS 2 ros2topic command-line tool that enables local attackers to execute arbitrary code through unsanitized input. This article covers technical details, affected distributions, and mitigation.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2024-42002 Overview

CVE-2024-42002 is a code injection vulnerability in the Robot Operating System 2 (ROS 2) ros2topic command-line tool. The flaw affects all ROS 2 distributions from Crystal Clemmys through Lyrical Luth and Rolling Ridley. The hz verb, which reports the publishing rate of a topic, accepts a Python expression via the --filter option. This input flows directly into Python's eval() function without sanitization. A local attacker who can supply or influence the filter argument can execute arbitrary Python code in the context of the invoking user. The weakness is classified under CWE-94: Improper Control of Generation of Code.

Critical Impact

Local attackers can execute arbitrary Python code with the privileges of the user running ros2topic hz --filter, compromising confidentiality, integrity, and availability of the robotic system.

Affected Products

  • ROS 2 distributions: Crystal Clemmys through Lyrical Luth
  • ROS 2 Rolling Ridley
  • The ros2topic package within the ros2cli project

Discovery Timeline

  • 2026-09-28 - CVE-2024-42002 published to the National Vulnerability Database
  • 2026-09-30 - Last updated in NVD database

Technical Details for CVE-2024-42002

Vulnerability Analysis

The ros2topic hz verb measures how frequently messages are published to a ROS 2 topic. It exposes a --filter option that lets operators evaluate an expression against each incoming message before counting it. The implementation passes the filter string directly to Python's built-in eval() function. Because eval() executes any valid Python expression, an attacker who controls the --filter value can call arbitrary functions, import modules, spawn subprocesses, or read and write files. The vulnerability requires local access but no authentication or user interaction beyond invocation of the vulnerable command. Because ROS 2 tooling frequently runs on robotics platforms, industrial controllers, and autonomous vehicles, successful exploitation can pivot from a low-privilege shell to full control of the host and connected physical systems.

Root Cause

The root cause is unsafe use of eval() on untrusted input. The --filter argument is treated as a trusted Python expression rather than opaque data. No allow-list, sandbox, or AST-based parser constrains the accepted syntax. As documented in the referenced ros2cli discussion, the risk of eval() on user-supplied strings was known to maintainers before the fix in pull request #1001.

Attack Vector

Exploitation requires the ability to invoke ros2topic hz with attacker-controlled --filter content on a system with a vulnerable ROS 2 distribution. Attack scenarios include: a lower-privileged user running the command against a shared ROS 2 environment, a script or launch file that interpolates untrusted data into the --filter argument, or a compromised automation pipeline that constructs ros2topic invocations. Any Python payload passed via --filter executes with the privileges of the invoking process, for example __import__('os').system('id').

No verified proof-of-concept code is published in the referenced advisories. See the linked ros2cli pull request for the corrective patch details.

Stop Remote Code Execution Before It Runs

Singularity™ Endpoint detects and blocks exploit attempts at machine speed, including zero-days and novel attack techniques.

Stop Exploit Attempts

Detection Methods for CVE-2024-42002

Indicators of Compromise

  • Shell history or process accounting entries showing ros2topic hz invocations with unusual --filter values containing __import__, os.system, subprocess, open(, or exec(.
  • Unexpected child processes spawned from ros2topic or its Python interpreter.
  • ROS 2 nodes writing to filesystem paths or opening network sockets that fall outside their normal behavior.

Detection Strategies

  • Audit command-line arguments for any process whose executable path resolves to ros2topic and alert on --filter values containing Python dunder attributes or import statements.
  • Use eBPF or auditd rules on Linux robotics hosts to capture execve calls where ros2topic is the parent and the child is a shell, interpreter, or networking utility.
  • Review ROS 2 launch files, systemd units, and CI pipelines for string concatenation that builds --filter arguments from external input.

Monitoring Recommendations

  • Forward process telemetry from ROS 2 hosts to a centralized analytics platform and baseline normal ros2topic usage.
  • Alert on any child process of ros2topic that is not part of the ROS 2 runtime.
  • Track package versions of ros2cli and ros2topic across the fleet to identify hosts still running vulnerable distributions.

How to Mitigate CVE-2024-42002

Immediate Actions Required

  • Upgrade ros2cli and ros2topic to a version that includes the fix from ros2cli pull request #1001.
  • Restrict local shell access on ROS 2 hosts to trusted operators only.
  • Audit scripts, launch files, and automation that call ros2topic hz --filter and remove any interpolation of untrusted data.

Patch Information

The upstream fix is delivered through ros2cli pull request #1001, which removes the unsafe use of eval() in the hz verb. Apply the patched package for your ROS 2 distribution through the official apt or pip channels. For end-of-life distributions in the Crystal Clemmys through Lyrical Luth range, migrate to a supported release that contains the fix.

Workarounds

  • Avoid using the --filter option of ros2topic hz until the patched package is deployed.
  • Wrap ros2topic invocations in a validator that rejects any --filter value containing characters or tokens outside a strict allow-list, such as message field names, numeric literals, and comparison operators.
  • Run ROS 2 tooling under a dedicated low-privilege account and apply mandatory access controls, for example AppArmor or SELinux profiles, to constrain what the Python interpreter can execute or access.
bash
# Configuration example: block use of the vulnerable --filter option via a wrapper
#!/usr/bin/env bash
if printf '%s\n' "$@" | grep -q -- '--filter'; then
  echo "ros2topic --filter is disabled pending CVE-2024-42002 remediation" >&2
  exit 1
fi
exec /opt/ros/<distro>/bin/ros2topic "$@"

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.