The vulnerability exists in the oneuptime application, specifically within the StatementGenerator.ts file, which is responsible for building ClickHouse database queries for analytics. The core issue is a failure to validate user-supplied input that is used to construct SQL queries, leading to SQL injection.
The advisory and the patch reveal that three methods in the StatementGenerator class were vulnerable: toGroupByStatement, toSortStatement, and toSelectStatement. These methods accept groupBy, sort, and select objects, respectively, which are derived directly from the request body of API endpoints like BaseAnalyticsAPI.getList() and BaseAnalyticsAPI.getAggregate(). The keys of these objects were used as column identifiers in the generated ClickHouse SQL queries.
ClickHouse's Identifier parameters are substituted directly into the query without escaping. The vulnerable methods were using these user-controlled keys as Identifier parameters without first checking if they were legitimate column names. This allowed an attacker to craft request bodies with malicious SQL snippets as keys in the groupBy, sort, or select JSON objects, which would then be executed by the database.
The patch addresses this by adding a validation step in each of the three vulnerable functions. It uses this.model.getTableColumn(key) to verify that the key corresponds to a valid column in the data model before it is used in the SQL statement. If the key is not a valid column, a BadDataException is thrown, preventing the injection.