Summary
SOGo versions before 5.12.7 contain a SQL injection vulnerability in the changePasswordForLogin functionality when backed by PostgreSQL or MariaDB and configured to store cleartext passwords.
Under these conditions, untrusted password data can be concatenated into SQL queries, allowing an attacker to manipulate the query logic and potentially alter or access authentication data.
Affected context
The vulnerability occurs in SOGo deployments that:
- Use PostgreSQL or MariaDB as the backend
- Store user passwords in cleartext in the database
- Rely on the changePasswordForLogin routine to update user credentials
In this context, user-supplied values are interpolated into SQL statements, and the use of patterns like c_password = '%@' creates an opportunity for crafted input to break query boundaries.
Exploit preconditions
- Attack surface: Application-level password change interface or any code path that invokes changePasswordForLogin.
- Required access: Ability to submit or influence password values that flow into the vulnerable SQL assignment (e.g., self-service password change, administrative password reset, or API calls).
- Trigger point: Execution of the changePasswordForLogin routine that builds a SQL statement with
c_password = '%@'and concatenates untrusted input without safe parameter binding. - Why exploitation is possible: The password value is embedded directly into the SQL string instead of being passed as a typed, bound parameter; this allows malicious characters to alter the structure of the query rather than being treated purely as data.
Why this happens
The underlying issue maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
In the affected code, the password field is interpolated into an SQL expression as a string literal (c_password = '%@') using string formatting or concatenation.
Because the input is not strongly parameterized and is only protected (if at all) by ad-hoc quoting, attackers can inject SQL control characters, terminate the intended string, and append arbitrary clauses.
This pattern breaks the intended separation between data and code, exposing the database to unintended commands whenever untrusted input reaches the vulnerable query construction logic.
Potential impact
- Bypassing or manipulating authentication data by altering stored passwords.
- Unauthorized modification of user account records, potentially leading to account takeover.
- Exposure of sensitive credential information if error messages or query behavior reveal underlying data.
- Escalation of impact to broader data tampering or retrieval within the same database schema, depending on the constructed query and DB privileges.
- Degradation of service availability if injected queries cause locking, errors, or resource exhaustion.
General mitigation guidance
Effective mitigation typically focuses on enforcing strict separation between SQL code and user data, and reducing the sensitivity of stored secrets:
- Use parameterized queries or prepared statements for all database interactions, ensuring password values are always transmitted as bound parameters rather than concatenated into SQL strings.
- Centralize database access behind a well-reviewed data access layer that prohibits inline string-built queries for authentication-related operations.
- Avoid storing passwords in cleartext; use slow, salted password hashing functions to reduce the impact of any data access or injection issue.
- Apply least-privilege principles to the database account used by SOGo so that, even if a query is manipulated, it cannot access or modify unrelated schemas or administrative tables.
- Introduce input validation and normalization for password fields to reject clearly malformed or control-heavy inputs, while recognizing that validation is a secondary layer behind parameterization.
How teams detect issues like this
Detection is best approached through a combination of static and operational controls:
- Use static analysis configurations or custom rules to flag string-built SQL queries that interpolate variables, especially in authentication and password-related code paths.
- During code review, pay attention to any use of format strings or concatenation in queries (e.g., patterns like
... = '%@'), and require parameter binding for all user-influenced values. - Apply database-side monitoring or logging to detect anomalous query patterns, such as unexpected comment markers, multiple statements in a single query, or frequent syntax errors near password fields.
- Integrate automated security testing (such as SAST tools and targeted SQL injection tests for password-change flows) into CI pipelines to catch regressions in query construction patterns.

