Summary
OpenEMR's patient portal payment page previously trusted patient identifiers supplied in the HTTP request instead of binding strictly to the authenticated user's session.
As a result, a logged-in portal user could manipulate patient IDs to view and interact with other patients' demographics, invoices, and payment history, leading to horizontal privilege escalation and an Insecure Direct Object Reference (IDOR) condition.
Affected context
This vulnerability occurs in the OpenEMR patient portal, specifically on the portal/portal_payment.php page where patient billing and payment information is displayed and managed.
It manifests in environments where the application reads the patient identifier (pid / hidden_patient_code) from user-controllable request parameters and uses it directly to drive data access, instead of exclusively relying on the patient ID already associated with the authenticated portal session.
The risk is most relevant where multiple patients have active portal accounts and the portal is accessible over the internet or a shared network.
Exploit preconditions
- Attack surface: HTTP endpoints in the patient portal, particularly
portal/portal_payment.php. - Required access: Valid patient portal account (authenticated user).
- Trigger point: Attacker supplies or modifies
pidand/orhidden_patient_codeparameters in the request (e.g., via query string, form data, or interception proxy). - Why exploitation is possible: The page overwrites the session-bound patient ID (
$pid) with user-supplied values and uses them directly to load records, without verifying that the requested patient ID belongs to the authenticated portal user.
Why this happens
The underlying issue is a broken authorization check combined with trusting user-supplied identifiers to control which records are loaded.
In portal/portal_payment.php, the $pid variable representing the active patient is reassigned from $_REQUEST['pid'] or $_REQUEST['hidden_patient_code'], which are fully attacker-controlled parameters.
This behavior matches CWE-639: Authorization Bypass Through User-Controlled Key, where an application uses a direct object reference (the patient ID) from the client without enforcing an ownership or relationship check against the authenticated user.
Instead of binding all data access to the patient ID stored in the authenticated portal session, the code allowed external input to dictate which patient records were retrieved and manipulated.
Potential impact
- A portal user may access another patient's demographic details.
- A portal user may view other patients' invoices and payment history.
- A portal user may potentially initiate or modify payment-related actions on other patients' accounts, depending on the integrated workflows.
- Exposure of sensitive personal and financial data that can aid further fraud or social engineering.
- Regulatory and compliance implications for healthcare providers due to unauthorized disclosure of protected health information (PHI).
General mitigation guidance
Effective mitigation focuses on enforcing strict authorization based on server-side identity and ownership checks:
- Bind all patient-specific queries and operations to the patient ID already stored in the authenticated portal session, ignoring any conflicting user-supplied patient identifiers.
- Implement central authorization checks that verify the requested resource (e.g., patient ID) is associated with the authenticated user before any data is returned or action is performed.
- Treat all object identifiers received from the client as untrusted and validate them against access-control rules, not just for existence but also for relationship/ownership.
- Use a consistent access-control layer or policy engine so that every portal endpoint that references patient resources must pass through the same authorization logic.
- Minimize exposure of raw internal identifiers where possible, or pair them with opaque tokens and robust authorization checks to reduce IDOR risk.
How teams detect issues like this
Organizations can identify similar authorization weaknesses with:
- Static analysis: Rules that flag use of identifiers (e.g.,
pid,patient_id) taken directly from$_GET,$_POST, or$_REQUESTand then used in database queries or object lookups without intervening authorization checks. - Code review: Manual review of portal and API endpoints that handle user-specific resources, checking that each resource access path derives the subject identity from the authenticated session rather than from request parameters.
- Dynamic testing: Automated or manual penetration tests that manipulate resource identifiers (patient IDs, invoice IDs, etc.) in URLs, hidden form fields, or JSON bodies to confirm whether cross-user access is possible.
- Policy enforcement: Introducing secure coding guidelines and CI checks requiring explicit authorization calls for any action that depends on client-supplied identifiers, and blocking merges when these patterns are missing.

