The analysis of the provided patch reveals two instances of a classic SQL injection vulnerability (CWE-89) within the NocoBase application. The root cause in both cases is the unsafe construction of SQL queries using template literals and string concatenation with user-controllable data, instead of using parameterized queries (prepared statements).
-
The first vulnerable function, queryParentSQL, is located in the core database package. It is used for recursive eager loading of tree structures. The nodeIds, which are primary keys and can be controlled by an attacker with record-creation permissions, are directly embedded into the SQL query. The patch remediates this by replacing the string concatenation with bind parameters ($1, $2, etc.), ensuring the database driver properly handles the input and prevents injection.
-
The second vulnerable function is SortField.init within the plugin-field-sort package. A similar injection pattern exists when initializing sort values for a scoped field. The scopeValue is concatenated directly into the WHERE clause. The patch applies the same fix, using bind parameters to safely include the scopeValue in the query.
Both functions are critical because they allow an attacker with low-level privileges (the ability to create records) to execute arbitrary SQL queries. As demonstrated in the proof-of-concept, this can lead to the exfiltration of sensitive data, such as user credentials, from the database.