Summary
OpenEMR's onsite portal activity update logic may authorize changes using the patient ID supplied in a request rather than checking the stored record's owner. An authenticated portal patient who can reference another patient's activity record may disclose data or alter its narrative, status, and ownership.
Affected context
The issue occurs in OnsitePortalActivityController::Update() when handling updates through the onsite portal activity API. It becomes risky when a portal patient can submit an update for an activity record belonging to someone else and the authorization check trusts the request's patientId instead of verifying the owner stored with that record.
Exploit preconditions
- Attack surface: The onsite portal activity API's update operation
- Required access: An authenticated portal patient account
- Trigger point: An update request that references another patient's activity record
- Why exploitation is possible: The ownership check uses the request-supplied patient ID rather than validating the target record's stored owner
Why this happens
The controller makes an object-level authorization decision using caller-controlled identity data instead of the ownership relationship associated with the requested record. This is an insecure direct object reference, mapped to CWE-639: Authorization Bypass Through User-Controlled Key. Authorization should be based on the authenticated principal and the persisted record, not on an identity value supplied with the request.
Potential impact
- An authenticated patient may disclose another patient's activity data, including table arguments and checksum information.
- An attacker could overwrite activity narratives or status.
- An attacker may be able to take ownership of another patient's activity record.
- Unauthorized changes could affect record integrity and patient privacy.
General mitigation guidance
Defensive patterns focus on enforcing object-level authorization against trusted identity and persisted ownership data:
- Derive the acting patient's identity from the authenticated session rather than trusting a request field.
- Verify that the authenticated patient is authorized to access the target record before reading or changing it.
- Apply the same ownership checks consistently to every operation on the resource.
- Minimize sensitive data returned by update endpoints and validate changes against an explicit schema.
- Follow least privilege for portal accounts and service operations.
How teams detect issues like this
Review update handlers for authorization decisions that rely on request-supplied owner or patient identifiers. Use static analysis or code review checks to flag object lookups followed by mutations without a persisted-owner check. Test authorization policies to confirm that one patient's identity cannot access or modify another patient's records, and enforce these checks in shared API middleware or policy layers where practical.

