Summary
A time-based SQL injection vulnerability in Koha Library's OPAC Send Basket feature allows malicious input in the bib_list POST parameter to influence SQL queries.
Under certain configurations, an authenticated library user can leverage timing responses to infer and read arbitrary data from the underlying database.
Affected context
This vulnerability appears in Koha Library deployments that expose the OPAC (Online Public Access Catalog) "Send Basket" functionality and construct SQL queries using the bib_list POST parameter without robust input handling.
It is most relevant where:
- The OPAC is accessible to library users
- The send-basket endpoint interacts with the database using dynamically built queries
- Database accounts used by the application have broad access to catalog and user-related tables
Exploit preconditions
- Attack surface: HTTP POST requests to
/cgi-bin/koha/opac-sendbasket.pl - Required access: Ability to authenticate or otherwise act as a "library user" in the OPAC interface
- Trigger point: Submission of a crafted
bib_listparameter in the Send Basket request - Why exploitation is possible: The server-side code incorporates
bib_listdirectly into SQL without adequate parameterization or validation, enabling an attacker to introduce additional SQL logic and use time-based techniques (e.g., deliberate delays) to infer database contents.
Why this happens
The root cause is the construction of SQL statements by concatenating or interpolating user-controlled input (bib_list) rather than using properly typed, parameterized queries.
This pattern aligns with CWE-89: SQL Injection, where attackers can modify the structure of a query by injecting SQL metacharacters and clauses into untrusted data fields.
In this case, the use of time-based operations makes it possible to exfiltrate information even when direct error messages or query results are not exposed.
Potential impact
- Reading database records that the current user would not normally be able to access
- Discovery of sensitive catalog, patron, or configuration data
- Mapping of database schema, including table and column names
- Pivoting to additional attacks if the database role has extensive privileges
General mitigation guidance
Effective mitigation centers on eliminating dynamic SQL built from user input and tightening the trust boundary around OPAC parameters.
Common defensive patterns include:
- Using parameterized queries or prepared statements for all database interactions involving
bib_listand similar parameters - Restricting inputs to well-defined formats (e.g., numeric IDs separated by approved delimiters) with strict server-side validation
- Applying least-privilege permissions to the database account used by the OPAC so it can access only what is necessary
- Centralizing query construction in vetted helper functions or ORM layers to reduce ad-hoc SQL
- Implementing generic error handling that avoids exposing detailed database behavior, while still logging security-relevant anomalies internally
How teams detect issues like this
Detection typically involves a combination of code-level review and runtime monitoring:
- Static analysis rules that flag string-based SQL construction using request parameters such as
bib_list - Manual code review focusing on CGI scripts and modules handling OPAC basket operations, looking for concatenated SQL strings
- Database query logging and analysis to detect unusual patterns, such as sleep/delay functions or conditional timing constructs
- Application-level security testing (including automated scanners) configured to exercise the Send Basket endpoint with time-based injection probes

