Summary
OpenEMR before 8.5.0 can store attacker-controlled PHP when an authenticated billing user uploads a malformed ERA file through era_payments.php. If a database-write primitive is also available to register a background service that loads the stored file, the PHP may execute as the web-server user.
Affected context
The vulnerability concerns ERA file handling and background-service loading in OpenEMR deployments before 8.5.0. Risk depends on whether a malformed upload can leave executable PHP in a stored .edi file and whether a database-write path can register a service that loads that file.
Exploit preconditions
- Attack surface: ERA file upload through
era_payments.php - Required access: An authenticated billing user who can submit ERA files, plus a way to write a suitable background-service database row
- Trigger point: A background service uses
require_onceto load the stored.edifile - Why exploitation is possible: Attacker-controlled PHP is stored in a file that is later loaded as PHP code; a database-write primitive, such as SQL injection, may enable registration of the loading service
Why this happens
The issue arises when uploaded ERA content is stored in a form that can contain executable PHP and is later included by the application. This reflects CWE-434: Unrestricted Upload of File with Dangerous Type: uploaded content is not sufficiently constrained to prevent dangerous file content from reaching an execution-capable loading path.
Potential impact
- An attacker could execute code with the privileges of the web-server user.
- The application or data accessible to that account may be compromised.
- The compromised application could be used to affect connected systems, depending on the web server's permissions and network access.
General mitigation guidance
Defensive patterns focus on treating uploaded files as untrusted data and preventing them from entering executable loading paths. Common approaches include:
- Accepting only required file formats and validating their structure and content with constrained parsers.
- Storing uploads outside executable web or application paths, with non-executable permissions.
- Avoiding dynamic inclusion of uploaded files and using data-only parsing APIs.
- Restricting who can upload ERA files and who can create or modify background-service records.
- Applying least privilege to the web-server account and limiting database-write capabilities.
How teams detect issues like this
- Review upload handlers for checks that rely only on file names or extensions rather than validating file content and format.
- Search for code paths that include or require uploaded files, particularly files stored with data-oriented extensions.
- Audit database access paths and permissions for unauthorized creation or modification of background-service records.
- Use static analysis and code review policies to flag executable inclusion of user-controlled files and risky upload handling.

