The vulnerability is a classic SQL injection in the EventRepository of BillaBear. The root cause is the use of sprintf() to construct dynamic SQL queries where user-controlled input, specifically metric filter names and aggregation properties, is concatenated directly into the SQL string without proper sanitization or escaping. While the filter values are parameterized, the filter identifiers (the column names) are not. This allows an authenticated attacker with ROLE_ACCOUNT_MANAGER permissions to craft a malicious filter name. This malicious payload is then stored in the database (a second-order injection) and is executed when a usage calculation is triggered, for example, during invoice generation. The vulnerable functions, createCountSql, createSumSql, createMaxSql, createLatestSql, and createCountUnique, all reside in src/BillaBear/Repository/Usage/EventRepository.php and are responsible for building and executing these flawed SQL queries. The lack of input validation in CreateMetricFilter.php for the filter name field is what makes the initial injection possible.