The vulnerability is a SQL injection in the ORDER BY clause of the FacturaScripts REST API, exploitable via the sort parameter. The analysis of the provided security advisory and the associated commit patch confirms the vulnerability in two main locations.
-
Modern Models (DbQuery::orderBy): The commit 1b6cdfa9ee1bb3365ea4a4ad753452035a027605 clearly shows the vulnerable code in Core/DbQuery.php. The orderBy function previously allowed any string containing parentheses to be directly included in the SQL query. The patch rectifies this by adding a whitelist validation for functions like LOWER(), UPPER(), and CAST().
-
Legacy Models (ModelClass::getOrderBy): The security advisory explicitly identifies Core/Model/Base/ModelClass.php and its getOrderBy method as vulnerable. It states that user-supplied sorting parameters are directly concatenated into the SQL query. The ModelClass::all method is the entry point that receives the malicious sort parameter from the API and passes it to getOrderBy.
The Proof of Concept demonstrates the vulnerability by injecting a SLEEP() function into the sort parameter's key, causing a time-based blind SQL injection. This confirms that the application fails to sanitize the keys of the sort array, which are then used to construct the ORDER BY clause.
Based on this evidence, the identified vulnerable functions are DbQuery::orderBy for modern models and ModelClass::getOrderBy (called by ModelClass::all) for legacy models. These functions would appear in a runtime profile during the exploitation of this vulnerability.