Summary
OpenEMR's SLEOB invoice-number lookup builds a database query using the CLP01 claim identifier from an uploaded X12 835 ERA file without parameter binding or escaping. A user with billing permissions, or a malicious payer whose file is uploaded by a clerk, may be able to manipulate the query to read or modify database records.
Affected context
The vulnerability occurs in SLEOB::slInvoiceNumber() in src/Billing/SLEOB.php when processing claim identifiers from uploaded X12 835 ERA files. It becomes risky when the CLP01 value is incorporated into a database query without safe parameterization and an attacker can supply or influence the ERA data that is processed.
Exploit preconditions
- Attack surface: ERA file processing and the database query used to look up an invoice number
- Required access: Billing permissions in OpenEMR, or the ability to provide a malicious payer ERA file that a clerk uploads
- Trigger point: Processing an ERA file and using its CLP01 claim identifier in the SLEOB lookup
- Why exploitation is possible: The identifier is concatenated into a query without escaping or parameter binding
Why this happens
The application treats a value from an ERA file as part of SQL syntax rather than as data. Concatenating that value into a query without parameterized statements allows crafted input to alter the query's meaning. This is CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Potential impact
- An attacker may read data from database tables, including user password hashes.
- An attacker could modify database records.
- Unauthorized access to sensitive information may affect confidentiality and privacy.
- Data integrity and billing workflows could be affected.
General mitigation guidance
Defensive patterns for this class of issue include:
- Use parameterized queries for all values originating from files or other untrusted sources.
- Treat imported ERA content as untrusted, regardless of who supplied the file.
- Apply input validation appropriate to the claim identifier's expected format, while retaining parameterization as the primary SQL injection defense.
- Limit database account permissions to the operations and records required by the application.
- Keep database access behind well-defined data-access functions that consistently enforce safe query construction.
How teams detect issues like this
Detection can include:
- Static analysis rules for SQL statements built through string concatenation with external or file-derived values.
- Code review of ERA import paths and database lookups that use claim identifiers.
- Tests that verify imported values are passed as query parameters rather than incorporated into SQL text.
- Policy enforcement that requires parameterized queries in database-access code.
- Review of database and application logs for unexpected query behavior during ERA processing.

