Summary
OpenEMR's IPPF contraceptive issue feature can form a SQL query using configurable field identifiers without safely restricting them. An authenticated administrator who can add a malicious identifier and trigger issue processing may cause arbitrary SQL to run with the application's database privileges.
Affected context
The vulnerability is in the IPPF contraceptive issue feature. The issue_ippf_con_save function builds a REPLACE INTO query using field_id values from layout_options as column names. The described issue affects OpenEMR versions before 8.5.0 when an administrator can modify those layout fields and the feature later processes them.
Exploit preconditions
- Attack surface: OpenEMR's authenticated administrative interface and IPPF issue-processing flow
- Required access: The ability to add or change a
field_idthroughedit_layout.php; the described scenario involves an authenticated administrator - Trigger point: Processing an issue through
add_edit_issue.php, which invokesissue_ippf_con_save - Why exploitation is possible: The configured identifier is incorporated into SQL as a column name without adequate restriction, allowing crafted configuration to alter the resulting query
Why this happens
The application concatenates a value from configurable layout data into a SQL statement as an identifier. SQL parameters generally bind data values, not column names, so dynamic identifiers require separate validation against a trusted set. Accepting an untrusted identifier in query construction creates a SQL injection flaw, corresponding to CWE-89: Improper Neutralization of Special Elements used in an SQL Command.
Potential impact
- An attacker could read, modify, or delete database data within the application's database permissions.
- Application records or configuration could be altered, affecting data integrity.
- Sensitive information stored in the database may be exposed.
- The issue could disrupt application functionality or undermine trust in stored records.
General mitigation guidance
Defensive patterns focus on preventing untrusted input from becoming part of SQL syntax.
- Use fixed, predefined column mappings rather than accepting arbitrary identifiers.
- Validate dynamic identifiers against a strict allowlist derived from the expected schema.
- Use parameterized queries for data values and safe, database-appropriate identifier handling where dynamic identifiers are unavoidable.
- Restrict who can modify layout configuration and separate configuration privileges from routine feature use.
- Apply least-privilege permissions to the database account so query impact is limited.
How teams detect issues like this
Review query-building code for string concatenation involving request data, configuration values, or database-sourced values, especially when used as table or column identifiers. Static analysis and code review can flag dynamic SQL construction and verify that identifiers are allowlisted rather than merely escaped. Policy checks can require parameterized queries for values and explicit validation for dynamic identifiers; automated code review tools may help surface these patterns.

