Summary
Koha's guided report builder incorporates user-controlled sorting parameters directly into an SQL ORDER BY clause without an allowlist or validation. A staff user with report creation or execution permissions may be able to perform time-based blind SQL injection, potentially exposing sensitive database information.
Affected context
The vulnerability occurs in Koha's guided report builder when the order_by CGI parameter and its dynamically named companion value are used to construct a report query. It is relevant where low-privilege staff accounts have the create_reports or execute_reports permission and the resulting query reaches a database containing patron, staff, or authentication-related information.
Exploit preconditions
- Attack surface: Koha's guided report builder web interface
- Required access: An authenticated staff account with report creation or execution privileges
- Trigger point: Processing user-controlled ordering parameters while assembling a report query
- Why exploitation is possible: Column and ordering values are concatenated into an SQL ORDER BY clause without an explicit allowlist, validation, or escaping
Why this happens
The underlying flaw is direct concatenation of request-controlled values into SQL syntax. Because SQL identifiers and ordering directions generally cannot be safely supplied through ordinary prepared-statement value placeholders, the application must map accepted inputs to known-safe server-side options; that control is absent here. This behavior maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command, commonly known as SQL injection.
Potential impact
- An attacker may infer database information through timing behavior
- Sensitive patron records could be exposed
- Staff or directory-service credentials could be disclosed
- Database integrity could be affected if broader query manipulation becomes possible
- The incident could enable follow-on compromise of connected systems
General mitigation guidance
Mitigation generally focuses on removing request-controlled SQL structure and reducing the trust placed in report parameters.
Common defensive patterns include:
- Mapping accepted sort fields and directions to fixed server-side allowlists
- Rejecting unknown, duplicated, or malformed ordering values before query construction
- Keeping SQL identifiers separate from user-supplied data and using parameter binding wherever values are involved
- Limiting report permissions according to least privilege and separating report execution from sensitive data access
- Restricting database accounts used by reporting features to the minimum required operations and datasets
- Applying consistent validation and authorization controls across all report-building paths
How teams detect issues like this
Organizations can look for this class of issue through:
- Static analysis rules that flag string interpolation or concatenation near SQL query construction
- Code review searches for request parameters inserted into clauses such as ORDER BY, GROUP BY, or LIMIT
- Tests that submit unexpected ordering names and directions and verify strict rejection
- Database monitoring for unusual report-query timing, repeated failed queries, or abnormal access to sensitive tables
- Policy enforcement requiring allowlists for SQL identifiers and centralized query-building abstractions
Automated code review and application security testing tools may help identify these patterns, but database-aware manual review remains useful for report-generation code.

