Summary
OpenEMR has an insecure direct object reference in the patient portal settings handler that can let an authenticated patient change settings belonging to another patient. The risk arises when the application accepts a patient identifier supplied with a settings request without verifying that the requester is authorized to act on that patient's records.
Affected context
The issue occurs in portal/lib/persist.php when patient portal settings are written. An authenticated portal patient may be able to target another patient by supplying an arbitrary setting_patient value, if the application does not bind that value to the authenticated user's authorized patient identity.
Exploit preconditions
- Attack surface: Patient portal settings functionality
- Required access: An authenticated patient portal account
- Trigger point: A request that inserts or updates a patient setting
- Why exploitation is possible: The supplied
setting_patientvalue may be trusted without an effective authorization check tying it to the authenticated patient
Why this happens
The underlying issue is a missing object-level authorization check. The application uses a client-supplied identifier to select the patient record being modified without adequately confirming that the authenticated user is permitted to act on that patient. This is an insecure direct object reference mapped to CWE-639: Authorization Bypass Through User-Controlled Key.
Potential impact
- An attacker may suppress notifications for other patients.
- An attacker could alter consent-related flags.
- An attacker may change other patients' portal preferences.
- Unauthorized changes could undermine the integrity of patient settings and related workflows.
General mitigation guidance
Defensive patterns focus on enforcing authorization for every patient-specific operation:
- Derive the patient identity from the authenticated session where possible instead of trusting a client-supplied identifier.
- Apply object-level authorization checks before inserting or updating settings.
- Restrict settings updates to an explicit allowlist of fields and permitted values.
- Use least-privilege database access and avoid broad write permissions for portal operations.
- Treat identifiers and other request data as untrusted, even when submitted by authenticated users.
How teams detect issues like this
- Review settings handlers for writes keyed by request-supplied patient identifiers.
- Use static analysis or code review checks to flag database updates without nearby object-level authorization.
- Test authorization policies by confirming that one authenticated patient cannot read or modify another patient's settings.
- Monitor audit logs for settings changes where the target patient differs from the authenticated patient's identity.

