Summary
Legacy patient notes functions in OpenEMR update and delete notes using only WHERE id = ? without checking that the note belongs to a patient the current user is authorized to access.
When user-controlled note IDs are passed directly from the web UI to these functions, an attacker with a valid session may modify or delete notes for patients outside their permitted scope.
Affected context
The vulnerability occurs in the legacy patient notes handling code (library/pnotes.inc.php) used by the OpenEMR web UI.
It is relevant where:
- The legacy notes functions are reachable from the user interface
- Users can influence the note ID passed to update or delete operations
- Authorization checks rely on note ownership or patient assignment but are not enforced at the data access layer
In such deployments, the application trusts the note ID parameter from the client without re-verifying that the target note belongs to a patient the user may access.
Exploit preconditions
- Attack surface: Authenticated web UI endpoints that create, update, or delete patient notes.
- Required access: A valid OpenEMR user account with any level of access that can interact with patient notes in the web UI.
- Trigger point: Supplying or tampering with the note ID parameter in requests that invoke the legacy note update or delete functions.
- Why exploitation is possible: The backend logic performs database operations using
WHERE id = ?and does not confirm that the note's patient is within the current user's authorized patient set, allowing horizontal privilege escalation via IDOR.
Why this happens
The root cause is an insecure authorization pattern where object access is decided implicitly by the presence of an identifier rather than explicit ownership checks.
The legacy patient notes functions accept a note ID and perform update/delete operations solely on id, without checking the associated patient context against the current user's permissions.
This maps to CWE-639: Authorization Bypass Through User-Controlled Key, where user-controlled identifiers are trusted to select protected records and no secondary authorization check ensures the user is permitted to act on that resource.
Potential impact
- Unauthorized modification of patient notes belonging to other patients.
- Deletion of notes for patients the attacker should not be able to access.
- Silent tampering with clinical documentation that may influence medical decisions.
- Integrity loss in audit trails or medical records where notes are used for compliance evidence.
- Potential privacy violations if note content can be inferred or exposed through error messages or related UI flows.
General mitigation guidance
Mitigation generally focuses on enforcing object-level authorization and avoiding reliance on client-supplied identifiers as proof of access.
Recommended patterns include:
- Implementing centralized checks that verify, for any given note ID, that the associated patient is within the current user's authorized scope before performing update or delete operations.
- Binding operations to patient context in the server-side logic (e.g., checking both note ID and patient ID against the user's permissions) rather than trusting isolated IDs from the client.
- Encapsulating data access in service or repository layers that always enforce ownership and role-based access control before executing queries.
- Minimizing direct exposure of raw database identifiers where possible, or pairing them with server-validated session context.
- Applying the least-privilege principle so that UI roles only receive permissions required for their workflow, reducing the blast radius of any IDOR.
How teams detect issues like this
Detection can leverage both code-centric and behavior-centric approaches:
- Static analysis and code review:
- Search for data access patterns that use only
WHERE id = ?or similar filters on primary keys in sensitive tables (e.g., notes, patients, encounters) without adjacent authorization checks. - Flag functions that take user-controlled IDs and directly pass them to database queries or ORM lookups without verifying ownership or patient association.
- Review legacy modules separately, as they often bypass newer centralized authorization frameworks.
- Automated testing and dynamic analysis:
- Add security tests that attempt to access or modify resources by substituting IDs from other users or test accounts.
- Use automated scanners configured to probe IDOR by incrementing or swapping identifiers in patient note endpoints.
- Policy and tooling:
- Establish code review guidelines mandating explicit object-level authorization for any operation keyed by a user-supplied ID.
- Integrate SAST/DAST tools that include rules for IDOR-style access control weaknesses.

