The vulnerability is a classic SQL injection within the CodeModel::all method of FacturaScripts. The root cause is the direct concatenation of user-controlled input into an SQL query string without proper sanitization or the use of prepared statements. The vulnerable parameters source, fieldcode, and fieldtitle from the autocomplete functionality map to $tableName, $fieldCode, and $fieldDescription respectively in the CodeModel::all function. This allows an authenticated attacker to inject arbitrary SQL and exfiltrate data from the database.
The patch 5c070f82665b98efd2f914a4769c6dc9415f5b0f confirms this analysis. It introduces two main changes:
- In
Core/Model/CodeModel.php, the all() and get() methods are modified to validate the $fieldCode and $fieldDescription parameters using a new isValidFieldName function. This prevents arbitrary SQL from being injected into the column name part of the query.
- In
Core/Controller/CopyModel.php, the autocompleteAction() method is updated to include a whitelist check on the source parameter, which is used as the table name. This restricts which tables can be queried, mitigating the injection vector for the table name.
Therefore, a runtime profile during exploitation would show a call stack originating from CopyModel::autocompleteAction, which then calls CodeModel::search and finally the vulnerable CodeModel::all function where the malicious SQL is executed. The CodeModel::get function was also identified as vulnerable due to the similar patch applied to it.