Summary
BillaBear versions prior to January 2026 contain a SQL injection vulnerability in the EventRepository, where user-controlled metric filter names and aggregation properties are directly interpolated into SQL queries.
Because these identifier fields are not safely quoted or validated, an authenticated user with ROLE_ACCOUNT_MANAGER can abuse them to execute arbitrary SQL commands against the backing database.
Affected context
The vulnerability exists in the EventRepository query-building logic that powers metrics and reporting features.
It affects deployments where metric filter names, aggregation properties, or similar query components can be influenced by authenticated users with ROLE_ACCOUNT_MANAGER.
While filter values are correctly parameterized, filter identifiers (such as column names or aggregation expressions) are inserted into SQL using string formatting, creating an injection vector whenever these identifiers are derived from user-controlled or semi-trusted input.
Exploit preconditions
- Attack surface: Application's metrics/event reporting endpoints that rely on the EventRepository to construct dynamic SQL queries.
- Required access: Valid authenticated account with ROLE_ACCOUNT_MANAGER (or any role allowed to supply metric filter names and aggregation properties).
- Trigger point: Submission of crafted metric filters or aggregation configuration where the "name" or "property" portion becomes part of the SQL identifier space (e.g., column, function, or ORDER BY expression).
- Why exploitation is possible: The code uses
sprintf()or equivalent string formatting to splice untrusted identifier components directly into SQL statements without quoting, whitelisting, or proper validation, so the database interprets the crafted input as executable SQL rather than as a benign identifier.
Why this happens
This issue stems from dynamically constructing SQL queries by concatenating or formatting untrusted input into the query text, specifically for identifier-like components such as metric filter keys and aggregation properties.
The implementation secures value placeholders with parameterization but fails to apply a similar trust boundary for identifier fields, which are injected directly into the SQL string via sprintf().
This aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where the application does not neutralize or constrain special characters and constructs in a way that prevents them from being treated as part of the SQL language.
At an abstract level, the pattern is: "accept free-form field names and expressions from users, assume they are safe identifiers, and merge them into SQL without whitelisting or structural constraints," allowing attackers to break out of the intended query structure.
Potential impact
- Execution of arbitrary SQL commands within the application's primary database context
- Unauthorized reading of sensitive data across tenants or accounts
- Modification or deletion of billing, event, or metrics data, potentially corrupting reports and business records
- Escalation of impact through manipulation of application state stored in the database
- In some environments, potential access to underlying host or other services via database-specific features (e.g., stored procedures, file access, or external calls), depending on DB configuration
General mitigation guidance
Effective mitigation focuses on eliminating direct insertion of untrusted identifiers into SQL and constraining dynamic query building:
- Use strict whitelisting for all dynamic columns, sort keys, and aggregation functions; map user-supplied names to a fixed set of allowed database identifiers.
- Replace raw string interpolation (
sprintf()or concatenation) with query builders or ORM facilities that offer structured handling of identifiers where possible. - Introduce a schema of allowed metrics and aggregations defined in code or configuration, and resolve user input to these predefined descriptors instead of accepting free-form names.
- Validate identifier-like input against conservative patterns (e.g., limited character sets, length restrictions) and reject anything out-of-schema, even if it syntactically matches the pattern.
- Apply least-privilege database accounts, ensuring the application's DB user has only the minimal rights required (e.g., preventing dangerous operations like
DROP,ALTER, or general DDL where feasible). - Where dynamic SQL is unavoidable, isolate it behind a carefully audited abstraction layer and avoid surfacing raw expression capabilities to end users.
How teams detect issues like this
Identifying this class of issue typically involves a combination of static analysis, code review, and runtime monitoring:
- Static analysis / SAST:
- Rules that flag uses of
sprintf(), string concatenation, or interpolation where the result is passed to database execution APIs. - Patterns that differentiate between parameterized values and raw identifier injection, especially in repositories or query helper classes.
- Code review cues:
- Any dynamic construction of SQL
SELECT,WHERE,ORDER BY, or aggregation clauses using user-influenced keys or expressions. - Repositories that accept arbitrary column names, metric names, or aggregation functions as input parameters without mapping them to known-safe constants.
- Policy enforcement:
- CI checks that prohibit direct SQL string building in high-risk modules, favoring query builders or ORMs.
- Secure coding guidelines that mandate whitelisting for all dynamic identifiers and prohibit exposing raw SQL expression capabilities to user-controlled inputs.
- Runtime indicators:
- Logging and alerting on anomalous SQL patterns, such as unexpected keywords, comment markers, or union-like constructs triggered from metric endpoints.
- Database audit logs that reveal unusual queries originating from metric/reporting endpoints.

