The vulnerability is a classic formula injection (CWE-1236) in Moodle's data export functionality. The root cause was the failure to sanitize data before including it in exported spreadsheet files (CSV, XLSX, ODS). An attacker could input a string that starts with a formula character (e.g., '=', '+', '-', '@') into any field that gets exported, such as a user's name or a forum post. When a privileged user exports this data and opens the resulting file, the spreadsheet application executes the malicious formula, potentially leading to information disclosure or other attacks.
The patch addresses this by introducing a new centralized function, core\dataformat::escape_spreadsheet_formula, which prepends a single quote (') to any value that could be interpreted as a formula. The analysis of the provided commits shows that four key functions, responsible for writing data into different spreadsheet formats, were modified to use this new escaping function. These functions (csv_writer::add_data, excel_workbook::write_string, ods_workbook::write_string, and spout_base::write_record) are the direct points of vulnerability, as they were the ones handling the unsafe data prior to the fix.