/

CVE-2024-42002

Severity:

HIGH RISK

(8.4)

Code Injection (CWE-94) in ROS 2 ros2topic CLI Tool

CVE-2024-42002

Awaiting Analysis

Vulnerability type

Category:

Code Injection

CWE:

CWE-94, CWE-95

Impact:

Arbitrary Code Execution

Severity:

HIGH RISK

(8.4)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A code injection vulnerability in the ROS 2 ros2topic hz command allows a local user to provide a Python expression through the --filter option. Because the expression is passed directly to Python's eval() without adequate sanitization, crafted input may execute arbitrary code with the permissions of the invoking process.

Affected context

The issue occurs in ROS 2 distributions that include the affected ros2topic command-line implementation and expose the hz verb's --filter option. Risk is present when a local user can invoke this command and supply or influence the filter expression, particularly in environments where the command runs with elevated permissions or access to sensitive robotics resources.

Exploit preconditions

  • Attack surface: The local ROS 2 command-line interface
  • Required access: Ability to run ros2topic hz and provide the --filter option
  • Trigger point: Processing of the user-supplied filter expression
  • Why exploitation is possible: The expression is evaluated as Python code through eval() without sufficient restriction or sanitization

Why this happens

The underlying flaw is the use of a general-purpose dynamic evaluation function on user-controlled input. Python's eval() interprets supplied text as executable code rather than treating it as inert data or a constrained expression. This behavior maps primarily to CWE-94: Improper Control of Generation of Code, with CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code also applicable.

Potential impact

  • A local attacker may execute arbitrary Python or operating-system commands
  • The attacker could access or modify files available to the ROS 2 process
  • Sensitive robotics data, credentials, or configuration may be exposed
  • Running processes, topics, or connected robot functions could be disrupted
  • Compromise could spread to other systems reachable from the affected host

General mitigation guidance

Mitigation generally focuses on removing dynamic evaluation of user-provided expressions and reducing the trust placed in command-line input.

Common defensive patterns include:

  • Replacing eval() with a narrowly defined, non-executable filter language
  • Parsing expressions with an allowlisted grammar and explicit permitted operations
  • Validating input types and structure before processing
  • Avoiding execution of command-line values as code or shell commands
  • Running ROS 2 tooling with least-privilege operating-system and ROS permissions
  • Separating monitoring functionality from sensitive robot-control capabilities

How teams detect issues like this

Organizations can identify similar risks through:

  • Static analysis rules that flag eval(), exec(), and comparable dynamic evaluation APIs
  • Code review checks for user-controlled values reaching interpreters or expression engines
  • Searches for command-line arguments passed into Python evaluation, shell execution, or template engines
  • Policy enforcement that prohibits unrestricted code evaluation in production tooling
  • Runtime monitoring for unexpected child processes, file access, or network activity from ROS 2 utilities

Automated security scanning and code review tools can help detect these patterns when configured to track data flow from CLI arguments.

Sources

SourceLink
github.comgithub.com/ros2/ros2cli/pull/1001
github.comgithub.com/ros2/ros2cli/pull/133#discussion_r223081766

Frequently asked

questions

The described attack requires local access to invoke the affected ROS 2 command and provide a filter expression. Remote exploitation could become possible indirectly if an attacker first gains control of a host or automation workflow that executes the command.

An attacker generally needs permission to run the ros2topic hz command and influence its --filter argument. The resulting impact depends on the operating-system privileges and ROS permissions of the executing process.

The safest pattern is to eliminate unrestricted eval() usage and replace it with a strictly parsed, allowlisted expression mechanism that cannot execute arbitrary Python code.

Treat command-line input as untrusted data, apply code-review and static-analysis rules for dynamic evaluation APIs, and run robotics tooling with minimal privileges and narrowly scoped access.

Find out what's already
exploitable in your codebase.