CVE-2022-24770
Gradio Arbitrary command execution in CSV files; fixed in v2.8.11
- CVSS 8.8
- CWE-1236 Improper Neutralization of Formula Elements in a CSV File
- Input Validation and Sanitization
- Local
`gradio` is an open source framework for building interactive machine learning models and demos. Prior to version 2.8.11, `gradio` suffers from Improper Neutralization of Formula Elements in a CSV File. The `gradio` library has a flagging functionality which saves input/output data into a CSV file on the developer's computer. This can allow a user to save arbitrary text into the CSV file, such as commands. If a program like MS Excel opens such a file, then it automatically runs these commands, which could lead to arbitrary commands running on the user's computer. The problem has been patched as of `2.8.11`, which escapes the saved csv with single quotes. As a workaround, avoid opening csv files generated by `gradio` with Excel or similar spreadsheet programs.
- CVSS base score
- 8.8
- Published
- 2022-03-17
- OWASP
- A03 Injection
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Local
- Impact
- Arbitrary Code Execution
- Affected component
- gradio
- Fixed by upgrading
- Yes
Solution
Update gradio to version 2.8.11 or higher.
Vulnerable code sample
import pandas as pd
def save_to_csv(data, filename):
# Directly saving data without escaping
df = pd.DataFrame(data)
df.to_csv(filename, index=False)
# Example usage
data = [
["Name", "Score"],
["Alice", "=SUM(1+1)"],
["Bob", "100"]
]
save_to_csv(data, 'output.csv')Patched code sample
import pandas as pd
def save_to_csv(data, filename):
# Escape the data to prevent formula injection
escaped_data = [[f"'{str(item)}" if isinstance(item, str) and item.startswith('=') else item for item in row] for row in data]
df = pd.DataFrame(escaped_data)
df.to_csv(filename, index=False)
# Example usage
data = [
["Name", "Score"],
["Alice", "=SUM(1+1)"],
["Bob", "100"]
]
save_to_csv(data, 'output.csv')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.
- sanitize flagging inputs before writing to csv (gradio-app/gradio)
gradio/flagging.py,gradio/flagging.py · CSVLogger.flag,gradio/flagging.py · HuggingFaceDatasetSaver.flag,gradio/flagging.py · SimpleCSVLogger.flag,gradio/utils.py
Cite this entry
@misc{vaitp:cve202224770,
title = {{Gradio Arbitrary command execution in CSV files; fixed in v2.8.11}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2022},
note = {VAITP Python Vulnerability Dataset, entry CVE-2022-24770},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-24770/}}
}
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 ::
