Summary
OneUptime's analytics endpoints contained a SQL injection flaw where user-controlled object keys were interpolated as ClickHouse Identifier parameters without validation.
An attacker who can access list or aggregate analytics APIs could inject arbitrary SQL through crafted sort, select, or groupBy keys, potentially leading to data exposure or modification within the analytics database.
Affected context
This vulnerability appears in OneUptime deployments that:
- Use the analytics APIs backed by ClickHouse, and
- Rely on the StatementGenerator utility to construct SELECT, GROUP BY, and ORDER BY clauses, and
- Accept request body parameters for sorting, selecting, or grouping analytics data.
The issue is present when application logic trusts client-provided object keys (e.g., field names) and passes them directly into query construction without checking that they are valid model columns.
Exploit preconditions
- Attack surface: Any reachable analytics list or aggregate endpoint that allows clients to specify sort, select, or groupBy options.
- Required access: Network access and any authentication level needed to reach these endpoints (often a regular user with analytics access).
- Trigger point: Submission of crafted JSON bodies or query parameters whose keys are consumed by
toSortStatement,toSelectStatement, ortoGroupByStatement. - Why exploitation is possible: The StatementGenerator treats user-controlled keys as ClickHouse Identifier parameters and interpolates them without verifying they map to permitted model columns. Since ClickHouse Identifiers are substituted directly into the SQL without escaping, this enables injection into query structure.
Why this happens
The underlying flaw is a classic SQL injection pattern (CWE-89) involving untrusted data used to dynamically construct query fragments.
Instead of using a closed list of allowed column names or mapping client fields to internal identifiers, the code paths toSortStatement, toSelectStatement, and toGroupByStatement accept arbitrary object keys from API requests and inject them into ClickHouse query strings as identifier tokens.
Because identifier parameters in this context are not escaped and are treated as part of the SQL syntax, an attacker can craft keys that alter the structure of the query (e.g., adding additional expressions, functions, or clauses) rather than simply referencing benign columns.
Potential impact
- Exposure of additional analytics data that would not normally be returned to the requesting user.
- Modification or corruption of analytics results, leading to incorrect reporting and decision-making.
- Circumvention of application-level query restrictions by injecting additional functions or clauses.
- Potential escalation to broader database compromise, depending on ClickHouse configuration, permissions, and available SQL features.
General mitigation guidance
Effective mitigation focuses on eliminating direct use of untrusted identifiers and constraining query construction:
- Introduce a strict allowlist of valid model columns, and map any client-provided field names to these known identifiers before building queries.
- Use structured query builders or ORM-like abstractions where identifiers are derived from schema metadata, not from raw client input.
- Normalize and validate sort, select, and groupBy specifications against server-side definitions (e.g., enumerations or configuration objects) instead of trusting arbitrary keys.
- Apply least-privilege to the analytics database user so even if a query is manipulated, the account cannot perform destructive operations or access unrelated schemas.
- Design APIs so that clients choose from predefined analytics dimensions and metrics, rather than constructing free-form query fragments.
How teams detect issues like this
Detection typically involves both code-centric and runtime approaches:
- Static analysis: Configure rules to flag string concatenation or identifier interpolation in query builders, especially where input originates from request bodies or query parameters.
- Code review: Pay particular attention to utility classes like
StatementGeneratorthat centralize query construction, checking that all paths enforce identifier validation and use allowlists. - Schema-aware checks: Implement unit or integration tests that verify only known column names can be used in sort/select/groupBy options; reject any unexpected identifier.
- Runtime monitoring: Analyze database logs for unusual queries containing unexpected column names or syntactic anomalies, and correlate them with API calls that include custom sorting or grouping options.

