Summary
Formance Ledger can treat unvalidated account expansion values as SQL when processing API requests. A remote caller who can reach the affected API may inject SQL through the expand query parameter or a base64 pagination cursor, potentially exercising the database role's permissions.
Affected context
The issue is described in Formance Ledger 2.2.0-beta.3 and earlier releases before 2.4.18. It occurs in API handling for account expansion and pagination when caller-supplied values are incorporated into SQL without adequate validation or safe parameterization. The practical exposure depends on whether the affected API is reachable and on the privileges assigned to its database role.
Exploit preconditions
- Attack surface: Formance Ledger API endpoints that process account expansion or pagination
- Required access: Ability to send requests to an affected API; the description does not specify whether authentication is required
- Trigger point: Processing an unvalidated
expandquery parameter or base64 pagination cursor - Why exploitation is possible: Caller-controlled values can influence SQL execution, which runs with the ledger database role's privileges
Why this happens
The underlying issue is SQL injection, mapped to CWE-89: Improper Neutralization of Special Elements used in an SQL Command. The vulnerable pattern occurs when input is incorporated into a SQL statement without reliably separating data from query structure. Validation alone may not establish that input is safe for SQL; parameterized queries and constrained query construction help preserve that separation.
Potential impact
- An attacker may execute SQL with the ledger database role's privileges.
- Depending on database permissions, queries could expose or alter ledger data.
- Data integrity or service availability could be affected by unauthorized database operations.
- The scope of impact could extend to other accessible database objects if the role has broader privileges.
General mitigation guidance
Mitigation generally focuses on ensuring user-controlled values cannot become SQL syntax.
- Use parameterized queries or safe query-building APIs for all caller-controlled values.
- Prefer allowlisted, typed options for expansion fields and pagination inputs.
- Treat encoded cursors as untrusted input; validate their structure and integrity before use.
- Apply least privilege to the ledger database role and limit access to the API surface.
- Avoid relying on input filtering as a substitute for separating SQL code from data.
How teams detect issues like this
- Use static analysis to identify SQL statements assembled through string concatenation, interpolation, or formatting with request-derived values.
- Review account expansion and pagination code paths for unsafe query construction and incomplete validation.
- Enforce repository policies requiring parameterized SQL and security review for database access changes.
- Monitor API and database telemetry for unusual query patterns or unexpected use of expansion and cursor parameters.
- Automated code review tools may help flag risky SQL construction patterns.

