Summary
OpenEMR contains a stored SQL injection vulnerability in patient demographic searches: values from the layout_options field_id are incorporated into a search query without adequate protection. A user with Layout Editor access could plant a malicious value that may later let an authenticated low-privilege user retrieve data from sensitive patient and user tables.
Affected context
The issue occurs in OpenEMR's getByPatientDemographics() patient-search functionality, where layout_options field identifiers are used to construct a WHERE clause. Deployments may be at risk when an attacker can edit layout configuration and the resulting values are later used in database queries without safe parameterization. The description identifies OpenEMR releases before 8.5.0 as affected.
Exploit preconditions
- Attack surface: Patient demographic search and layout configuration.
- Required access: The attacker planting the value needs Layout Editor access; the data-retrieving user needs an authenticated account.
- Trigger point: A patient search processes the stored
field_idvalue. - Why exploitation is possible: The value is concatenated into SQL rather than handled as a safely bound query parameter.
Why this happens
The underlying bug is stored SQL injection, mapped to CWE-89: Improper Neutralization of Special Elements used in an SQL Command. Application-controlled layout metadata is incorporated into a SQL statement as query text. When that value is not safely separated from SQL syntax, a planted value can alter the query's behavior when the search runs.
Potential impact
- An authenticated user could retrieve information from
patient_data. - An authenticated user could retrieve information from
users_secure. - Sensitive patient or account data could be exposed beyond the user's intended access.
General mitigation guidance
Defensive patterns for this class of issue include:
- Use parameterized queries for values and allowlist validation for identifiers that cannot be bound as parameters.
- Treat stored layout metadata as untrusted input, even when it was created by a privileged user.
- Keep database access scoped to the minimum permissions required by each operation.
- Restrict Layout Editor access and review changes to layout configuration.
- Apply authorization checks to search results so query behavior cannot bypass data-access boundaries.
How teams detect issues like this
- Use static analysis to identify SQL statements built through string concatenation, especially where stored configuration or metadata is involved.
- Review
getByPatientDemographics()and adjacent query-building code for unsafe handling offield_idvalues. - Monitor and audit Layout Editor changes, and investigate unexpected modifications to layout metadata.
- Enforce code-review or CI policies requiring parameterized queries and allowlisted SQL identifiers.

