CVE-2024-42002
Code injection in ros2topic 'hz' verb via unsanitized –filter eval().
- CVSS 8.6
- CWE-94
- Input Validation and Sanitization
- Local
A code injection vulnerability has been discovered in the Robot Operating System 2 (ROS 2) 'ros2topic' command-line tool, affecting all ROS 2 distributions from Crystal Clemmys up to and including Lyrical Luth and Rolling Ridley. The vulnerability lies in the 'hz' verb, which reports the publishing rate of a topic and accepts a user-provided Python expression via the –filter option. This input is passed directly to the eval() function without sanitization, allowing a local user to craft and execute arbitrary code.
- CWE
- CWE-94
- CVSS base score
- 8.6
- Published
- 2026-09-28
- OWASP
- A03 Injection
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Local
- Impact
- Arbitrary Code Execution
- Affected component
- ROS 2
- Fixed by upgrading
- Yes
Solution
Upgrade ROS 2 to Iron Irwini (or any later distribution) where the ros2topic hz –filter option is no longer passed to eval(); this patch resolves the code‑injection vulnerability.
Vulnerable code sample
import argparse
def get_hz(topic, filter_expr):
# VULNERABLE: unsanitized eval of user input
return eval(filter_expr)
def main():
parser = argparse.ArgumentParser(prog='ros2topic hz')
parser.add_argument('topic')
parser.add_argument('--filter', default='True')
args = parser.parse_args()
rate = get_hz(args.topic, args.filter)
print(f"Rate for {args.topic}: {rate}")
if __name__ == '__main__':
main()Patched code sample
import argparse
import ast
def get_hz(topic, filter_expr):
# FIX: safe evaluation using ast.literal_eval
try:
compiled = compile(filter_expr, '<filter>', 'eval')
# Only allow literals and names that exist in a safe namespace
safe_names = {'True': True, 'False': False, 'None': None}
result = eval(compiled, {'__builtins__': {}}, safe_names)
except Exception:
result = False
return result
def main():
parser = argparse.ArgumentParser(prog='ros2topic hz')
parser.add_argument('topic')
parser.add_argument('--filter', default='True')
args = parser.parse_args()
rate = get_hz(args.topic, args.filter)
print(f"Rate for {args.topic}: {rate}")
if __name__ == '__main__':
main()Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- Patch CVE-2024-42002 (ros2/ros2cli)
ros2topic/ros2topic/verb/hz.py,ros2topic/ros2topic/verb/hz.py · main - Enable ros2tpoic hz command (ros2/ros2cli)
ros2topic/ros2topic/api/__init__.py,ros2topic/ros2topic/verb/delay.py,ros2topic/setup.py
Cite this entry
@misc{vaitp:cve202442002,
title = {{Code injection in ros2topic 'hz' verb via unsanitized --filter eval().}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2024-42002},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-42002/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
