Summary
A blind SQL injection flaw in OpenEMR's Patient Search popup allows crafted HTTP parameter keys to alter backend SQL queries.
When an authenticated user can control parameter names in requests to the search endpoint, they may inject arbitrary SQL, impacting the confidentiality and integrity of medical records.
Affected context
This vulnerability occurs in OpenEMR's Patient Search functionality at /interface/new/new_search_popup.php.
It is exposed when:
- Users are authenticated into OpenEMR,
- The server processes patient search requests based on HTTP parameters,
- SQL query construction trusts parts of the HTTP request, including parameter keys, without rigorous validation or parameterization.
The issue is tied to how search filters and inputs are mapped into SQL clauses for querying patient data.
Exploit preconditions
- Attack surface: HTTP(S) interface of the OpenEMR application, specifically the Patient Search popup endpoint.
- Required access: Valid authenticated session (e.g., clinician, staff, or any user role with access to patient search).
- Trigger point: Submission of a crafted request where the HTTP parameter names (keys) are manipulated to alter the SQL query structure.
- Why exploitation is possible: The server-side code interpolates request parameter keys directly into SQL fragments, without strict whitelisting or prepared statements for dynamic identifiers, enabling an attacker to influence the query logic through blind SQL injection techniques.
Why this happens
The root cause aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Instead of treating HTTP parameters as untrusted input requiring strict handling, the Patient Search implementation appears to:
- Dynamically construct SQL statements using parameter keys to build column lists, filters, or conditions.
- Omit robust validation of parameter names against a fixed, known-safe set of columns or operators.
- Rely on string concatenation or similarly unsafe patterns when building SQL queries.
Because parameter keys are not properly constrained or parameterized, an attacker can introduce SQL syntax in places the application assumes are "safe," resulting in blind SQL injection where responses must be inferred indirectly (e.g., via timing or boolean conditions).
Potential impact
- Extraction of sensitive patient information and medical records through crafted blind queries.
- Unauthorized modification or deletion of patient data and related clinical records.
- Tampering with practice management data such as appointments, billing, or user accounts.
- Potential creation of backdoor administrative accounts or escalation of privileges at the application layer.
- Indirect impact on data availability, including causing query failures or partial denial of service by breaking SQL logic.
General mitigation guidance
Effective mitigation focuses on enforcing strict separation between untrusted input and SQL construction:
- Constrain request parameters to a whitelisted set of known-safe keys (e.g., predefined column names and operators) and reject any unexpected parameters.
- Use prepared statements and parameterized queries for all data values, and avoid concatenating user input into SQL fragments.
- For dynamic query building (such as optional search filters), construct the SQL using server-side constants and safe mappings, not user-controlled strings.
- Normalize and validate input types (e.g., integers, dates, enumerations) before including them in query logic.
- Apply least-privilege database accounts so that the application's DB user can perform only the minimum required operations.
- Introduce centralized query-building utilities or an ORM pattern that discourages raw string composition of SQL.
How teams detect issues like this
Organizations can identify similar SQL injection patterns using multiple complementary approaches:
- Static analysis: Configure SAST tools or custom rules to flag raw SQL concatenation involving
$_GET,$_POST, or framework request objects, including use of variable keys when building field lists or WHERE clauses. - Code review: Manually inspect search and filtering code paths for:
- Dynamic construction of column names, order-by fields, or operators from request parameter keys.
- Absence of strict whitelists and type checks for all dynamic components.
- Direct use of superglobals or request objects in SQL strings.
- Runtime testing: Use DAST or manual security testing to:
- Send requests with malformed or SQL-like parameter keys and look for behavior changes, timing anomalies, or database error patterns.
- Evaluate boolean and time-based blind injection indicators without relying on explicit error messages.
- Database monitoring: Enable logging and monitoring for unusual query patterns, such as injected tautologies, unexpected functions, or anomalous WHERE clauses driven by user input.

