Summary
Chamilo LMS 2.0.0-RC.2 contains a SQL injection vulnerability in the statistics AJAX endpoint, where date range parameters are directly interpolated into a SQL query without proper sanitization in the users_active action.
An authenticated admin can exploit this flaw using time-based blind SQL injection to extract arbitrary data from the underlying database whenever the vulnerable AJAX endpoint is invoked with crafted date parameters.
Affected context
The vulnerability occurs in the Chamilo LMS statistics module, specifically in public/main/inc/ajax/statistics.ajax.php within the users_active action.
It affects deployments where authenticated administrators can trigger the statistics AJAX endpoint with user-controlled date_start and date_end parameters.
The risk materializes when these date parameters are passed directly into SQL queries without using parameterized statements or robust server-side validation.
Exploit preconditions
- Attack surface: HTTP(S) interface exposed by the Chamilo LMS statistics AJAX endpoint.
- Required access: Authenticated admin-level access capable of invoking the
users_activestatistics action. - Input control: Ability to supply crafted
date_startanddate_endvalues in requests to the statistics AJAX endpoint. - Trigger point: Execution of the vulnerable SQL query when the
users_activeaction processes the provided date parameters. - Why exploitation is possible: The date parameters are concatenated directly into the SQL string without parameterization or sufficient server-side sanitization, enabling time-based blind SQL injection.
Why this happens
This issue stems from dynamically constructing SQL queries by concatenating untrusted input into query strings, rather than using parameterized queries or safe query builders.
In the users_active action, the date_start and date_end parameters bypass any strong validation and are interpolated directly into the SQL, violating the principle of strict separation between code and data.
This maps to CWE-89: SQL Injection, where an application fails to neutralize or parameterize external input before it reaches the SQL interpreter.
The problem is compounded by an incomplete fix: input filtering was applied in another action (get_user_registration_by_month) but not consistently across similar query paths, leaving a residual injection sink.
Potential impact
- An authenticated admin may extract sensitive data from arbitrary database tables using time-based blind SQL injection.
- Application data, including user records, course information, and assessment results, could be exposed or enumerated.
- The attacker could potentially modify or delete data if the crafted payloads reach write-capable queries.
- Further compromise of the LMS environment may occur if stored credentials, session tokens, or configuration secrets are exfiltrated.
General mitigation guidance
Effective mitigation focuses on eliminating direct string concatenation in SQL construction and enforcing strict input handling for all query parameters.
Recommended defensive patterns include:
- Replacing dynamic SQL string assembly with parameterized queries or prepared statements for all user-supplied input, including date fields.
- Centralizing query construction through a database abstraction layer or ORM that promotes safe parameter binding by default.
- Applying server-side validation and normalization of date parameters, enforcing expected formats and rejecting unexpected characters or structures.
- Adopting secure coding guidelines that prohibit embedding raw request parameters in SQL, with code review checklists to enforce these rules.
- Applying the principle of least privilege at the database level so the application account has only the minimal permissions required, reducing the blast radius of potential injection.
How teams detect issues like this
Detecting similar SQL injection issues typically combines static analysis, code review, and runtime monitoring.
Useful approaches include:
- Static analysis rules that flag string concatenation in SQL query construction, especially where input originates from HTTP parameters or request data.
- Pattern-based code review focusing on AJAX handlers, reporting endpoints, and utility functions that construct SQL, verifying that all parameters are bound using prepared statements.
- Establishing secure coding policies (e.g., "no raw SQL with concatenated input") enforced via pull request templates and automated linters.
- Instrumenting application and database logs to monitor for anomalous patterns such as long-running queries, timing-based probes, or unusual predicates that may indicate time-based injection attempts.
- Periodic dynamic testing and security scanning of exposed endpoints, including authenticated admin functionality, to identify residual injection points.

