Summary
OpenEMR contains a SQL injection vulnerability in CcrTable::insertApprovedData() where request parameter names are used as database column names. An authenticated user may be able to manipulate database queries through crafted parameters sent to the revandapprove route, potentially exposing or corrupting patient records.
Affected context
The issue affects OpenEMR deployments before 8.5.0 where the revandapprove route invokes CcrTable::insertApprovedData() with request parameters that can influence column names in a SQL statement. The described route lacks ACL and CSRF checks, which may weaken authorization and request-integrity protections.
Exploit preconditions
- Attack surface: The
revandapproveroute and its handling ofpatient_data-*-selrequest parameters - Required access: An authenticated OpenEMR account; the description does not specify a required privilege level
- Trigger point: Processing a request that reaches
CcrTable::insertApprovedData() - Why exploitation is possible: Parameter names are incorporated into SQL as column names without adequate protection, and the route is described as lacking ACL and CSRF checks
Why this happens
The underlying flaw is SQL injection caused by allowing request-controlled values to influence SQL identifiers. SQL parameters can safely bind data values, but generally cannot bind column names; identifiers must instead be selected from a strict, trusted allowlist. Treating untrusted parameter names as column names maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command.
Potential impact
- Attackers may be able to copy password hashes into patient fields
- Patient records may be corrupted or altered
- Sensitive database information may be exposed, depending on query behavior and database permissions
- Data integrity and confidentiality may be affected
General mitigation guidance
Mitigation patterns focus on keeping request data out of SQL structure and enforcing authorization at the operation boundary.
- Select column names only from a strict allowlist of expected identifiers
- Use parameterized queries for all user-controlled data values
- Validate request structure and reject unexpected parameter names
- Apply authorization checks to sensitive routes and operations
- Use CSRF protections for state-changing requests
- Restrict database account permissions to the minimum needed
How teams detect issues like this
- Use static analysis to identify SQL construction that incorporates request parameter names or other untrusted input
- Review database calls for dynamically assembled table or column identifiers and verify that identifiers come from trusted allowlists
- Check that sensitive routes enforce authorization and CSRF protections
- Apply policy checks in code review and CI to flag unsafe SQL construction and missing route-level security controls
- Monitor for unusual updates to patient fields and unexpected database query patterns

