Summary
OpenEMR's EtherFax document disposal functionality allows authenticated users to write arbitrary content to arbitrary locations on the server filesystem by abusing the disposeDocument() method.
When combined with the ability to upload PHP files into web-accessible directories, this can enable remote code execution through malicious web shells.
Affected context
This vulnerability occurs in OpenEMR deployments using the EtherFaxActions.php functionality where user-controlled input influences filesystem paths.
It is relevant when authenticated users can trigger disposeDocument() and the web server is configured to execute PHP files from writable directories.
The risk increases in shared or multi-user environments where untrusted or semi-trusted users have application-level accounts with access to document-related actions.
Exploit preconditions
- Attack surface: HTTP(S) interface of the OpenEMR application, specifically endpoints that invoke EtherFaxActions.php and disposeDocument().
- Required access: Valid authenticated user account with permissions to perform document disposal or related fax/document actions.
- Trigger point: Invocation of disposeDocument() with attacker-controlled parameters that determine the destination path and content of written files.
- Why exploitation is possible: The server trusts user-supplied path or file identifiers without robust normalization and enforcement of allowed directories, enabling path traversal or arbitrary path selection, and it writes attacker-controlled content directly to the filesystem.
Why this happens
The root cause is improper restriction of filesystem path input in disposeDocument(), aligning with CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Instead of strictly constraining file operations to known-safe directories and filenames, the implementation allows user-influenced values to determine where and what is written on disk.
This insecure pattern of combining user-controlled paths with file write operations, without canonicalization and whitelisting, permits arbitrary file placement and content injection.
Potential impact
- An attacker may upload PHP web shells into web-accessible directories, leading to remote code execution.
- An attacker could overwrite existing application or configuration files, potentially causing denial of service or altering application behavior.
- An attacker can create new files containing attacker-controlled data, enabling data exfiltration channels or further pivoting.
- An attacker may store malicious scripts or binaries on the server filesystem as part of a broader intrusion.
General mitigation guidance
Effective mitigation focuses on constraining filesystem access and decoupling user input from raw paths:
- Enforce strict allowlists of directories and filenames for any file operations, using server-side mappings from opaque identifiers to canonical paths rather than raw user-supplied paths.
- Normalize and canonicalize all filesystem paths before use, and verify they remain within a designated application-owned directory tree.
- Separate data directories from executable code directories so that uploaded or generated files cannot be interpreted as PHP or other executable scripts by the web server.
- Apply least-privilege file permissions at the OS level so the application process can write only where strictly necessary and cannot modify application code or configuration files.
- Design document disposal routines to use fixed, server-controlled locations and names, ignoring or heavily restricting any user-controlled path parameters.
How teams detect issues like this
Organizations can detect this class of vulnerability through a combination of review and automated analysis:
- Static analysis rules looking for file write functions (e.g., file_put_contents, fwrite, fopen in write modes) that directly use request parameters, query variables, or other tainted inputs when building paths.
- Code review practices that flag any concatenation of user input into filesystem paths, especially within document upload, disposal, or export features.
- Runtime application logging and monitoring to spot unusual paths in document-related operations, such as attempts to write outside expected directories or with unexpected file extensions.
- Security testing and QA checklists that include path traversal probes and arbitrary file write scenarios against document and file-handling endpoints.

