Summary
A SQL injection flaw in Apache Fineract's Office Search API allows crafted orderBy parameters to be concatenated directly into SQL, bypassing existing column validation.
Under authenticated conditions where a user can query offices, this can be abused for time-based blind data exfiltration and database connection pool exhaustion.
Affected context
This vulnerability occurs in Apache Fineract deployments exposing the Office Search endpoint (GET /api/v1/offices) on versions up to and including 1.14.0.
It is relevant where:
- The
orderByquery parameter is accepted from client requests, - SQL queries are built using string concatenation rather than parameterized expressions,
- Column validation logic does not fully restrict arbitrary SQL fragments in ORDER BY clauses, including embedded subqueries.
The risk is higher in multi-tenant or shared environments where authenticated users have broad visibility into office data.
Exploit preconditions
- Attack surface: HTTP API endpoint
GET /api/v1/offices. - Required access: Authenticated user with permissions to view offices and invoke the Office Search API.
- Trigger point: Supplying a malicious
orderByparameter that embeds SQL expressions or subqueries into the ORDER BY clause. - Why exploitation is possible: The application constructs SQL by concatenating the
orderByvalue without sufficiently restricting it to a safe set of column identifiers, allowing unvalidated SQL syntax to be interpreted by the database engine.
Why this happens
The underlying defect is the reliance on dynamic SQL string construction where user-controlled input is inserted into query text without robust validation or parameterization.
Column-level validators introduced for earlier fixes focus on recognizing and restricting known-unsafe patterns but do not comprehensively handle ORDER BY clauses that contain bare subqueries or complex SQL expressions.
This maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where user input is not constrained to a safe grammar and is treated as executable query logic.
Potential impact
- Authenticated users may exfiltrate sensitive data via time-based blind SQL injection techniques.
- Attackers could enumerate or infer internal schema details and relationships.
- Concurrent exploitation can exhaust the database connection pool, causing denial of service for other application users.
- Increased risk of lateral movement if injected queries expose cross-tenant data in multi-tenant setups.
- Potential compromise of integrity if injected queries are extended to perform write operations, depending on database permissions.
General mitigation guidance
Effective mitigation focuses on removing direct concatenation of user-controlled values into SQL and enforcing strict query construction patterns.
Recommended defensive approaches include:
- Restricting
orderByto a fixed, whitelisted set of column identifiers, expressed as constants in application code rather than arbitrary client-supplied strings. - Using parameterized queries or ORM-level ordering constructs that separate data values from SQL syntax and do not treat client input as raw query fragments.
- Applying rigorous server-side validation that enforces a limited grammar for sorting parameters (e.g., column name plus optional ASC/DESC), rejecting any subqueries or complex expressions.
- Centralizing query-building logic so that validation and sanitization rules are consistently applied across all endpoints handling filtering, sorting, and searching.
- Running application and database roles with least privilege to reduce the impact of any residual injection paths.
How teams detect issues like this
Detection tends to combine application-layer review with database monitoring:
- Static analysis rules can flag string concatenation patterns in SQL-building code, especially around ORDER BY, WHERE, and JOIN clauses using user input.
- Manual code reviews should look for non-parameterized query construction, ad hoc sorting/filtering logic, and incomplete whitelist implementations around request parameters.
- Database query logs and performance metrics can reveal anomalous long-running queries or repeated time-based patterns originating from the Office Search API.
- Security testing, including automated SQL injection scanners and focused time-based blind injection tests on sorting parameters, can help confirm whether validation is robust.
- CI/CD pipelines can enforce policies that prohibit raw concatenation of request parameters into SQL and require use of vetted query helpers or ORM features.

