Summary
EcclesiaCRM versions prior to 8.0.0 contain a SQL injection vulnerability in v2/templates/query/queryview.php, where the custom and value parameters are used unsafely in database queries.
An attacker who can control these parameters may inject arbitrary SQL, potentially leading to data exfiltration, data tampering, or complete compromise of the CRM database under vulnerable configurations.
Affected context
The issue appears in EcclesiaCRM's server-side PHP code that dynamically builds SQL queries for the query view functionality.
It becomes relevant when user-controllable input (such as HTTP GET/POST parameters mapped to custom and value) is passed into SQL statements without guaranteed use of prepared statements or strict parameterization.
Installations exposed to untrusted users over a network, especially internet-facing deployments or multi-user church management portals, are most at risk.
Exploit preconditions
- Attack surface: Web interface endpoints that eventually invoke
v2/templates/query/queryview.php. - Required access: Ability to send crafted HTTP requests or interact with UI elements that populate the
customandvalueparameters. - Trigger point: Execution of SQL queries in the query view feature where
customandvalueare incorporated into the query text. - Why exploitation is possible: Input from
customandvalueis not robustly constrained or parameterized, allowing attackers to alter the intended SQL structure rather than only its data values.
Why this happens
This vulnerability stems from constructing SQL statements by concatenating or interpolating untrusted input into query strings in PHP.
Instead of treating custom and value as bounded parameters, the code path in queryview.php allows user input to influence parts of the SQL syntax (e.g., WHERE clauses, operators, or additional statements).
This aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command, where metacharacters such as quotes, comment markers, or statement delimiters are insufficiently sanitized, enabling attackers to modify the logic of the query.
Potential impact
- Extraction of sensitive CRM data, including member records, contact information, and internal notes
- Unauthorized modification or deletion of records, potentially affecting donations, membership, and pastoral care data
- Bypassing authentication or authorization checks if the database is used to validate sessions or roles
- In some environments, potential execution of server-side commands or pivoting to other systems if the database engine or configuration allows it
General mitigation guidance
Effective mitigation generally focuses on removing dynamic SQL construction based on raw user input and reducing trust in web-sourced parameters:
- Use parameterized queries or prepared statements for all database access, binding
customandvalueas data values rather than inline SQL fragments. - Introduce server-side whitelisting for any queryable fields or operators; map user choices to predefined, constant SQL fragments instead of passing them through directly.
- Apply strict input validation for query-building inputs (e.g., only allow known field names and restricted value formats) to narrow the input domain.
- Enforce least-privilege database accounts so that even if a query is abused, the account has minimal ability to alter schema or sensitive tables.
- Centralize database access patterns in a data access layer, making unsafe query construction easier to spot and refactor.
How teams detect issues like this
Organizations can look for this and similar issues using:
- Static analysis rules that flag SQL query strings built via string concatenation or interpolation with user-sourced variables in PHP.
- Code review checklists emphasizing parameterized queries, explicit whitelisting of queryable fields, and banned direct use of request variables in SQL.
- Runtime monitoring of database logs for anomalous queries, such as those containing comment sequences, tautologies, or unexpected UNION/OR clauses.
- Web application security testing tools or frameworks that perform automated injection tests against parameters like
customandvalueto detect exploitable patterns.

