Summary
OpenEMR's Fee Sheet drug-inventory lookup is vulnerable to SQL injection because a submitted warehouse value is incorporated into an ORDER BY clause. A low-privileged authenticated user who can submit Fee Sheet product lines may exploit this behavior as a time-based blind oracle to extract sensitive database information.
Affected context
The issue occurs in DrugSalesService::sellDrug during the Fee Sheet drug-inventory lookup. The prod[N][warehouse] POST field is interpolated into an SQL ORDER BY clause; deployments are at risk when this input can reach the query without safe parameterization or equivalent validation. The supplied description identifies OpenEMR versions before 8.3.0 as affected.
Exploit preconditions
- Attack surface: The Fee Sheet drug-inventory lookup.
- Required access: A low-privileged authenticated account able to submit Fee Sheet product lines.
- Trigger point: Processing the
prod[N][warehouse]POST field inDrugSalesService::sellDrug. - Why exploitation is possible: User-controlled input is incorporated into an SQL ordering expression, allowing time-based blind inference from query behavior.
Why this happens
The underlying bug is SQL injection, mapped to CWE-89. The application builds or alters an SQL statement using a request value in an ORDER BY clause without safely separating data from query structure. Because ordering expressions are part of SQL syntax, unsafe interpolation can allow input to influence query evaluation rather than being treated strictly as a value.
Potential impact
- An attacker may infer database contents through a time-based blind oracle.
- Patient information could be disclosed.
- Users' bcrypt password hashes could be exposed.
- Exposure of sensitive records could create privacy and account-security risks.
General mitigation guidance
Defensive patterns focus on preventing request data from controlling SQL syntax:
- Use query builders or parameterized queries, and avoid interpolating request values into SQL clauses.
- Where a SQL clause cannot use bind parameters, map inputs to a strict allowlist of known-safe values rather than accepting arbitrary expressions.
- Validate request data against an explicit schema and reject unexpected fields or values.
- Limit database account privileges to the minimum needed for the application's operations.
- Reduce exposure of sensitive data through appropriate access controls and database permissions.
How teams detect issues like this
- Use static analysis to identify SQL statements assembled through string concatenation or interpolation, especially in
ORDER BYclauses. - Review code paths that pass POST fields into query-building functions and verify that values cannot alter SQL structure.
- Apply code-review checks and repository policies requiring parameterized queries or strict allowlists for dynamic SQL fragments.
- Monitor for unusual database query timing patterns and unexpected access to sensitive patient or account data.
- Automated security review tools may help flag unsafe query construction for manual assessment.

